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: 6

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You're formula looks fine. If you try
Excel Formula:
=COUNTIF(HRData[Job Band],$B$8)
does it give the correct number?
 
Upvote 0
Try this.
Excel Formula:
=IF($B$8="All Employees",  SUMPRODUCT(--(YEAR(HRData[Start Date])=$A$8)), SUMPRODUCT(--(YEAR(HRData[Start Date])=$A$8),--(HRData[Job Band]=$B$8)))
 
Upvote 0
Hi,
Thanks for replying so quickly.

Where would I put your suggested formula inside the sumproduct statement?
 
Upvote 0
No just put it in a cell on it's own
 
Upvote 0
So it gives the correct total value of all rows with MM?
 
Upvote 0
In that case I see no reason why your formula doesn't work, as it works for me.
What makes you think it's not working?
 
Upvote 0
In that case I see no reason why your formula doesn't work, as it works for me.
What makes you think it's not working?


Sorry maybe I'm not making sense or missing something.

The formula you suggested works when Job Band selected is not "All Employees".
It won't work if user selects "All Employees" as "All Employees" does not exist as a job band.
If user selects "All Employees" with your formula, then the result will return 0.
If user selects "All Employees" the result should return a count of all the entries for the specified year regardless of "Job Band".

Hope this makes sense. :)
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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