Countifs before a certain date

andydarly

New Member
Joined
Oct 18, 2016
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi, all. I am looking to do a countifs formula, which is usually pretty straightforward. However, one of the criteria needs to specify unque values

Please note that I am on a work computer and it will not let me download xl2bb, so had to use an image. Sorry. I did try :(

So in the attached data I would like to count unique entries for all the people in a team with "_D" in it, are 1 FTE and have a start date of before the first of the next month, so July's data in this attachment would number 43. The number for August would be 44 and September would be 45 etc. The formula I am trying is below works but counts all entries, so is 20 higher for each month. Is there a simple way to do this unique value part? Thanks in advance.

My formula is =COUNTIFS($C:$C,"*_D*",$D:$D,1,$F:$F,"<01/08/2022")

1667181866212.png
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
*******Correction******* I realise I do not mean "unique" values. I mean distinct values - apologies
 
Upvote 0
To count for July2022:
Code:
=COUNTIFS($C:$C,"*_D*",$D:$D,1,$F:$F,">=01/07/2022",$F:$F,"<01/08/2022")
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

it will not let me download xl2bb, so had to use an image.
In that case consider just a direct copy/paste from your worksheet and tell us what the range is. That way we can at least copy the data for testing.
For example, this is A1:F2
EMP_IDEMP_CLASS_1FTEHoursSTART DATE
NGoo81Service_D JHB2
1​
75​
18/09/2017​
 
Upvote 0
To count for July2022:
Code:
=COUNTIFS($C:$C,"*_D*",$D:$D,1,$F:$F,">=01/07/2022",$F:$F,"<01/08/2022")
Hi, bebo21999 Thank you for your reply. Sadly this will not work as it will only give me the people in July. I need all before before August. Your version would also give me the duplicates too :(
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)


In that case consider just a direct copy/paste from your worksheet and tell us what the range is. That way we can at least copy the data for testing.
For example, this is A1:F2
EMP_IDEMP_CLASS_1FTEHoursSTART DATE
NGoo81Service_D JHB2
1​
75​
18/09/2017​
Hi, Peter. I did not realise I could do that. Thank you.

Looking athe below if we go with the same dates - so all the individuals before 01/08/2022 in the Start Date...

My countifs formula will give me 19 rows but I need to know how many different people this is (the answer in this data set would be 13). I know I could do this in Power Query by removing duplicates but that would cause something else to break.

I'm hoping I can put the countifs formula inside some sort of distinct formula or vice versa or something?



EMP_IDEMP_SHORT_NAMEEMP_CLASS_1FTEHoursSTART_DATE
NG0081Ngcobo, KhanyisileService_D JHB217518/09/17
NG0081Ngcobo, KhanyisileService_N JHB917501/04/22
SA0576Saba, LindaService_D JHB317518/09/17
SA0576Saba, LindaService_N JHB617501/04/22
SE0236Seqobane, JenniferService_N JHB917522/03/22
SE0236Seqobane, JenniferService_N JHB517501/07/22
JI0334Mokgosi, XolileService_N JHB817501/01/22
JI0334Mokgosi, XolileService_N JHB417501/08/22
JI0334Mokgosi, XolileService_N JHB1017501/09/22
KG0186Kgasane, LesegoService_D JHB517501/10/20
MA0987Mabetoa, OlgarService_N JHB117502/12/21
TS0257Tsholetsasne, BoitumeloService_N JHB517501/12/21
ZU0768Zulu, FaithService_N JHB1017518/09/17
ZU0768Zulu, FaithService_N JHB817501/07/22
ZU0768Zulu, FaithService_N JHB717522/08/22
GO1158Golding, NicoletteService_D JHB516001/03/21
MA0293Mazibuko, Thuli-NonkonzoService_D JHB80.86001/01/22
MA0293Mazibuko, Thuli-NonkonzoService_D JHB40.86001/10/22
BA0178Banda, NtandoService_N JHB40.86001/10/20
BA0178Banda, NtandoService_N JHB80.86001/02/22
MP5608Mphahlele, Ouma VickyService_N JHB517501/12/21
MP5608Mphahlele, Ouma VickyService_N JHB817501/07/22
MP5608Mphahlele, Ouma VickyService_D JHB517501/09/22
RU5561Ruiters, KagisoService_D JHB817501/01/21
RU5561Ruiters, KagisoService_D JHB417501/10/22
 
Upvote 0
I'm hoping I can put the countifs formula inside some sort of distinct formula or vice versa or something?
Possibly, but to know what is available in your version of Excel we need you to act on my previous suggestion. ;)
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Possibly, but to know what is available in your version of Excel we need you to act on my previous suggestion. ;)
Apologies. I forgot that bit. I am specifically using Microsoft 365 MSO (Version 2202 Build 16.0.14931.20764) 64-bit (y)
 
Upvote 0
Try:

Book1
ABCDEFGHIJK
1EMP_IDEMP_SHORT_NAMEEMP_CLASS_1FTEHoursSTART_DATEStart Date Before8/1/2022
2NG0081Ngcobo, KhanyisileService_D JHB21759/18/2017Count5
3NG0081Ngcobo, KhanyisileService_N JHB91754/1/2022
4SA0576Saba, LindaService_D JHB31759/18/2017
5SA0576Saba, LindaService_N JHB61754/1/2022
6SE0236Seqobane, JenniferService_N JHB91753/22/2022
7SE0236Seqobane, JenniferService_N JHB51757/1/2022
8JI0334Mokgosi, XolileService_N JHB81751/1/2022
9JI0334Mokgosi, XolileService_N JHB41758/1/2022
10JI0334Mokgosi, XolileService_N JHB101759/1/2022
11KG0186Kgasane, LesegoService_D JHB517510/1/2020
12MA0987Mabetoa, OlgarService_N JHB117512/2/2021
13TS0257Tsholetsasne, BoitumeloService_N JHB517512/1/2021
14ZU0768Zulu, FaithService_N JHB101759/18/2017
15ZU0768Zulu, FaithService_N JHB81757/1/2022
16ZU0768Zulu, FaithService_N JHB71758/22/2022
17GO1158Golding, NicoletteService_D JHB51603/1/2021
18MA0293Mazibuko, Thuli-NonkonzoService_D JHB80.8601/1/2022
19MA0293Mazibuko, Thuli-NonkonzoService_D JHB40.86010/1/2022
20BA0178Banda, NtandoService_N JHB40.86010/1/2020
21BA0178Banda, NtandoService_N JHB80.8602/1/2022
22MP5608Mphahlele, Ouma VickyService_N JHB517512/1/2021
23MP5608Mphahlele, Ouma VickyService_N JHB81757/1/2022
24MP5608Mphahlele, Ouma VickyService_D JHB51759/1/2022
25RU5561Ruiters, KagisoService_D JHB81751/1/2021
26RU5561Ruiters, KagisoService_D JHB417510/1/2022
Sheet3
Cell Formulas
RangeFormula
K2K2=ROWS(UNIQUE(FILTER($B$2:$B$26,(ISNUMBER(SEARCH("_D",$C$2:$C$26)))*($D$2:$D$26=1)*($F$2:$F$26<=$K$1),"")))
 
Upvote 0
@andydarly
Thanks for updating your version details. (y)

@AhoyNC
Some 'tweaking' comments about your solution.

  • I do not know if it would be possible with the OP's data but if no rows meet the criteria (you seemed to have tried to allow for this with the "" for if empty argument in the filter function) your formula would still return 1 since the "" would occupy a row.

  • a start date of before the first of the next month
    That would imply that your K1 needs to be the last day of a month, or perhaps better to use "<" instead of "<=" when comparing column F to K1

  • Makes no difference to the results but as the question is asked there should be no need for any $ signs in the formula.
So, my tweaks to account for the above would be

andydarly.xlsm
BCDEFGHIJK
1EMP_SHORT_NAMEEMP_CLASS_1FTEHoursSTART_DATEStart Date Before1/08/2022
2Ngcobo, KhanyisileService_D JHB217518/09/2017Count5
3Ngcobo, KhanyisileService_N JHB91751/04/2022
4Saba, LindaService_D JHB317518/09/2017
5Saba, LindaService_N JHB61751/04/2022
6Seqobane, JenniferService_N JHB917522/03/2022
7Seqobane, JenniferService_N JHB51751/07/2022
8Mokgosi, XolileService_N JHB81751/01/2022
9Mokgosi, XolileService_N JHB41751/08/2022
10Mokgosi, XolileService_N JHB101751/09/2022
11Kgasane, LesegoService_D JHB51751/10/2020
12Mabetoa, OlgarService_N JHB11752/12/2021
13Tsholetsasne, BoitumeloService_N JHB51751/12/2021
14Zulu, FaithService_N JHB1017518/09/2017
15Zulu, FaithService_N JHB81751/07/2022
16Zulu, FaithService_N JHB717522/08/2022
17Golding, NicoletteService_D JHB51601/03/2021
18Mazibuko, Thuli-NonkonzoService_D JHB80.8601/01/2022
19Mazibuko, Thuli-NonkonzoService_D JHB40.8601/10/2022
20Banda, NtandoService_N JHB40.8601/10/2020
21Banda, NtandoService_N JHB80.8601/02/2022
22Mphahlele, Ouma VickyService_N JHB51751/12/2021
23Mphahlele, Ouma VickyService_N JHB81751/07/2022
24Mphahlele, Ouma VickyService_D JHB51751/09/2022
25Ruiters, KagisoService_D JHB81751/01/2021
26Ruiters, KagisoService_D JHB41751/10/2022
Sheet1
Cell Formulas
RangeFormula
K2K2=IFNA(ROWS(UNIQUE(FILTER(B2:B26,(ISNUMBER(SEARCH("_D",C2:C26)))*(D2:D26=1)*(F2:F26<K1),NA()))),0)
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top