EXCEL Formula: Multiply SUMIFS outcome with the corresponding row value from a different column - excel

I am trying to use SUMIFS and multiply its output with the a values from the corresponding row. Example:
Example
In This example I will use just 1 criteria for the SUMIFS, but the concept remains the same:
SUMIFS(C2:C5; B2:B5; "=Sum"). This would return 5 + 6 = 11
Now I want to multiple that by the corresponding probability. Meaning 5 * 50% + 6 * 20%: SUMIFS(C2:C5; B2:B5; "=Sum") *
Any idea how to include the probability in the equation?
Thanks!

You can't use SUMIFS for this unless you add a helper column - try using SUMPRODUCT instead
=SUMPRODUCT((B2:B5="Sum")+0;C2:C5;D2:D5)
SUMPRODUCT multiplies all the arrays/ranges and then sums the result, so we can include your value and probability ranges with a conditional array based on "Sum" in the include range
With a helper column you can just use column E to multiply C and D, e.g. this formula in E2 copied down
=C2*D2
and then use SUMIFS like this
=SUMIFS(E2:E5;B2:B5;"Sum")

Related

SUMIF but for products?

I have a table like the following:
X 1
X 3
X 2
Y 2
Y 5
Z 3
Z 4
I know I could use SUMIF to calculate the sum of the second column for each value in the first column, e.g., =SUMIF(A1:A7,"X",B1:B7) would give me the sum of values for X: 1+3+2=6. However, I want the product of values in the second column for each value in the first column. I.e., the output would be:
A 6
B 10
C 12
When I try to search for SUMIF but for product, I only see suggestions to use SUMPRODUCT, but that multiplies arrays together and then adds their values, whereas I don't want to sum anything, just multiply all the values within a column.
My only idea is to create a new column with the log of the values, then do EXP(SUMIF(...)) to get the product. However, this will not work if any values are 0 or negative. Is there any way to directly compute the product I want?
If one has the Dynamic Array formula FiLTER:
=PRODUCT(FILTER(B1:B7,A1:A7="X",0))
You can also use a Pivot Table:
There are probably cleverer* ways, but you could use this array formula:
=PRODUCT(IF($A$1:$A$7=D1,$B$1:$B$7))
*Edit - as I said, see Scott's answer. I always forget the new formulas.

How to make countifs and sumifs operate as "OR" instead of "AND"

I am trying to make a formula that uses SUMIFS and COUNTIFS to find an average of numbers with one of two criteria from different columns. So I want it to add the numbers in one column if the criteria is met in either range 1 or range 2 or both, not if its met only for both. And I need to do the same for the COUNTIFS.
Right now I have it formatted as
=SUM(SUMIF(XX:XX,"<130"ZZ:ZZ),SUMIF(YY:YY,"<80",ZZ:ZZ))/SUM(COUNTIF(XX:XX,"<130"ZZ:ZZ),COUNTIF(YY:YY,"<80",ZZ:ZZ))
But I know it is adding some numbers twice since it goes down both columns and counts the ones that have both, twice.
This is my attempt in using COUNTIF to work as COUNTIFS as an OR operator instead of AND, does anybody have any suggestions?
You can do it combining 2 SUMPRODUCTS, 1 to get the sum of all values that met criteria, and a second one to count how many values met criteria, and then do the average.
In this case I want to get the average of values in column A only if column B or C equals to 1. The green values are the only ones that meet this requirement, a total of 8 values.
If we do (3+4+5+7+8+9+11+12) we get 59, and 59/8=7.375, the result of my formula
My formula is:
=SUMPRODUCT(--(((B1:B15<2)+(C1:C15<2))<>0);A1:A15)/SUMPRODUCT(--(((B1:B15<2)+(C1:C15<2))<>0))
The first SUMPRODUCT will return the sum value:
SUMPRODUCT(--(((B1:B15<2)+(C1:C15<2))<>0);A1:A15)
This is how it works:
(B1:B15<2) will return an array or False/True if value is <2. In this case we get {0;0;1;1;1;0;0;1;1;0;1;1;0;0;0}
(C1:C15<2) same than before, but in column C, so we get {0;0;1;1;1;0;1;1;0;0;1;1;0;0;0}
--(((B1:B15<2)+(C1:C15<2))<>0) The double unary operator will check if the sum of both previous arrays are distinct to 0 (that means that ROW is valid), returning 1 if true, 0 if false. so it returns {0;0;1;1;1;0;1;1;1;0;1;1;0;0;0}
We multiply array from step 3 with values in column A and we sum them up, obtaining 59
The second SUMPRODUCT works exactly the same, but there isn't step 4, so we get just a sum of 1 and 0 to get how many values meet criteria, in this case 8.
And finally 59/8=7.375

Why excel SUMIF with range criteria does not work as expected?

I have 3 columns A, B, C. Now, I want to get the sum for each cell Ai where
Bi < Ci
Example:
A B C
-----------
2 1 3
4 5 4
3 2 7
6 6 6
-----------
Expected result = A1 + A3 = 2 + 3 = 5
I tried the following formula: =SUMIF(B1:B4,"<C1:C4",A1:A4),
but it gives me 0 !
Anyone could help ?
The SUMIF function accepts 3 arguments: range, criteria, and sum_range.
If you check the documentation, you'll notice that while range and sum_range both accept a "range of cells" (i.e. multiple values), criteria is a single value, the same thing compared against all of the cells in range. If you do put a Range or Array in, then it will only use the first item.
{EDIT} Unless the entire function is part of an Array Calculation, in which case you will get an array of SUMIF for each item in the Array - e.g. {=SUM(SUMIF(A1:A4,{1,2}))} is the same as {=SUM({SUMIF(A1:A4,1), SUMIF(A1:A4,2)})}
This means, you can do =SUM(B1:B4,"<" & MIN(C1:C4),A1:A4) to add up where the values in column A where the value in column B is smaller than all the values in column C, but for a row-by-row comparison you will need an Array Formula or SUMPRODUCT, like so:
=SUMPRODUCT(A1:A4*--(B1:B4<C1:C4))
You can use this array formula:
{=SUM(IF(B1:B4<C1:C4,A1:A4))}
You'll need to apply it with Ctrl + Shift + Enter.
You know that you set the array formula correctly when you see the curly brackets around the formula

Formula to sum items in a column only if other column has specific value

I have an excel table with 2 columns. First column contains a string such as A,B,C and second column contains numbers. I want to obtain sum of numbers in each row if text of first column for that row is equal to given text.
For example:
A 2
C 3
B 4
A 1
C 3
formula(A) = 3
formula(B) = 4
formula(C) = 6
and so on.
One way to achieve this is via SubTotal option. Follow the example in this link Creating subtotals
Another way to do the same is using sumif function follow this link Sumif function
SUMIFS() is capable of doing this. As is SUMPRODUCT()
In european excel this would look like this. I don't know where your reference is so I am putting it in a cell named Reference.
SUMIFS($B:$B;$A:$A;"="Reference)
If you want a "running" count, then replace the arrays - from $B:$B to B$2:B2 and similar with $A:$A, and copy it down the rows.

using OR within a sumproduct

I have a table:
a 1
b 2
c 3
and I want to use a SUMPRODUCT that will give me the total if the cell is a or b.
I have a cell that shows:
a/b
and I want to use either SUMIF or SUMPRODUCT to give me the total if it is a or b.
I wrote this:
=SUMPRODUCT(--(A2:A4=LEFT(A7,1)))
Do you think there is a way to use an OR within the SUMPRODUCT so that it can check for b within the table and give the total of that?
In a SUMPRODUCT formula OR is +. AND is *
=SUMPRODUCT(--(A2:A4=LEFT(A7,1))+(A2:A4=LEFT(B7,1))

Resources