SUMIFS with mutliple OR/AND criterias (using a cell reference) - excel

A B C D E F G E
1 Products Suppliers Value Criteria 1: Product_C Result: 600
2 Product_A Supplier_01 500 Criteria 2: Supplier_01
3 Product_B Supplier_01 600 Criteria 3: Supplier_03
4 Product_B Supplier_02 300
5 Product_C Supplier_01 200
6 Product_C Supplier_01 400
7 Product_C Supplier_03 800
8
9
In the table you find a list of different Products (Column A) and Suppliers (Column B).
In Cell G1 I want to get the sum of the values in Column C if the following conditions are met:
Product = Product_C AND
Supplier = Supplier_01 OR Supplier_03
Those conditions are typed in as Criteria 1-3 in Cells E1:E3.
In order to achieve this I tried to go with the solution from these questions (Q1,Q2) which gives me the correct result:
G1 =SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,{"Supplier_01","Supplier_02"}))
However, my issue with this solution is that I need to enter the OR-criterias manually as {"Supplier_01","Supplier_02"}. How do I have to change my formula so I can refer to the values in Cells E2:E3 so if the user changes those values the result is automatically adjusted?

One possibility:
=SUMPRODUCT((A2:A7=E1)*((B2:B7=E2)+(B2:B7=E3))*C2:C7)
It will be easy to extend criteria in the same fashion for both column A and B.

I was going to say that you need to transpose E2:E3. I think this is true in general, but in this particular case with only a single criterion applying to column A, you don't need to:
=SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,$E$2:$E$3))
works if entered as an array formula.
If you have multiple criteria for A and B, you do need to transpose one set of criteria:
=SUM(SUMIFS($C:$C,$A:$A,$E$1:$E$2,$B:$B,TRANSPOSE($E$3:$E$4)))

try this
=SUM(SUMIFS($C:$C,$A:$A,$E$1,$B:$B,E2:E3))
or
=SUM(IF(($A$2:$A$7=E1)*(($B$2:$B$7=E2)+($B$2:$B$7=E3)),$C$2:$C$7,0))

Related

Excel Index Match Sumifs

I have a table of data where column headers are account numbers, and I'm trying to sum all data for a specified account when one column (left hand column) equals a certain number.
724| 453 | 345
1 90 0 2
2 91 1 3
3 80 5 4
So would like a formula that would sum account 453, or 345 if values in first column are less than 2. I've written an index/match function to find the column for a specified fund. But can't seem to add in the sumif or sumifs to help sum. if there is a better way, please help.

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

Sort list by the difference between two values

I have the following Excel spreadsheet:
A B C D
1 Budget Actual Sort by Variancy (descending)
2 Product A 500 250 Product F
3 Product B 900 800 Product D
4 Product C 300 450 Product C
5 Product D 400 600 Product B
6 Product E 700 300 Product A
7 Product F 150 900 Product E
As you can see in Column A I have listed different products and in Column B I have their budget value and in Column C the actual value.
Now, I want to list those products based on their budget-actual-variancy in Column D in a descending order (starting from the highest positive variancy).
The only formula which comes in my mind is =LARGE(B2:B7,1) but it only sorts the products by the budget values (Column B) or actual values (Column C). Not by the difference between the two values.
Do you know any formula which I can use to sort the products in Column D based on their variancy?
Please note:
I know I could add a helper column in which I calculate the differences between Column B and Column C and then go with the LARGE function on this helper column but I am looking for a solution without such a helper column.
If one has SORTBY()(Currently only available with Office 365 insiders) then put this in D2 and it will spill automatically:
=SORTBY(A2:A7,B2:B7-C2:C7,1)
You can use the following (even when there are duplicate variances):
Formula in D2:
=INDEX($A$1:$A$7,LARGE(INDEX(($C$2:$C$7-$B$2:$B$7=AGGREGATE(14,3,$C$2:$C$7-$B$2:$B$7,ROW(1:1)))*($A$2:$A$7<>D1)*ROW($A$2:$A$7),),1))
Drag down.
In case of duplicate variances it will grab the last value in column A that represents that variancy and has not been featured in column D as yet.

VLOOKUP with multiple criterias in different columns [duplicate]

This question already has answers here:
Vlookup using 2 columns to reference another
(2 answers)
Closed 3 years ago.
I have the following Excel spreadsheet:
A B C D E
1 Products Brands Revenue Search Criterias
2 Product A Brand1 500 Criteria 1: Product C
3 Product B Brand3 800 Criteria 2: Brand 3
4 Product B Brand2 900 Revenue: 300
5 Product C Brand1 200
6 Product C Brand3 300
7 Product C Brand4 750
8 Product D Brand1 450
9 Product C Brand4 150
10
As you can see in Column A I have list of products and in Column B the corresponding brands and in Column C the revenue.
Now I want to use VLOOKUP to search for the revenue based on a product (Cell E2) and a brand (Cell E3). Therefore, I tried to go with this formula:
E4 =VLOOKUP(E2&"-"&E3,A1:C9,3,FALSE)
However, this formula gives me #NV.
What do I need to change in my formula to make it work?
Please note:
I know I could solve this issue by adding a helper column in which I combine the datas from Column A and Column B and then let the VLOOKUP run over this helper column. However, I am looking for a solution without this helper column.
First of all, please note that your lookup array does not have a space while your lookup value does! That will never return a match, so address that issue first.
Furthermore, I would highly recommend to not concatenate values in a multi-criteria lookup, ever! That's very error prone. Instead use boolean logic to create an array of 1's and 0's to use the powerfull combination of INDEX and MATCH. Try to get into the habit of using that combination over VLOOKUP if you are a regular user of Excel and it's worksheet functions.
Here is a small introduction to this combination of functions. And as mentioned in that post too, INDEX will come in handy much more often as you will notice in the below example when we create our return array. This will prevent the use of having to enter as an array formula through CtrlShiftEnter =)
Formula in E4:
=INDEX(C2:C9,MATCH(1,INDEX((A2:A9=E2)*(B2:B9=E3),),0))
When you actually got numeric values under Revenue you can simply use SUMIFS, as the other answer suggest.
I would strongly recommend using SUMIFS instead of VLOOKUP because this would make sure if you have multiple same values it will add them together:
=SUMIFS(C:C,A:A,E2,B:B,E3)
But this function will only work in newer versions of Excel if you need it for an older version of excel you need to work with SUMPRODUCT
Optional you can also use an alternative VLOOKUP which would be a combination of INDEX and MATCH. There are two options, either the array formula with the "{}" can in some cases result to wrong data, but is easy to understand:
{=INDEX(C:C,MATCH(E2&E3,A:A&B:B,0))}
This is a matricial formula so the "{}" are added by Excel when you type the formula regularly by pressing CTRL + SHIFT + ENTER
otherwise use. I would always recomend using regular formulas over matricial formulas
Quote user JvdV
Formula in E4:
=INDEX(C2:C9,MATCH(1,INDEX((A2:A9=E2)*(B2:B9=E3),),0))
The shortest and fastest formula for 2 criteria Lookup is using DGET()
Table layout as below :
A B C D E F
1 Products Brands Revenue Search Criterias
2 Product A Brand1 500 Products Brands Revenue
3 Product B Brand3 800 Product C Brand3
4 Product B Brand2 900
5 Product C Brand1 200
6 Product C Brand3 300
7 Product C Brand4 750
8 Product D Brand1 450
9 Product C Brand4 150
Formula in F3 :
=DGET(A1:C9,F2,D2:E3)
and, will return the desired result : 300

Sum the values in Excel cells depending on changing criteria

In an Excel spread sheet I have three columns of data, the first column A is a unique identifier. Column B is a number and column C is either a tick or a space:
A B C
1 d-45 150 √
2 d-46 200
3 d-45 80
4 d-46 20 √
5 d-45 70 √
Now, I wish to sum the values in column B depending on a tick being present and also relative to the unique ID in column A. In this case rows 1 and 5. Identifying the tick I use
=IF(ISTEXT(C1),CONCATENATE(A1))
&
=IF(ISTEXT(C1),CONCATENATE(B1)).
This leaves me with two arrays of data:
D E
1 d-45 150
4 d-46 20
5 d-45 70
I now want to sum the values in column E depending on the ID in column D, in this case row 1 and 5. I can use a straight forward SUMIFS statement to specify d-45 as the criteria however this unique ID will always change. Is there a variation of SUMIFS I can use?
I also wish to put each new variation of ID number into a separate header with the summed totals underneath, that is:
A B
1 d-45 d-46
2 220 20
etc...
You can try this:
To get the distinct ID's write (in H1 then copy right):
This one is an array formula so you need Ctrl Shift Enter to enter the formula
=INDEX($A$1:$A$5;SMALL(IF(ROW($A$1:$A$5)-ROW($A$1)+1=MATCH($A$1:$A$5;$A$1:$A$5;0);ROW($A$1:$A$5)-ROW($A$1)+1;"");COLUMNS($A$1:A1)))
Now to get the sum (H2 and copy right)
=SUMPRODUCT(($A$1:$A$5=H1)*ISTEXT($C$1:$C$5)*$B$1:$B$5)
Data in the example is in A1:C5
Depending on your regional settings you may need to replace ";" field separator by ","
Try this,
SUMIFS
=SUMIFS(B1:B5,A1:A5,"=d-45",C1:C5,"<>")
where "<>" means that the cell is not empty...

Resources