In spreadsheet (Excel or Google Sheets), how to find the sum of multiple values with multiple rows of column headers criteria? - excel

as in the above picture, I need to sum all the values within the table C8:V22 which match
the first three characters of column B(orange),
row 5 for the number(blue),
row 6 for the first character(green),
row 7 for the first three characters(yellow)
The desire result would be the sum of the number in red, which is 10001 + 10081 + 10161 + 10221 = 40464
I tried many different ways to write the formula, one of that is:
=INDEX($B$5:$V$22,
MATCH($D$26,LEFT($B$5:$B$90,3),0),
MATCH(($F$26=$5:$5) * ($G$26=LEFT($6:$6, 1)) * (H26=LEFT($7:$7,3)), 0))
and pressed Ctrl+Shift+Enter to make it as an array formula, but couldn't figure out where is the error.
Anyone could help on this? Thank you!
Edit: The following is a simplify table for easy reference:
1
2
3
a1
a2
b1
abc1
abdf2
abc2
111a
11
12
13
222a
14
15
16
111b
17
18
19
555a
20
21
22
333d
23
24
25
111a
26
27
28
in this case, the match values are 11 + 17 + 26 = 54
I also tried using combinations of functions such as SUMIFS, SUMPRODUCT, search, e.t.c. but still not able figure out the solution.

In your sheet:
=SUMPRODUCT((LEFT(B8:B22,3)=C26&"")*(C5:V5=E26)*(LEFT(C6:V6,1)=F26&"")*(LEFT(C7:V7,3)=G26&"")*C8:V22)
simply retrieve the sum using your parameters and converting in string to match exactly.

If you have Excel 365 you can use this formula:
=LET(data,C8:V22,
ruleColumnB,LEFT(B8:B22,LEN(D26))=TEXT(D26,"0"),
ruleRow5,C5:V5=F26,
ruleRow6, LEFT(C6:V6,1)=G26,
ruleRow7, LEFT(C7:V7,3) =H26,
SUMPRODUCT(data*ruleColumnB*ruleRow5*ruleRow6*ruleRow7)
)
)
Using LET makes the formula more readable - esp. if you name the rules according to your special context.
If you don't have Excel 365 you have to replace the single parameters within SUMPRODUCT with each range/formula

Related

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Excel - Writing a Complex Formula

I have the following numbers in the range AI3:AJ41:
34 3
26 3
25 3
24 2
24 2
24 2
24 2
24 2
24 2
24 2
24 2
24 2
22 2
22 2
22 2
22 2
21 2
21 2
21 2
21 2
19 2
19 2
19 2
19 2
19 2
19 2
19 2
19 2
17 2
17 2
17 2
15 2
15 2
15 2
15 2
12 1
12 1
12 1
12 1
The AI column contains values while the AJ column contains the following formula in cell AJ3:
=ROUNDUP(AI3/12,0)
which spans down to AI41.
In cell AJ2 I have the following sum formula
=SUM(AJ3:AJ41)
which results in 77.
I want to write a formula into cell AI2, to get the same result as I now have in AJ2 without using the (helper) column AJ i.e. only using the values of the AI column.
Maybe it can be a VB macro to do is, i don't know...
I've provided a link to my Sample File for easy copy/pasting.
Thank you for your time & help.
Updated November 27
I'm still at an airport, and decided to do this problem a stab without VBA/UDF.
An Array function can get you what you want. Type this into your worksheet with CTL SHIFT ENTER for a non-vba solution:
=SUM(ROUNDUP(COUNTIF(A1:AH1,">="&ROW(INDIRECT("A1:A"&MAX(A1:AH1),TRUE)))/12,0))
You can download XLSM file here.
For anyone who ever wishes they could perform VBA "loops" in a regular Excel formula, this is a pretty good example of how to approach as this essentially "loops" through the range with a higher integer each time by using the Row and Indirect functions. Chip Pearson's sight is brilliant for stuff like this.
UPDATED Nov 26
I am sitting bored in an airport, so I will give this another go... I think this custom function will get the OP what they want. Put this in anywhere and you'll get 77. =UMutCustom2(A1:AH1)
The custom function code needed is here:
Function UMutCustom2(rng As Range) As Double
Dim r As Long
For r = 1 To Application.WorksheetFunction.Max(rng)
UMutCustom2 = Application.WorksheetFunction.RoundUp(Application.WorksheetFunction.CountIf(rng, ">=" & r) / 12, 0) + UMutCustom2
Next r
End Function
original Answer
I included both of these examples in a file here.
Probably easiest to use an array formula. In cell Ai1 put this formula: =SUM(ROUNDUP(AI3:AI999/12,0))
However, after typing the formula YOU MUST HIT CTR SHIFT ENTER!
This will create curly brackets around the formula so when you view the formula it should appear: {=SUM(ROUNDUP(AI3:AI999/12,0))} and does sum to 77 on my version of file.
(good news is that in 2019 Excel's new query engine will not require the CTL SHIFT!)
Alternatively, if you want to make a custom function using vba, you could use this custom function, that would not require ctr shift enter... here's VBA code to make that:
Function UMuTCustomFunc(rng As Range) As Double
Dim ws As Worksheet, rCell As Range
Set ws = Sheets(rng.Parent.Name)
For Each rCell In Intersect(ws.UsedRange, rng).Cells
UMuTCustomFunc = Application.WorksheetFunction.RoundUp(rCell.Value / 12, 0) + UMuTCustomFunc
Next rCell
End Function
Sumproduct
If you don't want to use an array formula (too lazy to press CTRL SHIFT ENTER) you can use:
=SUMPRODUCT(ROUNDUP(AI$3:AI$41/12,0))
and press ENTER. The result is 77.
Funny
I didn't even know there was a ROUNDUP function so I used this at first:
=SUMPRODUCT(IF(MOD(AI3:AI41,12)=0,INT(AI3:AI41/12),INT(AI3:AI41/12)+1))
but it doesn't work without entering it as an array formula. This should serve as a reminder that even SUMPRODUCT won't always work as a 'non-array' formula.
Addition
If you want to apply the same principle to the range A1:AH1, use this formula:
=SUMPRODUCT(ROUNDUP($A1:$AH1/12,0))
The result is 87 though.

Excel how to look for value in table and return value from another cell

I have an issue in excel where I cannot get it to return a specific value.
I have a table of data like this
Week N1 N2 N3
w0 6 15 24
w1 5 8 9
w2 3 8 17
w3 20 23 31
w4 13 21 23
w5 6 12 15
w6 2 5 20
w7 10 20 21
the numbers in N1 N2 and N3 can change and are random.
What I need to be able to do is to lookup any number in the table and return the value in the weeks column.
so for example if I was looking for the number 20 it would return w6.
Ive tried various vlookups, Hlookups, Index and Match variations but just dont seem to be able to get this fairly simple thing to work.
Can anybody help me please, before I explode.
Try this:
= INDEX($A$2:$A$9,MATCH(1,MMULT(($B$2:$D$9=20)+0,{1;1;1}),0))
EDIT A slightly better formula:
= INDEX($A$2:$A$9,MATCH(TRUE,MMULT(($B$2:$D$9=20)+0,{1;1;1})>0,0))
It returns the first Week where a match is found in the table.
Obviously just replace 20 above with whatever value you want to look up.
See example below.
EDIT
More generally, instead of hardcoding {1;1;1} into the formula, you can make this dynamic, e.g.
= INDEX($A$2:$A$9,MATCH(1,MMULT(($B$2:$D$9=20)+0,TRANSPOSE((COLUMN($B$1:$D$1)>0)+0)),0))
Also, if you want to search the table from left to right instead of top to bottom, do this:
= INDEX($A$2:$A$9,MATCH(1,MMULT(TRANSPOSE((ROW($A$2:$A$9)>0)+0),($B$2:$D$9=20)+0),0))
Note, both of these are now array formulas (must be entered with Ctrl+Shift+Enter instead of just Enter.
Another method,
=index(A:A, iferror(match(G5, B:B, 0), iferror(match(G5, C:C, 0), match(G5, D:D, 0))))

Lookup multiple values in excel

Is there a way for excel formulas to look up multiple values in an 2d matrix for excel? For example:
sum(vlookup({2015,2016},Matrix,{2,4,6},False)) = 3 + 4 + 5 + 2 + 3 + 2
2014 1 3 7 11 9 2
2015 3 6 4 12 5 8
2016 2 1 3 99 2 6
I don't necessarily have to use the function vlookup but I prefer not having to use the same function multiple times then summing them since the list {2015,2016} could be quite long.
Put your search criteria in one cell each:
Then use this formula:
=SUMPRODUCT(ISNUMBER(SEARCH($A$1:$A$3,J1))*ISNUMBER(SEARCH(COLUMN($B$1:$G$3),K1))*$B$1:$G$3)
If you want to hard code the numbers then you can do it this way:
=SUMPRODUCT(ISNUMBER(SEARCH($A$1:$A$3,"2015,2016"))*ISNUMBER(SEARCH(COLUMN($B$1:$G$3),"2,4,6"))*$B$1:$G$3)
I like #ScottCraner's answer a lot, I just did it slightly differently, but using close-on the same tricks.
For me, I put the year values in as follows in column N:
N1 = 2015
N2 = 2016
And the columns I wanted to use for the look-up in column O:
O1 = 2
O2 = 4
O3 = 6
Then, I used the following (entered as an array formula - meaning you press CTRL+SHIFT+ENTER after putting it in):
=SUMPRODUCT(ISNUMBER(MATCH(A1:A3,$N$1:$N$2,0))*ISNUMBER(MATCH(COLUMN(A1:G3)-COLUMN(A1)+1,$O$1:$O$3,0))*A1:G3)
Again, Scott's answer is perfectly right, I just added in a different way to get to the same result.
Hope it helps you or someone else facing the same kind of challenge.

Percentage Greater than/Less than in a table

I have a table that I want to find the percentage greater than and percentage less than compared to a baseline, for the total group based on the weights of each group.
Here is my example table:
Benchmark GRP 1 GRP 2 GRP 3 GRP 4
10 10 11 10 12
14 12 15 11 15
17 11 17 13 16
18 14 15 14 17
Poulation 40 45 30 80
What I want to do is find out for each level of the benchmark what % of the total population of all four groups is above or below the bench mark value.
I have tried various sumproducts and sumifs but can't seem to get it work.
Let me know your thoughts!
Thanks as always!
Assuming your sample data is in A1:E7 put the following formula into B9 and use Ctrl+Shift+Enter to record it as an array formula:
=SUM(IF(B$2:B$5>$A$2:$A$5,1,0))/COUNTA($A$2:$A$5)
This can then be copied across under the other groups. Below is showing how it works for me.
Note: The array formula will display with braces ({...}) around it but you do not type these.

Resources