SUMIFS with multiple criteria and OR logic in multiple columns - excel

I found here an example for doing a sumifs with multiple criteria and OR logic, but I tried with multiple to do it for multiple columns and it is not working.
Here is an example. Base on this dataset:
A1 B1 C1 D1
B X u 11
B X u 22
A X t 22
B X t 22
I'm using the following formula:
=SUM(SUMIFS(D:D,B:B,"X",A:A,{"A","B"},C:C,{"t","u"}))
I get 55 as a result in the formula, but it should be 77 instead
If I change last row of the dataset it calculates correctly like:
A1 B1 C1 D1
B X u 11
B X u 22
A X t 22
A X t 22 --> Column A1 value changed from B to A
Is it possible to have multiple columns with multiple OR values?

Try,
=SUM(SUMIFS(D:D, B:B, "X", A:A, {"A","B"}, C:C, TRANSPOSE({"t","u"})))
By changing the 'direction' in which the second array of criteria is read, you get all possible combinations instead of paired combinations.

I was working on the same lines as #Jeeped but came up with
=SUM(SUMIFS(D:D,B:B,"X",A:A,{"A","B"},C:C,{"t";"u"}))
in order to change the direction of the second array.
Note: I don't know how you would easily extend this to include another set of criteria because you need another 'dimension'. As far as I can see it would have to look like this
=SUM(SUMIFS(D:D,B:B,{"X","X","X","X","Y","Y","Y","Y"},A:A,{"A","A","B","B","A","A","B","B"},C:C,{"t","u","t","u","t","u","t","u"}))

Related

Populate summary "table" column based on details "table"

I've tried looking up how this might be done, but it's a bit beyond my excel-fu, unfortunately (I could do it in SQL in a snap!).
Basically, in one worksheet, I have the following details "table" (I've included the column and row labels):
A B C D
1 owner name line # run?
2 A A1 10 Y
3 A A1 20 N
4 A A2 2 Y
5 A A2 14 Y
6 A A3 34 N
7 B B1 26 Y
8 B B1 59 Y
9 B B1 193 Y
10 B B1 194 Y
11 B B2 27 N
12 B B2 51 N
and I have the following summary "table" on a different worksheet
A B C
1 owner name status
2 A A1
3 A A2
4 A A3
5 B B1
5 B B2
I need to populate the status column in the summary "table" based on the run? column in the details "table", linked on the owner and name columns.
Here are the results I'm expecting to get, along with why:
A B C D
1 owner name expected status reason
2 A A1 Partial There are Y and N values for owner=A and name=A1 in the details table
3 A A2 Complete There are only Y values for the owner=A and name=A2 in the details table
4 A A3 Not Started There are only N values for the owner=A and name=A3 in the details table
5 B B1 Complete There are only Y values for the owner=B and name=B1 in the details table
5 B B2 Not Started There are only N values for the owner=B and name=B2 in the details table
I know I'll probably need countifs to work out if there are Y's and N's present, plus an IF to turn the output into the words, it's the getting to the point where I can count the Y's and N's present for each owner+name that I'm struggling with.
I have googled how I might find out if there were Y's and/or N's present for a given owner and name, and have come across this link which involves MATCH and INDEX but for the life of me, I can't get it working - I get an output of #N/A, using the following formula to get the first status:
=INDEX(A2:D12,0,MATCH(c2,'<Detail worksheet>'!A2:D12,0))
Am I on the right lines or is there a better way of doing this? (I could always manually specify the range of rows to look down in the details "table" for each summary "table" row, but I'd like to avoid that if possible!)
I split the formula into two parts, which should get you most of the way there. If you have an uncertain length of data, then be careful with how many rows you examine, my answer only goes to row 13.
Summary Sheet with columns added to split formula
Sheet 1
The formula for the Y column in the above picture is:
=COUNTIFS(Sheet1!$E$3:$E$13,Sheet2!$D$2,Sheet1!$B$3:$B$13,Sheet2!$B3,Sheet1!$C$3:$C$13,Sheet2!$C3)

Find The Highest Value And Return Adjacent Cell Value with duplicates In Excel

I am having an excel with below table
A B
Name Score
A 80
B 45
C 34
D 45
E 99
F 99
G 99
In the above table E, F and G's scores are same (sharing the maximum value).
I am trying to achieve the Top 3 'Names' and hence trying the formula -
Max 2nd =INDEX(A1:A8,MATCH(LARGE(B1:B8,2),B1:B8,1))
Max 3rd =INDEX(A1:A8,MATCH(LARGE(B1:B8,3),B1:B8,1))
However, I am getting the FIRST name's 'E' only for the rest of the maximum. values.
I am expecting F and G to be displayed the next.
Can anyone please help.
Thanks in advance
You will need a list of the scores that you can increase the LARGE's k parameter using COUNTIF. This can be something as simple as the following in an unused cell and filled down,
=large(b$2:b$8, row(1:1))
Now use this formula beside the list you just created and fill down.
=INDEX(A:A, AGGREGATE(15, 7, ROW(A:A)/(B$1:B$8=E2), COUNTIF(E$2:E2, E2)))

Sum the values of if statements on multiple rows? (Excel)

Say I have a spreadsheet which looks like this:
A B C
1 In Actual Predicted
2 Thing One 300
3 Thing Two 564
4 Thing Three 256 1065
I want to be able to get a sum of the "predicted" column which incorporates values from the "actual" column if the "predicted" value is empty.
I.e. in this case, the value would be 300 + 564 + 1065 = 1929.
I know that I can achieve this for any individual row like so:
IF(C2="",B2,C2)
How do I get a sum of these "if" statements for each individual row?
Thanks.
That can be done with Sumifs() and no helper columns
=SUMIFS(B:B,C:C,"")+SUM(C:C)
Cell D2 = IF(C2="",B2,C2)
Cell D3 = IF(C3="",B3,C3)
...drag / copy to all relevant D cells...
Cell E1 = Sum(D:D)

Logical calculation in Excel

I need advice/help. I am working on calculation in excel where I have data like mentioned below.
. A B C D E F G H
1| A275 A277 A273 A777 A777 TOTAL A222 GRAND TOTAL
2| 5 7 4 3 4 7 7
Now, I want to count row 2 based on the header.
Here is the condition.
If A1 <> B1 then take A1, if B1 <> C1 then take B1, if C1 <> D1 then C1, so on.
But tricky part is...
If D1<>E1 then D1 else (if E1<>F1 then E1 else (if F1 = "TOTAL" then F1 else(if F1<>G1 then F1)))
In short H2 should have 30 and not 37.
Added comments:------------------------------------
So, Basically if A1<>B1 then take A1 but if A1=B1 then take B1, but then for B1, its a same rule like if B1<>C1 then take B1, but if B1=C1 then take C1 and for C1, same rule. Stopping point will be "TOTAL". Along with these logic I need to check if any cell in row 1 is "TOTAL" then take value for same column. Now this "TOTAL" can be in any cell in row 1.
So from above table my calculation will be 5(A2) + 7(B2) + 4(C2) + 7(F2) + 7(G2) = 30
In this calculation I have not included D2 and E2 as D2=E2 so I took D2, here E2<>F2 so I should have taken E2, but as F2="TOTAL" so I took F2 and not D2 and E2.
I hope this make sense. (Sorry, I know its confusing.)
I have data in more then 100 columns.
Can this be achieved using Macro?
------------------------------------------------------------
Another pain point is data and header are dynamic, so I can't have a fix format. Logic should be in a way that can handle the dynamic data and header.
Any help or suggestion will be greatly appreciated.
I achieved the results you want with this.
Add a helper row. In cell A3 write this formula and drag it to the right:
=IF(OR(A$1=B$1,B$1="TOTAL"),0,1)
Calculate sum in say cell H4 (not H2 because if the formula refers to entire row 2 there will be circular reference):
=SUMIF($3:$3,1,$2:$2)

Count data if row is true excel

I have this Data:
var number
a 1
a 4
a 30
b 4
b 50
b 6
b 4
ab 1
I need to find the sum of each time a (var occurs X the number next column right) in excel.
In the case above the answer would be:
a = 36
b = 65
How can I write a formula for this in excel? Can I do this in excel?
Since you are counting the last one as well, I would use this formula:
=SUMIF(A:A,"*"&D2&"*",B:B)
Here, there is the value a in cell B2 and I can drag the formula down for B instead of typing a whole new formula. Handy if you have many like those to look for.
I assume that you have the table you published above in cells A1:B8. In order to do the calculating you would like to do you need to use the array-functionality in Excel. The following syntax in a cell will do:
=SUM(IF("a"=A1:A8,B1:B8))
However, instead of ENTER you need to press COMMAND+SHIFT+ENTER (I am on a Mac so it might be that Windows has a slightly different key combo. The result is that the formula now reads like:
{=SUM(IF("a"=A1:A8,B1:B8))}
This will give you 35 and not 36, but in a similar manner you could sum all the columns with 'ab' and then add that up to the sum of the 'a' columns.
Good luck!

Resources