A B C D E F G H
1 Products Date Sales Criteria 1: Product_B Result: 200
2 Product_A 2020-04-15 500 Criteria 2: 2020-04-15
3 Product_B 2020-04-12 600
4 Product_B 2020-04-12 300
5 Product_B 2020-04-15 200
6 Product_B 2020-04-20 400
7 Product_C 2020-04-15 800
8 Product_C 2020-04-19 900
9 Product_C 2020-04-30 300
10
11
In the table above I have different products and their sales on a certain date.
In Cell G1 I calculate sum of the sales based on the criterias in Cell E1 and E2.
G1 = SUMPRODUCT((($A$2:$A$100=$E$1)*($B$2:$B$100=$E$2)*$C$2:$C$100))
All this works exactly as it should.
Now, I want to include an IF-Condition that says if you enter the words "All Products" into Cell E1 the product condition ($A$2:$A$100=$E$1) in the SUMPRODUCT should not be applied.
Therefore, I tried to go with this:
= SUMPRODUCT((IF(E1="All Products",1,($A$2:$A$100=$E$1))*($B$2:$B$100=($E$2))*$C$2:$C$100))
Unfortunately, this solution only works if I enter "All Products" into Cell E1.
Once I switch back to Product_B it displays 0 instead of 200.
What do I need to change to make it work?
NOTE:
I know one solution could be to split the SUMPRODUCT into two formulas like this:
=IF(E1="All Products",SUMPRODUCT((($B$2:$B$100=$E$2)*$C$2:$C$100)),SUMPRODUCT((($A$2:$A$100=$E$1)*($B$2:$B$100=$E$2)*$C$2:$C$100)))
However, I would prefer a solution with one SUMPRODUCT-Formula.
With SUMIFS:
=SUMPRODUCT(SUMIFS($C:$C,$A:$A,IF(E1="All Products","*",$E$1),$B:$B,$E$2))
Combining with your LAST QUESTION
=SUMPRODUCT(SUMIFS($C:$C,$A:$A,IF(E1="All Products","*",$E$1),$B:$B,$E$2:$E$3))
Modify the column A criteria as follows:
=SUMPRODUCT((($A$2:$A$100=$E$1)+($E$1="All Products")*($A$2:$A$100=$A$2:$A$100))*($B$2:$B$100=$E$2)*$C$2:$C$100)
The new factor +($E$1="All Products")*($A$2:$A$100=$A$2:$A$100) will ensure a vector of all 1 with the appropriate input in E1:
Array (Control+Shift+Enter) formula in F2
=SUMPRODUCT(IF((E1<>"All Products"),(A2:A9=E1),TRUE)*(B2:B9=E2)*(C2:C9))
Following Array formula is better than the above one. If you enter anything that doesn't match in column A it will consider it as "All Products"
=SUMPRODUCT(IF(COUNTIF(A2:A9,E1)=0,TRUE,(A2:A9=E1))*(B2:B9=E2)*(C2:C9))
OR
=SUMPRODUCT(IF(ISNA(MATCH(E1,A2:A9,0)),TRUE,(A2:A9=E1))*(B2:B9=E2)*(C2:C9))
Related
End-goal: A column with the subtotals of groups (defined in the below table as all foods listed above Zucchini, incl Zucchini).
Current attempt: create a column to define groups using COUNTIF('count all 'zucchini' thus far'). Then use SUMIF to get the total cost for the current group.
Problem: I don't know how to do this without the COUNTIF column (since SUMIF needs range C:C to be resolved first). I'd like to have it in a single formula. I looked into array formulas but not sure if/how to apply that here.
FOOD COST COUNTIF(A2:A$2;"Zucchini") SUMIF(C:C;C2;B:B)
Apple 3 0 12
Pecan 7 0 12
Zucchini 2 0 12
Apple 4 1 23
Olive 8 1 23
Pecan 6 1 23
Zucchini 5 1 23
Apple 4 2 16
Olive 9 2 16
Zucchini 3 2 16
Any ideas on how to solve either the current problem or the end-goal problem? Thanks!
Put this in C2 and copy down:
=IF(A2="Zucchini",SUM($B$1:B2)-SUM($C$1:C1),"")
It basically sums everything to the row and subtracts what is already accounted for.
I have a sheet in WB1 that looks like this:
A B C
Row Supplier PO_Date Delivery_Days
...
2091 A 8/2/2018 5
2092 B 8/5/2018 4
2093 C 8/7/2018 1
2094 B 8/8/2018
2095 B 8/8/2018 -7
2096 B 8/8/2018 -7
2097 C 8/17/2018 5
2098 D 8/22/2018
2099 D 8/22/2018 2
2100 A 8/28/2018 -3
2101 E 8/30/2018 4
2102 A 8/31/2018
2103 A 8/31/2018 12
...
And in WB2, I have a cell that is meant to calculate the average delivery days, but only including specific suppliers and adjustable start and end dates in cells B1 and B2. That function looks like this:
=AVERAGE(AVERAGEIFS('[WB1.xlsx]Sheet 1'!$C:$C,
'[WB1.xlsx]Sheet 1'!$A:$A, {"A", "B", "C"},
'[WB1.xlsx]Sheet 1'!$B:$B,">=" & B1,
'[WB1.xlsx]Sheet 1'!$B:$B,"<=" & B2))
This function does not produce the value I want, though. I want to calculate the average delivery days for all the POs from these specific suppliers, not the average of the average delivery days for the POs for each supplier. (Basically, I want to sum up all the Delivery Days ONCE, not sum and divide within each supplier, then sum and divide those averages.)
How do I need to change the formula? Or should I use a different formula all together?
posting comment as answer so this can be marked appropriately in the queue:
have you tried sumifs() then countifs() so you divide those to get your average, ensuring only one division? – Cyril 31 mins ago
#Cyril Hadn't thought of that, but just implemented it and it's working great. Thank you. – Millie 15 mins
I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0
What I want to do (if possible) is sum each metric of each transaction with a common customer_id in ONE STEP. The output should look like the "DESIRED OUTPUT" sheet. I know some sort of lookup will need to be used to reference the "CUSTOMER LOOKUP" table.
I can see how to accomplish this using VLOOKUP then SUMIF (or the other way around), but I would like to accomplish it using a single formula if possible.
TRANSACTIONS
transaction customer_id metric_1 metric_2
1 1 0 564
2 1 0 762
3 1 5.305 8367
4 2 0 150
5 2 3.125 4109
6 2 6.18 1853
7 3 0 61
8 3 0 1
9 3 0 4
CUSTOMER LOOKUP
customer_id customer_name
1 XXX
2 YYY
3 ZZZ
DESIRED OUTPUT
customer_name metric_1 metric_2
XXX 5.305 9693
YYY 9.305 6112
ZZZ 0 66
I doubt it can be done with one formula. This is a very common scenario and is typically solved by adding a Vlookup column to the first table to show the customer name.
Then you can build a pivot table with a few clicks.
I guess, since using a pivot table does not involve formulas, the only formula you need is the Vlookup. So, yes, it can be done with one formula ;-)
Phone number Provider Duration (min)
1001 Fastcom 2
1002 Fastcom 1
1004 Mobilecom 4
1008 Telecom 5
1001 Fastcom 3
1001 Fastcom 2
1003 Telecom 3
1004 Mobilecom 2
1008 Telecom 6
1002 Fastcom 1
I want to use one formula to get the sum of the duration of calls whose service provider is the provider for the phone number 1001. I hope this revised version is clearer than the previous one. Again, thanks to all who paid attention.
There are 14 rows. Column A contains numbers from 1 to 14. Column B contains Names of people(maybe repeated). Column C contains their preferred seasons (possible more than 1) and Column D contains how many days they do sports in that partucular season. I need one formula to get how many days are spent doing sports in the season(s) that is (are) preferred by Adam, which actually are Spring and Fall
Assuming data in rows 2 to 15 try this array formula
=SUM(IF(ISNUMBER(MATCH(C2:C15,IF(B2:B15="Adam",C2:C15),0)),D2:D15))
confirmed with CTRL+SHIFT+ENTER
In one formula I'm not sure. Personally I'd have a formula in each row of column E that is 0 or the value from D, then you can sum(e:e) instead.