How do you do sumif with equation? - excel

Basically, I want to do a SUMIF, but I need to enter an equation for sum_range parameter, so normally, to do a SUMIF, you write:
=SUMIF(CRITERIA_RANGE,CRITERIA,SUM_RANGE)
This is great, but what if I need to do some calculation in my summation? So for example:
=SUMIF(CRITERIA_RANGE,CRITERIA,COL1*COL2)
Is something like this possible?

SUMPRODUCT is commonly used in this case
Eg
=SUMPRODUCT((CRITERIA_RANGE=CRITERIA)*COL1*COL2)

A different answer (NOT FOR POINTS).
Explanation
The reason why you cannot use SUMIF in your scenario is because SUMIF cannot handle Arrays as sumproduct does and hence I would go with Chris's suggestion of using SUMPRODUCT
Alternative
Here is one more way to achieve what you want.
=SUM(IF(CRITERIA_RANGE=CRITERIA,COL1*COL2,""))
ScreenShot
Please note that this is an ARRAY FORMULA which means that instead of pressing ENTER, you have to press CTRL+SHIFT+ENTER

Related

How to impose ABS unto a range while taking the AVERAGEIF?

I'd like to take the AVERAGEIF of a range, more specifically calculate the average using the values in their absolute form.
Therefore I'd like to do a function such as: =AVERAGEIF(W13:W1553;"42018";ABS(O13:O1553))
But this won't work in Excel...
Can someone help? Thank you!
AVERAGEIF will not allow the manipulation of the ranges. One would need to use an array formula:
=AVERAGE(IF((W13:W1553=42018)*(O13:O1553<>""));ABS(O13:O1553)))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If one does not want to use an array formula, one can use a helper column to get the ABS of the number row.
In Z13 put =ABS(O13) then copy down to row 1553 and then use AVERAGEIF
=AVERAGEIF(W13:W1553;"42018";Z13:Z1553))

Excel - equivalent of Javascript reduce function?

Is there an Excel equivalent of the Javascript reduce function? Essentially, I want to apply a function to each cell in a range, and then sum up each result.
The reason I ask is because I have the following sheet:
For each expense, I'm calculating the "change", i.e. the amount needed to round it up to the nearest pound. I'm then summing that at the bottom.
I want to be able to do this without having the extra column and summing those values.
Thanks.
Use SUMPRODUCT(it avoids the need of Ctrl-Shift-Enter) and ROUNDUP(just shorter, personal preference):
=SUMPRODUCT(ROUNDUP(C3:C7,0)-C3:C7)
OK, so I just found out there's something called an array formula where you type your formula and then press Ctrl+Shift+Enter (and it'll put curly brackets around your formula to show that it worked).
So for my example above, I'd type
=SUM(CEILING.MATH(C3:C7)-C3:C7)
Then press Ctrl+Shift+Enter and it'd change it to
{=SUM(CEILING.MATH(C3:C7)-C3:C7)}
and that gives me the £2.11 I'm expecting.

Combine Two Formulas

I want to combine a formula that disregards cells where there is a 0 in order to average and also to disregard cells where there is an error such as DIV/0.
I have these two formulas which achieve either of these functions but not both. How would I combine them?
{=AVERAGE(IF(ISNUMBER(M2:P2),M2:P2))}
=AVERAGEIF(M2:P2,"<>0")
You would simply add the criterion of the second to the first:
=AVERAGE(IF(ISNUMBER(M2:P2)*(M2:P2<>0) ,M2:P2))
This is still an array formula and as such needs to be confirmed with Ctrl-Shift-Enter instead of Enter. If done properly then Excel will put {} around the formula.
you could use an if() to check for either condition then use the appropriate average function.
#Scott : better than mine...

IF function with two cell ranges

I have two sheets with the same line of cells, for example, A1:A5.
I need to check if the value of every cell in Sheet1!A1:A5 is equal to Sheet2!A1:A5 but the hitch is the values will be letters, and all values are different. Simply typing the formula got me a #VALUE! error.
I know I can just write the formula:
=IF(Sheet1!A1=Sheet2!A1;1;0)
and then simply retype it in a number of cells with different values, but I'm looking for a way to shorten the formula.
Any suggestions?
To shorten the formula use array function. With that you will be able to check the whole range at once.
=IF(AND(Sheet1!A1:A5=Sheet2!A1:A5);1;0)
After typing the formula press Ctrl+Shift+Enter instead of just Enter key to confirm array formula.
This one is a little shorter
=(Sheet1!$A1=Sheet2!$A1)
You could use
AND(EXACT(Sheet1!A1, Sheet2!A1), EXACT(Sheet1!A2, Sheet2!A2), EXACT(Sheet1!A3, Sheet2!A3), EXACT(Sheet1!A4, Sheet2!A4), EXACT(Sheet1!A5, Sheet2!A5))
But in the following way:
Have a separate column with the code (let's say, column G)
EXACT(Sheet1!$A1, Sheet2!$A2)
To the column next to that, have a single cell with the code
AND(G1:G5)
Use the AND() function:
IF(AND(Sheet1!A1=Sheet2!A1,Sheet1!A2=Sheet2!A2,Sheet1!A3=Sheet2!A3,Sheet1!A4=Sheet2!A4,Sheet1!A5=Sheet2!A5),1,0).
EDIT
Not realy sure about your aim,
If you want it short because it is too difficult to write the above function, then try the method below:
=IF(CONCATENATE(Sheet2!A1,Sheet2!B1,Sheet2!C1,Sheet2!D1,Sheet2!E1)=CONCATENATE(Sheet1!A1,Sheet1!B1,Sheet1!C1,Sheet1!D1,Sheet1!E1),1,0)
But this is not without catch, it could return false positive. So use it with care. To overcome the false positive, I could only make the formula longer (but still relatively easy to write out).
=IF(CONCATENATE(Sheet2!A1,"|",Sheet2!B1,"|",Sheet2!C1,"|",Sheet2!D1,"|",Sheet2!E1)=CONCATENATE(Sheet1!A1,"|",Sheet1!B1,"|",Sheet1!C1,"|",Sheet1!D1,"|",Sheet1!E1),1,0)

Using SUMPRODUCT with TRANSPOSE

I'm trying to use TRANSPOSE inside SUMPRODUCT. What's wrong with my formula?
I use Excel 2013 if that matters.
Your formula is correct, you just need to press Crtl+Shift+Enter to confirm it and make it an array formula. In some cases SUMPRODUCT will sometimes automatically handle array treatment of arguments, but a TRANSPOSE argument apparently is not among them.
I'm not sure what result you want but would be interested to know whether:
=MMULT(D9:F9,D3:D5)
entered with Ctrl+Shift+Enter is such.

Resources