# SUMPRODUCT with nested If statement

#### Moeey

##### New Member
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)))

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

I hope this makes sense.
Thanks for looking.

Mo

#### Attachments

• 1601041946158.png
12.6 KB · Views: 3
• 1601042007603.png
28.5 KB · Views: 1

### 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
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
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
Hi,

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

#### Fluff

##### MrExcel MVP, Moderator

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

#### Moeey

##### New Member
No just put it in a cell on it's own

The formula you suggest works fine for all entries, apart from when "All Employees" is selected.

#### Fluff

##### MrExcel MVP, Moderator

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

#### Fluff

##### MrExcel MVP, Moderator
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
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.

Replies
16
Views
123
Replies
1
Views
38
Replies
5
Views
57
Replies
8
Views
76
Replies
3
Views
46

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