Simplifying Nested Countif with If Formula

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have a LOOOOOONG Countif nested formula . Had to double it with a + because I need to count businesses that are found in two different columns (AA_AP_Hierarchy_String_2 and a combination of AA_AP_L2_Business and AA_AP_Business_Impacted). Would anyone have any ideas how I could possibly simplify this nested formula?

Excel Formula:
=IF($DW$4<>"",IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B16,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B16,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")),IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B16,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B16,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")))+IF($DW$4<>"",IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_L2_Business,"Multi O&T Businesses",AA_AP_Business_Impacted,"*GCB Technology*",AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_L2_Business,"Multi O&T Businesses",AA_AP_Business_Impacted,"*GCB Technology*",AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")),IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_L2_Business,"Multi O&T Businesses",AA_AP_Business_Impacted,"*GCB Technology*",AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_L2_Business,"Multi O&T Businesses",AA_AP_Business_Impacted,"*GCB Technology*",AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")))


Thank you,
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If I follow the logic correctly, this might work:
Excel Formula:
=SUMPRODUCT(
(AA_AP_Hierarchy_String_2 = $B16) + (AA_AP_L2_Business = "Multi O&T Businesses") + (ISNUMBER(SEARCH("GCB Technology",AA_AP_Business_Impacted))),
--(AA_AP_Report_Flag = "Yes"),
--(AA_AP_Control_Rating = $B$2),
--(IF($DW$4<>"", (AA_AP_Region_Revised = $DW$4) * (AA_AP_Published_Month <= $D$4), --(AA_AP_Published_Month <= 999999))),
--(AA_AP_Audit_Status = "Completed"),
--(AA_AP_Monthly_BUR_Date <= IF(COUNTIF(AA_DropDowns_EOMonth,$F$2), $F$2, 999999))
)
 
Upvote 0
After playing around with the suggestion in my previous post, I think the first term in the SUMPRODUCT may need to be wrapped with a condition to avoid double counting...try:
Excel Formula:
=SUMPRODUCT(
--( ( (AA_AP_Hierarchy_String_2 = $B16) + (AA_AP_L2_Business = "Multi O&T Businesses") + (ISNUMBER (SEARCH("GCB Technology",AA_AP_Business_Impacted) ) ) )>=1),
--(AA_AP_Report_Flag = "Yes"),
--(AA_AP_Control_Rating = $B$2),
--(IF($DW$4<>"", (AA_AP_Region_Revised = $DW$4) * (AA_AP_Published_Month <= $D$4), --(AA_AP_Published_Month <= 999999))),
--(AA_AP_Audit_Status = "Completed"),
--(AA_AP_Monthly_BUR_Date <= IF(COUNTIF(AA_DropDowns_EOMonth,$F$2), $F$2, 999999))
)

...Or was the intent to double count rows involving AA_AP_Hierarchy_String_2, AA_AP_L2_Business, and AA_AP_Business_Impacted if two or more of them evaluate to TRUE on the same row (if that is possible)?
 
Upvote 0
One more try...I made a mistake treating two of the criteria as OR's rather than AND's...the + sign should be multiplication sign and then those terms are wrapped with parentheses:
Excel Formula:
=SUMPRODUCT(
--(((AA_AP_Hierarchy_String_2=$B16)+((AA_AP_L2_Business="Multi O&T Businesses")*(ISNUMBER(SEARCH("GCB Technology",AA_AP_Business_Impacted)))))>=1),
--(AA_AP_Report_Flag = "Yes"),
--(AA_AP_Control_Rating = $B$2),
--(IF($DW$4<>"", (AA_AP_Region_Revised = $DW$4) * (AA_AP_Published_Month <= $D$4), --(AA_AP_Published_Month <= 999999))),
--(AA_AP_Audit_Status = "Completed"),
--(AA_AP_Monthly_BUR_Date <= IF(COUNTIF(AA_DropDowns_EOMonth,$F$2), $F$2, 999999)))
 
Upvote 0
Upon further investigation, I think there is one more issue with how the criteria are applied to the AA_AP_Published_Month array. This version addresses that issue. I've rearranged the formula and grouped the easier to follow arrays together on the first line. The primary change introduced with this version is found on the last line, where an IF statement as been added to specify which criteria to use (999999 or $D$4).
Excel Formula:
=SUMPRODUCT(--(AA_AP_Report_Flag = "Yes"), --(AA_AP_Control_Rating = $B$2), --(AA_AP_Audit_Status = "Completed"),
--(((AA_AP_Hierarchy_String_2=$B16)+((AA_AP_L2_Business="Multi O&T Businesses")*ISNUMBER(SEARCH("GCB Technology",AA_AP_Business_Impacted))))>=1),
--(AA_AP_Monthly_BUR_Date <= IF(COUNTIF(AA_DropDowns_EOMonth,$F$2), $F$2, 999999)),
--(IF($DW$4<>"", (AA_AP_Region_Revised = $DW$4) * (AA_AP_Published_Month <= $D$4), --(AA_AP_Published_Month <=IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),999999,$D$4)))))
 
Upvote 0
Thank you so much. I will try it out today.

I actually had to add 1 more criteria to my original formula "AA_AP_Sector,"EIO&T". Where would i be able to plug this into your last formula? Should I add it in the beginning of the formula?

Excel Formula:
=IF($DW$4<>"",IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B12,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Sector,"EIO&T",AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B12,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Region_Revised,$DW$4,AA_AP_Sector,"EIO&T",AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")),IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B12,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Audit_Status,"Completed",AA_AP_Monthly_BUR_Date,"<="&$F$2),COUNTIFS(AA_AP_Hierarchy_String_2,$B12,AA_AP_Report_Flag,"Yes",AA_AP_Control_Rating,$B$2,AA_AP_Published_Month,"<="&$D$4,AA_AP_Audit_Status,"Completed")))

Thank you.
 
Upvote 0
For the condition, AA_AP_Sector="EIO&T", when should it be applied? Is it a criteria that you want to include everywhere we have the other two text string criteria (AA_AP_L2_Business="Multi O&T Businesses" and AA_AP_Business_Impacted="*GCB Technology*"), and no where else? If so, then this should work:
Excel Formula:
=SUMPRODUCT(--(AA_AP_Report_Flag = "Yes"), --(AA_AP_Control_Rating = $B$2), --(AA_AP_Audit_Status = "Completed"),
--(((AA_AP_Hierarchy_String_2=$B16)+((AA_AP_Sector="EIO&T")*(AA_AP_L2_Business="Multi O&T Businesses")*ISNUMBER(SEARCH("GCB Technology",AA_AP_Business_Impacted))))>=1),
--(AA_AP_Monthly_BUR_Date <= IF(COUNTIF(AA_DropDowns_EOMonth,$F$2), $F$2, 999999)),
--(IF($DW$4<>"", (AA_AP_Region_Revised = $DW$4) * (AA_AP_Published_Month <= $D$4), --(AA_AP_Published_Month <=IF(COUNTIF(AA_DropDowns_EOMonth,$F$2),999999,$D$4)))))

This part of the formula:
--(((AA_AP_Hierarchy_String_2=$B16)+((AA_AP_Sector="EIO&T")*(AA_AP_L2_Business="Multi O&T Businesses")*ISNUMBER(SEARCH("GCB Technology",AA_AP_Business_Impacted))))>=1)
considers any rows where either of these conditions are met:
1. AA_AP_Hierarchy_String_2=$B16
2. AA_AP_Sector="EIO&T" ...AND... AA_AP_L2_Business="Multi O&T Businesses" ...AND... AA_AP_Business_Impacted contains the text string "GCB Technology"
Then to avoid double counting (in case both conditions are TRUE on the same row), we perform a check on the array elements to see if they are at least 1, and if so, return the value to 1.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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