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
Mo

The formula from your initial post works fine for me.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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)))

Hi,
Thank you very much for your quick reply.
Your formula works great.
Do you know why my formula does not work?

I would like to use the structure of my formula because I have other criterias I need to add to the formula.
Using your formula means that I would have to duplicate the other criterias which would make a very long formula.
 
Upvote 0
Mo

The original formula you posted works for me, I posted my formula before testing yours.
 
Upvote 0
The formula I suggested was just to check that your job band values didn't have any leading/trailing spaces or other hidden hidden characters.
As we have both said, there is nothing wrong with your formula & it works for both of us.
What makes you think it doesn't work?
 
Upvote 0
Mo

The original formula you posted works for me, I posted my formula before testing yours.

That's bizarre :)
I wonder if there's something about the way my Excel is set up.
Many thanks to you and Fluff for the quick response.
 
Upvote 0
The formula I suggested was just to check that your job band values didn't have any leading/trailing spaces or other hidden hidden characters.
As we have both said, there is nothing wrong with your formula & it works for both of us.
What makes you think it doesn't work?

When I cross check the results from the formula with the results from the table, they don't match.
 
Upvote 0
How are you cross checking the result?
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

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