+ Reply to Thread
Results 1 to 24 of 24

countif + match formula

  1. #1
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    countif + match formula

    Hello

    need some help regarding the countif + match formula

    cell $B$4 = Time frame (i.e. P1W1)

    Im trying to calculate the employee headcount in a city so my countif formula is:
    Please Login or Register  to view this content.
    I produce this report each week, so next week the period will be, P1W2 then P1W3 (P1=Jan, P2= Feb etc - for your record)

    so once i change the time frame in cell $B$4, I would like the countif to modify itself. i tried to compile the formula, but keep getting an error. please help!

    this is my match/countif
    Please Login or Register  to view this content.
    can someone help me with where I am going wrong? Thanks.
    Last edited by jw01; 01-26-2011 at 11:54 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Possibly:

    =COUNTIFS([Master Employee List.xls]Washington-Philadelphia'!$C$7:$C$1119,$B$4,'[Master Employee List.xls]Washington-Philadelphia'!$D$7:$D$1119,"Philadelphia")
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: countif + match formula

    Note that COUNTIFS like COUNTIF would work only if the target file is open at calculation time - this is implied by your use of short names in original formula (and ref. to COUNTIF) but is perhaps worth pointing out nonetheless.

    If the file is not always open you would need to revert to the less efficient SUMPRODUCT (or equiv. Array)

  4. #4
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    Hello

    I used the formula below:

    =COUNTIFS('[YTD_Branch SE v1.xls]Washington-Philadelphia'!$D$8:$D$1119,$B$4,'[YTD_Branch SE v1.xls]Washington-Philadelphia'!$D$8:$D$1119,"Philadelphia")

    and i keep getting a "#name" error.

    B4 = week, so when I change the week to i.e. week 3, i would like the data to change accordingly (hence like a count if + match formula....
    any help pls?!

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Are you using XL2003 or earlier? That would give you the #NAME? error in this case since COUNTIFS is not available in those versions...

    You could try:


    =SUMPRODUCT(--('[YTD_Branch SE v1.xls]Washington-Philadelphia'!$D$8:$D$1119=$B$4),--('[YTD_Branch SE v1.xls]Washington-Philadelphia'!$D$8:$D$1119="Philadelphia"))

    and as DonkeyOte mentioned, this will work with closed workbooks too.

  6. #6
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    Hello

    I'm using both 2003 and 2007. I keep receiving the "#name" error. any ideas what maybe casuing this?

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Are you sure it is #NAME? and not #REF! that you are getting?

    I can't see how you are getting the #NAME? error, where the #REF error would be if the file can't be found or is misnamed....

  8. #8
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    Hello

    It appears to only like 0 as an answer. I have tried to play with it but getting no luck what so ever :S so im hoping i can some of your help pls.

    i have attached a sample file, that shows just "wash-phillie" region. mind you, i have another 33 other regions to cover so the task does become tedious when i have to manually update the data so im hoping your expertise can help me in someway.

    i have two worksheets in the workbook
    -US data
    -Wash-Phillie

    in the US data sheet, i have highlighted in red where i would like that formula to be implied. please note it references cell (B4). I change that in my master file to reflect the correct time frame. you will also notice in the wash-phillie worksheet, i have highlighted in red font the city names (i use that as a method to count the # of sales ppl for a particular time frame.

    P1W3 basically means, period 1 week 3 means (week 3 of january).

    i would really appreciate it if i can get your help. i also have other metrics to cover i.e. other actitives, so if this formula can function, it would be of great time, so i would only need to change the P1W3 portion and the rest is calculated on it's own. i realize i would need the other workbooks open, but that is fine. kindly let me know your thoughts. thxs a bunch.
    Attached Files Attached Files
    Last edited by jw01; 01-25-2011 at 06:20 PM.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: countif + match formula

    You are getting a 0 as an answer because that is the correct answer.

    Your formula in B14 is:
    =SUMPRODUCT(--(Sheet2!$D$50:$D$69=$B$4),--(Sheet2!$D$50:$D$69="Washington"))

    the answer is "the number of times P1W3 appears in D50:D69 AND Washington is in the same row within that range". Obviously it's 0 because they can't occupy the same cell.

    What numbers were you hoping to get in B14 and B15 (and why)?

    You won't be able to use SUMPRODUCT to match the P1W3 because it only appears once (at the beginning of its section).
    Last edited by Cutter; 01-25-2011 at 06:58 PM.

  10. #10
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    hello

    thxs for pointing that out, feel like an idiot :S. basically im trying to use the countif formula (that was my intentions intially) so get a count for a city name, which would translate into the # of sales ppl they have.

    but i produce a report each week, thus next week it will be P1W4, so i have to natrually go in each cell and do a find and replace for it to look under P1W4 in the i..e Wash-Phillie worksheet.

    So im trying to automate that, so B14 is P1W4, then for it to count in the appropriate row/columns in the wash-phillie sheet.

    i really apprecaite your help and input. kindly let me know. thxs!

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719

    Re: countif + match formula

    Does this formula do what you want in B14

    =COUNTIF(OFFSET(Sheet2!D$7,MATCH($B$4,Sheet2!$C$7:$C$2000,0),0,20),$A14)

    copy to B15
    Audere est facere

  12. #12
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    hello daddylonglegs,

    your formula works beautifully, thx you.

    quick question regarding capturing additional fields.

    i need to capture additional metrics for the sales ppl (i.e. the range in E6:Y6)...things such as, # of calls they made etc etc, with respective to the city they work for.

    so, ie. in washington, what the total days worked was for i.e. P1W1?

    i thought it was the same formula as above and changing the beginning portion to (E$7):
    =COUNTIF(OFFSET(Sheet2!E$7....

    but that is not getting me the right answer. any suggestions, pls and thx you

  13. #13
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    currently, in order to calculate the "total days worked" i would use the following formula for P1W3

    =SUMIF('[YTD_Branch SE v1.xls]Washington-Philadelphia'!$D$50:$D$69,"Washington DC",'[YTD_Branch SE v1.xls]Washington-Philadelphia'!$E$50:$E$69)

    -its a tedious process as i have the change the range for "E50:E69" everytime the week changes, so is it possible to intrigrate the offset formula or index match so I can apply the formula that was provided above? thx you for your time.

  14. #14
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719

    Re: countif + match formula

    Yes, you should able to use OFFSET to derive both ranges in the SUMIF formula based on the value in B4, i.e.

    =SUMIF(OFFSET(Sheet2!D$7,MATCH($B$4,Sheet2!$C$7:$C$2000,0),0,20),$A14,OFFSET(Sheet2!E$7, MATCH($B$4,Sheet2!$C$7:$C$2000,0),0,20))

    where A14 contains the city

  15. #15
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Just a note that if you are referencing a closed workbook as initially might be assumed, SUMIF will not work.... both workbooks must be open.

  16. #16
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    hello daddylonglegs
    again, thx you for your time. it worked out perfectly...thxs for all your kind help/prompt response!!

    also nbvc, i really apprecaite your feedback and help with this matter. i realize the sumif only works if the workbook is open, which is fine for now; however for future reference or knowledge, is there a way to go around this? thx you.

  17. #17
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Quote Originally Posted by jw01 View Post
    also nbvc, i really apprecaite your feedback and help with this matter. i realize the sumif only works if the workbook is open, which is fine for now; however for future reference or knowledge, is there a way to go around this? thx you.
    Usually, Sumproduct() is the replacement for COUNTIF or SUMIF when working with closed workbooks...

  18. #18
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    Hello

    I have a similar inquiry.

    I have attached a sample workbook. Highlighted in "red" are the fields that i'm currently looking to get information from sheet2.

    similar to the formula that is the cell beside the red cells, sumif(offset....which matches the P1W1, P1W2 etc...and finds the correct sum, im looking to do something similar for the "PTD" or period to date field.

    PTD is basically, P1, P2, P3...P12 (where P is equal to month).
    each month im having to go in and change manually the sum references. i tried to intrigrate the sumif(offset to capture just the PTD portion, but having some trouble. if someone can kindly help out, that would be much appreciated. thx you!
    Attached Files Attached Files

  19. #19
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    What I would suggest is to add a helper column in Sheet2, say in column B.

    put formula in B7:

    =LOOKUP(9.999999,SEARCH(LEFT(C$7:C7,1),"P"),C$7:C7)

    copied down. This will extract relevant code for the whole group.

    Then in the US(Data) sheet, B14

    =SUMPRODUCT(--(Sheet2!$B$7:$B$2000=$B$4),--(Sheet2!$D$7:$D$2000=$A14))

    in C14:

    =SUMPRODUCT(--(LEFT(Sheet2!$B$7:$B$2000,2)=$C$4),--(Sheet2!$D$7:$D$2000=$A14))

    in D14:

    =SUMPRODUCT(--(Sheet2!$B$7:$B$2000=$B$4),--(Sheet2!$D$7:$D$2000=$A14),Sheet2!$E$7:$E$2000)

    in E14:

    =SUMPRODUCT(--(LEFT(Sheet2!$B$7:$B$2000,2)=$C$4),--(Sheet2!$D$7:$D$2000=$A14),Sheet2!$E$7:$E$2000)

    in F14:

    =SUMPRODUCT(--(Sheet2!$B$7:$B$2000=$B$4),--(Sheet2!$D$7:$D$2000=$A14),Sheet2!$F$7:$F$2000)

    in G14:

    =SUMPRODUCT(--(LEFT(Sheet2!$B$7:$B$2000,2)=$C$4),--(Sheet2!$D$7:$D$2000=$A14),Sheet2!$F$7:$F$2000)

    each copied down.

  20. #20
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    Hello

    thx you for your help with this matter. it works like a charm!

    the only issue pertaining to the "lookup"...is the "P" portion. one a few sheets, there are individuals whose name starts with p (Paul, Paulina etc) so lol it's throwing it off. im not sure how to make the lookup distinguish between P1 then P2 otherwise and not let it catch any names that start with the letter P...? your thoughts, thx you!

  21. #21
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    Good point

    Try replacing formula in B7 with:

    =LOOKUP(2,1/(SEARCH(LEFT(C$7:C7,1),"P")*ISNUMBER(MID(C$7:C7,2,1)+0)),C$7:C7)

    copied down.

  22. #22
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: sunproduct...&row

    Hello

    im just having an issue as im not embedding the quotations properly for the formula to function...

    here is my original formula:
    =SUMPRODUCT(--(LEFT('[YTD_District (2011).xls]Toronto'!$A$2:$A$59,2)=$C$4),('[YTD_District (2011).xls]Toronto'!$G$2:$G$59))


    i would like to modify is, so instead of typing in seperately the city name, it references the cell $A13 etc......but im messing up on my placement of ""......
    =SUMPRODUCT(--(LEFT("'[YTD_District (2011).xls]"&A13&"'!$A$2:$A$59,2)=$C$4),("'[YTD_District (2011).xls]"&A13&"''!$G$2:$G$59))

    thx you very much!

  23. #23
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: countif + match formula

    To reference the city in order to reference the proper sheet, you will need to incorporate the INDIRECT function like this:

    =SUMPRODUCT(--(LEFT(INDIRECT("'[YTD_District (2011).xls]"&A13&"'!$A$2:$A$59"),2)=$C$4),(INDIRECT("'[YTD_District (2011).xls]"&A13&"'!$G$2:$G$59")))

    but note that INDIRECT only works with open workbooks.

    If you want to work with closed workbooks, you will need to download and install a free addin from here and replace INDIRECT with INDIRECT.EXT

  24. #24
    Forum Contributor
    Join Date
    11-26-2010
    Location
    usa
    MS-Off Ver
    Office 365
    Posts
    1,233

    Re: countif + match formula

    thx you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1