COUNTA with conditions

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
888
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a complicated formula with countif and count A. Basically my goal is when M1 has the value "All" that all "Y" and "N" are counted.
However if M1 has the person's name it will only count the "Y" and "N" for that person. My end goal is to graph this so I can rather show everyone's "Y" and "N" result or by the individual person when you select specified values in M1.

Help would be greatly appreciated!

Safety Incentive.xlsx
ABCDEFGHIJKLM
1YNWilliam
2Emp NamePPESafe LiftingSafety KnowledgeSafety TrainingSWPUnsafe Acts 11
3WilliamYNYYYNAshley66
4SteveYYYYYNSteve66
5AshleyYYYNYNTest66
6TestYYYNYNTest 266
7Test 2YNYYYNWilliam66
8
Sheet1
Cell Formulas
RangeFormula
J2:J7J2=IFERROR(IF(AND($M$1="All",$I$2="All"),COUNTIF(Table1[[PPE]:[Unsafe Acts]],$J$1),COUNTA(INDEX(Table1[[PPE]:[Unsafe Acts]],MATCH(I2,Table1[Emp Name],0),0))),"0")
K2:K7K2=IFERROR(IF(AND($M$1="All",$I$2="All"),COUNTIF(Table1[[PPE]:[Unsafe Acts]],$K$1),COUNTA(INDEX(Table1[[PPE]:[Unsafe Acts]],MATCH(I2,Table1[Emp Name],0),0))),"0")
I2I2=IF(M1="All","All","")
I3:I7I3=IF(M1="All","",UNIQUE(SORT(Table1[Emp Name])))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
B3:G7ListY,N


1644868793255.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Is there a reason you do not want to use a pivot chart for this?
To be honest I am not sure how to get the desired effect with a pivot table either as I do not want to include the column headers: PPE, Safe Lifting etc. I only want to count Y or N for all or by employee
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDEFGHIJKLM
1YNwilliam
2Emp NamePPESafe LiftingSafety KnowledgeSafety TrainingSWPUnsafe Acts  
3WilliamYNYYYNAshley00
4SteveYYYYYNSteve00
5AshleyYYYNYNTest00
6TestYYYNYNTest 200
7Test 2YNYYYNWilliam42
8
Main
Cell Formulas
RangeFormula
I2I2=IF(M1="All","All","")
J2J2=IF(M1="all",COUNTIFS(Table1[[PPE]:[Unsafe Acts]],J1:K1),"")
I3:I7I3=IF(M1="All","",UNIQUE(SORT(Table1[Emp Name])))
J3:J7J3=IF(M1="all","",MMULT((Table1[[PPE]:[Unsafe Acts]]=J1)*(I3#=M1),SEQUENCE(COLUMNS(Table1[[#Headers],[PPE]:[Unsafe Acts]]),,,0)))
K3:K7K3=IF(M1="all","",MMULT((Table1[[PPE]:[Unsafe Acts]]=K1)*(I3#=M1),SEQUENCE(COLUMNS(Table1[[#Headers],[PPE]:[Unsafe Acts]]),,,0)))
Dynamic array formulas.
 
Upvote 0
Solution
To be honest I am not sure how to get the desired effect with a pivot table either as I do not want to include the column headers: PPE, Safe Lifting etc. I only want to count Y or N for all or by employee
Add a column to the right of your data titled Y
=countif(B3:G3,"Y")

Add a second collumn to the right of that called N
=countif(B3:G3,"N")

These will give you the total number for each employee, which is what you can drop into the values section of the pivot table. Then you can filter by Employee Name or by all
 
Upvote 0
I entered it wrong at first but now seems like it is working perfectly
 
Upvote 0
Add a column to the right of your data titled Y
=countif(B3:G3,"Y")

Add a second collumn to the right of that called N
=countif(B3:G3,"N")

These will give you the total number for each employee, which is what you can drop into the values section of the pivot table. Then you can filter by Employee Name or by all
Thank you very much!!
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDEFGHIJKLM
1YNwilliam
2Emp NamePPESafe LiftingSafety KnowledgeSafety TrainingSWPUnsafe Acts  
3WilliamYNYYYNAshley00
4SteveYYYYYNSteve00
5AshleyYYYNYNTest00
6TestYYYNYNTest 200
7Test 2YNYYYNWilliam42
8
Main
Cell Formulas
RangeFormula
I2I2=IF(M1="All","All","")
J2J2=IF(M1="all",COUNTIFS(Table1[[PPE]:[Unsafe Acts]],J1:K1),"")
I3:I7I3=IF(M1="All","",UNIQUE(SORT(Table1[Emp Name])))
J3:J7J3=IF(M1="all","",MMULT((Table1[[PPE]:[Unsafe Acts]]=J1)*(I3#=M1),SEQUENCE(COLUMNS(Table1[[#Headers],[PPE]:[Unsafe Acts]]),,,0)))
K3:K7K3=IF(M1="all","",MMULT((Table1[[PPE]:[Unsafe Acts]]=K1)*(I3#=M1),SEQUENCE(COLUMNS(Table1[[#Headers],[PPE]:[Unsafe Acts]]),,,0)))
Dynamic array formulas.
Thank you very much Fluff
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Not sure id ever want a chart to look like that. Are you sure thats best solution?
 
Upvote 0

Forum statistics

Threads
1,215,442
Messages
6,124,886
Members
449,194
Latest member
ronnyf85

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