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: 3
  • 1601042007603.png
    1601042007603.png
    28.5 KB · Views: 1

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,015
Office Version
  1. 365
Platform
  1. Windows
You're formula looks fine. If you try
Excel Formula:
=COUNTIF(HRData[Job Band],$B$8)
does it give the correct number?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,804
Office Version
  1. 365
Platform
  1. Windows
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)))
 

Moeey

New Member
Joined
Sep 13, 2014
Messages
34
Hi,
Thanks for replying so quickly.

Where would I put your suggested formula inside the sumproduct statement?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,015
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

No just put it in a cell on it's own
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,015
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

So it gives the correct total value of all rows with MM?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,015
Office Version
  1. 365
Platform
  1. Windows
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?
 

Moeey

New Member
Joined
Sep 13, 2014
Messages
34
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. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,108,538
Messages
5,523,428
Members
409,522
Latest member
szophie

This Week's Hot Topics

Top