SUMPRODUCT with nested If statement

Moeey

New Member
Joined
Sep 13, 2014
Messages
34
Hi everyone,
Hope you're all well.

I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT formula.

The formula is trying to count all the entries in "HRData" table, for the specified year and "Job Band".
If the job band selected is "All Employees" then count all the entries for the specified year.
If the job band selected is not "All Employees" then only count the selected "Job Band" for the specified year.
The formula only seems to work for "All Employees".
There are no "errors" for the formula.

I think the problem lies with the "else" part of the IF statement.
From what I can gather, the "else" part of the IF statement, is only reading one row of the table.

Here's the formula,
=SUMPRODUCT((YEAR(HRData[Start Date])=$A$8)*(IF($B$8="All Employees",TRUE(),HRData[Job Band]=$B$8)))

1601042599535.png


This is what my "HRData" table looks like.
There are 10,000 entries in the table.
1601043192201.png


I hope this makes sense.
Thanks for looking.

Mo
 

Attachments

  • 1601041946158.png
    1601041946158.png
    12.6 KB · Views: 8
  • 1601042007603.png
    1601042007603.png
    28.5 KB · Views: 7
The formula seems to be working as expected on everyone's Excel except mine.
See my previous post regarding the formula when evaluated.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Insert a few rows above the range of data that you posted.
Copy the formulas that I suggested and then check the results.


Did you try the formula that I suggested?
You need the correct syntax to use the or component.
 
Upvote 0
You could use the following; it yields the same results.

T202009c.xlsm
ABCD
82013All Employees25
92013MM10
1dd
Cell Formulas
RangeFormula
D8:D9D8=IF(B8="All Employees",SUMPRODUCT(--(YEAR(HRData[Start Date])=A8)),SUMPRODUCT(--(YEAR(HRData[Start Date])=A2),--(HRData[Job Band]=B2)))
 
Upvote 0
You could use the following; it yields the same results.

T202009c.xlsm
ABCD
82013All Employees25
92013MM10
1dd
Cell Formulas
RangeFormula
D8:D9D8=IF(B8="All Employees",SUMPRODUCT(--(YEAR(HRData[Start Date])=A8)),SUMPRODUCT(--(YEAR(HRData[Start Date])=A2),--(HRData[Job Band]=B2)))

Dave,
I think I'll use this one

=SUMPRODUCT(--(YEAR(Table2[Start Date])=A5),--(Table2[Job Band]=B5)+(B5="All Employees"))

Very grateful for your work on this, thank you. :)
Still curious though, as to why my original formula works for others and not me.
 
Upvote 0
"Still curious though, as to why my original formula works for others and not me. "

The If Function and/or * syntax with your original formula dictates that it must be Array Entered.
New versions of Excel may consider the formula an array formula and may not require array enter.
N.B. I did not check this with Excel 365.
With "All Employees" , it does not matter; it is equivalent to Count of Dates * 1.

T202009c.xlsm
ABCDEFGH
82013All Employees252525
92013MM#VALUE!#VALUE!
102013MM1010
1dd
Cell Formulas
RangeFormula
F8:F9F8=SUMPRODUCT((YEAR(HRData[Start Date])=A8)*(IF(B8="All Employees",TRUE(),HRData[Job Band]=B8)))
G8:G9G8=SUMPRODUCT((YEAR(HRData[Start Date])=A8)*(IF(B8="All Employees",1,HRData[Job Band]=B8)))
H8H8=SUMPRODUCT((YEAR(HRData[Start Date])=A8)*1)
F10F10=SUMPRODUCT((YEAR(HRData[Start Date])=A10)*(IF(B10="All Employees",TRUE(),HRData[Job Band]=B10)))
G10G10=SUMPRODUCT((YEAR(HRData[Start Date])=A10)*(IF(B10="All Employees",1,HRData[Job Band]=B10)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,980
Members
448,934
Latest member
audette89

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