Home » excel » excel – SUMIF statement returns a value from the incorrect row

# excel – SUMIF statement returns a value from the incorrect row

Posted by: admin May 14, 2020 Leave a comment

Questions:

My current formula on Worksheet1 is below:

``````SUMIF(Setup!\$C\$5:\$C\$375,"C-R",'PMS Input'!\$K\$13:\$K\$416)
``````

On the Setup worksheet, I have confirmed that there is only one C-R in column C.

``````Row C39 C-R CAMPSITES
Row C40 G-S GROUP SHELTER
Row C41 G-S PICNIC SHELTER
Row C42 P-A SQUIRREL'S NEST
Row C43 P-A MISC. PARK REVENUE/VENDING
Row C44 P-A MINIATURE GOLF
Row C45 P-A CANOE RENTALS
Row C46 P-A BICYCLE RENTALS
Row C47 P-A PROGRAMMING FEES
Row C48 P-A MISC. PARK REVENUE/VENDING
``````

On the PMS Input worksheet, the rows are as follows:

``````Row K48    CAMPSITES                   9     18.25
Row K49    GROUP SHELTER               -     -
Row K50    PICNIC SHELTER              -     -
Row K51    SQUIRREL'S NEST             -     (195.00)
Row K55    BICYCLE RENTALS             -     -
Row K57    PROGRAMMING FEES            -     108.00
Row K58    MISC. PARK REVENUE/VENDING  -     -
``````

On Worksheet1, the value returned for the above formula looking for C-R is 0.

The actual responses should be `C-R = 18.25`. The incorrect response in consistent throughout the file.

I have three other locations using the same file, with no issues using the above formula.

Another formula issue:

``````=SUMIF(\$B\$63:\$D\$82,"TIPS",R\$63:R\$82)
``````

This formula is returning a value of `17`, however there is no `17` in column R. The `17` is actually in column T. This same error is repeating on several other days.

I have compared, checked and re-checked the formulas, but to no avail.

Could this just be a problem with the overall worksheet, or have I been staring at my numbers too long?

How to&Answers:

On the second issue you need to know that SUMIF always works on a “one to one” basis. That means that both ranges need to be the same size and shape. If the second range isn’t the same size and shape as the first then Excel implicitly makes it so, starting from the top left cell of range 2.

In short that means that with your formula like this:

`=SUMIF(\$B\$63:\$D\$82,"TIPS",R\$63:R\$82)`

The sum range is extended to be the same size as the criteria range so that formula will do the same as this

=SUMIF(\$B\$63:\$D\$82,”TIPS”,R\$63:T\$82)

Note: second range covers 3 columns like the first. If any value in colums C and D are “TIPS” it will sum the relevant value from column S or T, so that’s probably where your 17 comes from.

Can you explain in words what you are trying to do with this formula? Do you want to sum column R only if any value in B, C or D is equal to “TIPS” – what if all 3 cells are equal to “TIPS” in one row, do you want to sum column R 3 times for that row?

### Answer：

Your lookup and your values are not aligned correctly. C-R is on C39, and the value is on K48. They are 9 rows apart. However the lookup and values in your equation start eight rows apart.

So either you have an extra row in PMS or missing a row in Setup, or you just started at the wrong row and something like this would fix it:

``````SUMIF(Setup!\$C\$5:\$C\$375,"C-R",'PMS Input'!\$K\$14:\$K\$416)

SUMIF(Setup!\$C\$4:\$C\$375,"C-R",'PMS Input'!\$K\$13:\$K\$416)
``````

### Answer：

to fix the second issue you’ll need the following formula (based on the great detail provided by barry in his answer)

``````=SUMIF(\$B\$63:\$B\$82,"TIPS",\$R\$63:\$R\$82)+SUMIF(\$C\$63:\$C\$82,"TIPS",\$R\$63:\$R\$82)+SUMIF(\$D\$63:\$D\$82,"TIPS",\$R\$63:\$R\$82)
``````