COUNTIF Formula String

Radiatedjay2

New Member
Joined
Oct 7, 2018
Messages
8
The formula string below currently counts the number of supervisors scheduled to work based on specific entries in three cells. Certain entries add to the count and certain entries subtract from the count.

=COUNTIF(KI4:KI6,"*N*")+COUNTIF(KI4:KI6,"PHY")+COUNTIF(KI4:KI6,"TRD")+COUNTIF(KI4:KI6,"MT")+COUNTIF(KI4:KI6,"*D*")-COUNTIF(KI4:KI6,"DC")-COUNTIF(KI4:KI6,"XD")-COUNTIF(KI4:KI6,"XN")

What I need it to do is subtract 1 from the total if the total is => 3. How would I modify this formula to accomplish that.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
What version of Excel are you using? (Good idea to update your user profile to show this.) It will make a big difference in what solution to give you.
 
Upvote 0
Basically, use this structure:

=Your_Formula + IF(Your_Formula>=3,-1,0)

Beside, in your formula:

COUNTIF(KI4:KI6,"TRD")+...+COUNTIF(KI4:KI6,"*D*")

in which "*D*" is including "TRD" (TRD will be counted twice)
 
Upvote 0
Here is a formula that will work in your version (but not older versions before 2021)

Rich (BB code):
=LET(COUNTIF(KI4:KI6,"*N*")+COUNTIF(KI4:KI6,"PHY")+COUNTIF(KI4:KI6,"TRD")+COUNTIF(KI4:KI6,"MT")+COUNTIF(KI4:KI6,"*D*")-COUNTIF(KI4:KI6,"DC")-COUNTIF(KI4:KI6,"XD")-COUNTIF(KI4:KI6,"XN"),F,F-IF(F=>3,1,0))
 
Upvote 0
Basically, use this structure:

=Your_Formula + IF(Your_Formula>=3,-1,0)

Beside, in your formula:

COUNTIF(KI4:KI6,"TRD")+...+COUNTIF(KI4:KI6,"*D*")

in which "*D*" is including "TRD" (TRD will be counted twice)
Thanks! I did notice that about the "*D*" and the "TRD" a while back. I really haven't ever needed to use the TRD entry so it hasn't caused any issues yet. I will cut that part out in future iterations of the scheduling spreadsheet.
 
Upvote 0
Here is a formula that will work in your version (but not older versions before 2021)

Rich (BB code):
=LET(COUNTIF(KI4:KI6,"*N*")+COUNTIF(KI4:KI6,"PHY")+COUNTIF(KI4:KI6,"TRD")+COUNTIF(KI4:KI6,"MT")+COUNTIF(KI4:KI6,"*D*")-COUNTIF(KI4:KI6,"DC")-COUNTIF(KI4:KI6,"XD")-COUNTIF(KI4:KI6,"XN"),F,F-IF(F=>3,1,0))
With that formula, I get an error message that says, "The first argument of LET must be a valid name"
 
Upvote 0
Very sorry, I got it backwards:

Rich (BB code):
=LET(F, COUNTIF(KI4:KI6,"*N*")+COUNTIF(KI4:KI6,"PHY")+COUNTIF(KI4:KI6,"TRD")+COUNTIF(KI4:KI6,"MT")+COUNTIF(KI4:KI6,"*D*")-COUNTIF(KI4:KI6,"DC")-COUNTIF(KI4:KI6,"XD")-COUNTIF(KI4:KI6,"XN"),F-IF(F=>3,1,0))
 
Upvote 0
Your original formula can be written a bit more concisely like so:

Excel Formula:
=SUM(COUNTIF(KI4:KI6,{"*N*","PHY","TRD","MT","*D*","DC","XD","XN"})*{1,1,1,1,1,-1,-1,-1})

When included in the LET to allow for the >=3 condition, it looks like:

Excel Formula:
=LET(s,SUM(COUNTIF(KI4:KI6,{"*N*","PHY","TRD","MT","*D*","DC","XD","XN"})*{1,1,1,1,1,-1,-1,-1}),IF(s>=3,s-1,s))
 
Upvote 1
Very sorry, I got it backwards:

Rich (BB code):
=LET(F, COUNTIF(KI4:KI6,"*N*")+COUNTIF(KI4:KI6,"PHY")+COUNTIF(KI4:KI6,"TRD")+COUNTIF(KI4:KI6,"MT")+COUNTIF(KI4:KI6,"*D*")-COUNTIF(KI4:KI6,"DC")-COUNTIF(KI4:KI6,"XD")-COUNTIF(KI4:KI6,"XN"),F-IF(F=>3,1,0))
Thanks, that does the trick!
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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