Getting a count

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
705
Office Version
  1. 365
Platform
  1. Windows
Sheet1 column A contains dates, Column B contains one of 5 text strings. There may be 100 rows for 2/22/23, then 20 rows for 2/23/23, then 50 rows for 2/34/23, etc.
I need cell A1 in Sheet2 to look at Sheet1 and give me the count of all records for 2/22/23 that contain "text string 1". And B1 is the same for "text string 2."
Then A2 and B2 are the same things for 2/23/23
Then A3 and B3 are etc.

So A1 in Sheet2 should be a formula that reads "Look at all the rows in Sheet 1 that contain 2/22/23 in column A and tell me how many of those rows have "text string 1" in column B.
 
update your formula to this:

Excel Formula:
=SUM(
(--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*
((--("CA"=$M$2:$M$20))+(--("NV"=$M$2:$M$20)))
)

I think that should work.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
A new twist - the boss wants this same count EXCEPT - if the value in column M is equal to CA or NV.
Someone posted a fix for this twist but now I can't find it. I copied it down as
=SUM((--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*(--("CA"=$M$2:$M$20))+(--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*(--("NV"=$M$2:$M$20))) and it's not working for me. I'm not sure if I copied it wrong because I'm still trying to figure out how this solution works.
In my file, I used one of the other solutions for the initial question - it works and I'm smart enough to understand why it works but not smart enough to add the new twist of excluding 2 states.
This is the formula I was using: =COUNTIFS(A:A,E2,B:B,$F$1:$G$1)
Could the kind soul who posted the fix report it? Or does anyone know how to make it work with this formula? =COUNTIFS(A:A,E2,B:B,$F$1:$G$1)
Thanks to all.
 
Upvote 0
that was probably me:
=SUM(
(--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*
((--("CA"=$M$2:$M$20))+(--("NV"=$M$2:$M$20)))
)
I was trying to use the communicative property there. Maybe i have a paren wrong... try this then:
=SUM(
(--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*((--("CA"=$M$2:$M$20))
)
+
SUM(
(--(H$1=$B$2:$B$20))*(--($G2=$A$2:$A$20))*(--("NV"=$M$2:$M$20)))
)

I am not sure the parens are correct.
 
Upvote 0
to amend @Fluff 's formula maybe this will work:
Excel Formula:
=COUNTIFS(A:A,E2,B:B,$F$1:$G$1,M:M,"NV") + COUNTIFS(A:A,E2,B:B,$F$1:$G$1,M:M,"CA")
 
Upvote 0
How about
Fluff.xlsm
ABMNOPQ
1DateTextTextString 1TextString 2
219/02/2023TextString 1ca19/02/202311
319/02/2023TextString 120/02/202321
419/02/2023TextString 321/02/202301
519/02/2023TextString 4
619/02/2023TextString 5
719/02/2023TextString 1nv
819/02/2023TextString 2
919/02/2023TextString 3
1019/02/2023TextString 4
1119/02/2023TextString 5
1220/02/2023TextString 1
1320/02/2023TextString 2
1420/02/2023TextString 3
1520/02/2023TextString 4
1620/02/2023TextString 5
1720/02/2023TextString 1
1821/02/2023TextString 2
1921/02/2023TextString 3
2021/02/2023TextString 4
21
Main
Cell Formulas
RangeFormula
O2:O4O2=UNIQUE(FILTER(A2:A100,A2:A100<>""))
P2:Q2P2=COUNTIFS(A:A,O2,B:B,$P$1:$Q$1,M:M,"<>CA",M:M,"<>NV")
P3:Q4P3=COUNTIFS(A:A,O3,B:B,$P$1:$Q$1)
Dynamic array formulas.
 
Upvote 0
I ended up using countif:
=COUNTIFS(Data!$R$2:$R$20000,$A3,Data!$D$2:$D$20000,$B$2)-(COUNTIFS(Data!$R$2:$R$20000,$A3,Data!$D$2:$D$20000,$B$2,Data!$I$2:$I$20000,"CA"))-(COUNTIFS(Data!$R$2:$R$20000,$A3,Data!$D$2:$D$20000,$B$2,Data!$I$2:$I$20000,"NV"))

I need to play some more with the other options provided here. Thanks to all.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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