Excel SUMIF column value matches - excel

I would like to sum all values in column J when the value in column K matches. So, for example, I have the following:
COL J | COL K
25.00 | Now
45.00 | Aug 15
40.00 | Sep 10
70.00 | Now
14.00 | Aug 15
92.00 | Now
I'd like Excel to find all matching values in Column K and add up the values in corresponding rows of column J. For the example above it would sum 25.00, 70.00 and 92.00 which correspond with "Now" and then also add up 45.00 and 14.00 which correspond with Aug 15.
I know it can be done with formulas like this:
=SUMIF(K:K,"Now",J:J)
=SUMIF(K:K,"Aug 15",J:J)
However, I'd like to be more flexible and not have to have a separate formula for every different value in Column K. Is there a way to use a wildcard of some sort that can replace "Now" and "Aug 15" in the example above so that I could just have one formula that finds any matches in Column K and sums the corresponding values for those rows in Column J?
Thank you!

SUMIF accepts wildcards (e.g., this or this).
I tried adding another line to your data,
92.00 | Never
and then =SUMIF(K:K,"N*",J:J). It works great. If I understood what you were specifically aiming at, it would be =SUMIF(K:K,"*",J:J).
PS: I wouldn't know how it behaves when you have cells formatted as date, and you try to match according to what is displayed. That might involve locale issues.

You need to investigate Array Formulas also known as CSE formulas. http://www.mrexcel.com/articles/CSE-array-formulas-excel.php or http://office.microsoft.com/en-us/excel-help/guidelines-and-examples-of-array-formulas-HA010342564.aspx
=SUM(IF($K$1:$K$6=K1,$J$1:$J$6,0))
If you paste this formula into cell L1 (assuming your data is in K1:J6) and press Control-Shift-Enter to save it, it will calculate the sum of all the cells in Column J that have a matching Column K. Array Formulas are pretty powerful but they are pretty hard to debug.

Related

Excel printing a specific number in a row subject to other columns

I have an excel file with 3 columns and 100 thousand rows. My goal is to print the number of column A, where the number in column C is the maximum and the number in column B is higher or equal to 0.9. Like this example:
-----+------+-----
A | B | C
-----+------+-----
1 | 0.9 | 130
2 | 0 | 200
3 | 0.95 | 90
In this example for example it should print '1' since column 1 and 3 are higher than 0.9 but 1 is higher than 3 in column C. Anyway to do this in excel?
Assuming your data in column C is positive (or at least, that the maximum value is positive), you can use this array formula:
= INDEX(A:A,MATCH(LARGE(((B:B>=0.9)+0)*(C:C),1),((B:B>=0.9)+0)*(C:C),0))
Note this is an array formula, so you must press Ctrl+Shift+Enter after typing in the formula.
This gets pretty ugly since there is no =MAXIFS() formula. Instead, an array formula will do the trick:
=SUMIFS(A1:A3, C1:C3,MAX(IF(B1:B3>=0.9, C1:C3, 0)), B1:B3,">=.9")
Hit Ctrl+Shift+Enter when entering that so Excel will interpret as an array formula.
The Sumifs() here isn't summing more than one value so no worries there. We are grabbing the value from A1:A3 where C1:C3 is equal to the MAX() of that column where B1:B3 is greater than or equal to .9. Which solves that max() issue. And then we are then only allowing selection A1:A3 where B1:B3 is greater than or equal to .9.
It's not pretty, and it requires us to check that >=.9 condition twice, but it does the job.
Try using this array formula =SUMPRODUCT(INDEX(A2:A20,MATCH(MAX(--($B$2:$B$20>=0.9)*C2:C20),--($B$2:$B$20>=0.9)*C2:C20,0),1)) in cell D2. Confirm it with CTRL+SHIFT+ENTER.
This is the array formula (means you have to click Ctrl + Shift + Enter altogether) what I came up with:
=INDEX(A:C,MATCH(MAX(--(B:B>=0.9)*(C:C)),(B:B>=0.9)*(C:C),0),1)
Please note that I used the whole column but I will suggest to only use the ranges that are needed for faster speed.

Counting unique list of items from range based on criteria from other ranges

I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.

Formula returning Column A value for row containing MAX value of a range

Assume I have the following table:
A B C
1 Week 1 Week 2
2 Melissa 114.7 82.8
3 Mike 105.5 122.5
4 Andrew 102.3 87.5
5 Rich 105.3 65.2
The names are in column A, the Week values are in Row 1. (So A1 is blank, B1 = Week 1, and A2 = Melissa.)
I'm trying to build a formula that looks at all the values in a known range (in this example, B2:C5), chooses the highest value of the bunch (here, 122.5) and returns the name of the person from Column A that got that value. If I use this formula, it works for the values in range B2:B5:
=INDEX(A2:A5,MATCH(MAX(B2:B5),B2:B5,0))
That returns Melissa but if I expand the range to include more than just column B's values, I get an #N/A returned:
=INDEX(A2:A5,MATCH(MAX(B2:C5),B2:C5,0))
The weird part (to my simple brain) is that the MATCH portion of the formula works fine, if I just put in this formula, it returns the highest value of 122.5 from C3:
=MAX(B2:C5,B2:C5,0)
So clearly something it going wrong when I'm using either the MATCH or INDEX commands.
Hopefully this makes sense and someone can point out my error?
Try this:
=INDEX(A:A,MAX((B2:C5=MAX(B2:C5))*ROW(B2:C5)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Note: Match can only search one vector at a time. It can be one row or one column or one array. It cannot be two or more rows or columns or a 2D array.
Do it "twice"? Please try:
=INDEX(A2:A5,IFERROR(MATCH(MAX(B2:C5),B2:B5,0),MATCH(MAX(B2:C5),C2:C5,0)))
If you are going to have up to 52/53 weeks to cope with I'd suggest instead inserting a helper column with the MAX for each row. Make that an new (inserted) ColumnA (say =MAX(C2:BC2) etc.) and a simple VLOOKUP should serve, say:
=VLOOKUP(MAX(A:A),A:B,2,0)

How to sum a row in Excel with lookup values from a column based lookup?

I have rows of values in columns AC to AU (but also some blanks)
I want to convert these values in a formula via a lookup and sum all the lookup values in a row.
For 1 cell I can use VLOOKUP(AC2,'Lookup_Table'!A2:B41,2) successfully
How do I sum the whole row of AC2 to AU2 with this kind of lookup?
Note the lookup is column oriented in a vertical lookup, the 'Lookup Table' is actually a worksheet.
This has stumped me for hours now!
| AC | AD | AE ..Ax... AU
Row 1 | 12 | 23 | 43 ..00... 67
'Lookup table' worksheet
A | B
12 | 4
23 | 2
43 | 3
67 | 5
The result should be 14 for the sample Row 1 data above
It is much easier to use an array formula (ctrl+shift+enter instead of just enter). Generally I don't like array formulas (because they are easy for the uneducated to break), but I think it will work the best in your situation apart from reformatting your sheet or using helper columns.
{=SUM(IF(AC2:AU2=Lookup_Table!A2:A41,Lookup_Table!B2:B41))}
which should have {} around the whole thing if you entered it correctly.
You need to use a combination of SUM and INDEX functions, where AB in Lookup_Table is your index column for the table, and A! is the value you wish to lookup:
=SUM(INDEX(Lookup_Table!$AC$1,MATCH(A1,Lookup_Table!$AB:$AB,0)):INDEX(Lookup_Table!$AU$1,MATCH(A1,Lookup_Table!$AB:$AB,0)))

Excel: Matching the closest date from range of dates

I'm trying to display the header of the column that its cell that contains a date, is the closest (out of 3 other cells with dates, B2:D2) to the a specific cell (A2)
So here's my sheet:
A B C D
1 | T1 | T2 | T3 | T4 |
2 | 5/1/2013 | 5/31/2013 | 2/5/2013 | 3/2/2013 |
A2 = a date.
B2:D2 = 3 dates, can also be blank
I've tried using the following array formula that I found online:
=IF(COUNT($B2:$D2)>0,INDEX($B$1:$D$1,MATCH(MIN(ABS($B2:$D2-$A2)),ABS($B2:$D2-$A2),0)),"")
But it sometimes when there is only one or two dates, it gives me the wrong header. I would also like to avoid using array formulas, but couldn't convert it to a regular one.
Would highly appreciate assistance on this matter
Can you give an instance were the array formula you are using isn't working ? It worked for the cases I tried.
You can avoid using the array formula if you are prepared to have another row with the difference in the dates and your date cell A2.
Push your rows down one row, so the headings are on row 2 and the dates on row 3 and enter the following formula across row 1, starting at cell B1
=ABS(B3-$A$3)
Drag this across and enter the following HLOOKUP to get your header row
=HLOOKUP(MIN(B1:D1),B1:D3,2,FALSE)
if you can't move your rows down for some reason you can use a combination of MATCH and INDEX (which is slower) . If you were to put the difference function =ABS(B2-$A$2) across row 7 the formula would be
=INDEX(B1:D1,1,MATCH(MIN(B7:D7),B7:D7,0))
Okay so the answer was fairly simple.
I went back to the sheet to investigate the scenarios in which this happens.
It seems that when A2 is blank (= no date to make the comparison) it just gives out the only date available from B2:D2.
By simply adding another condition to the IF statemented that would work only if A2 has a value resolved the issue. So we're checking if both A2 and B2:D2 has values in them (with B2:D2 needs to be at least one:
=IF(AND(COUNT($B2:$D2)>0,$A2>0),......)
and here is the full formula
=IF(AND(COUNT($B2:$D2)>0,$A2>0),INDEX($B$1:$D$1,MATCH(MIN(ABS($B2:$D2-$A2)),ABS($B2:$D2-$A2),0)),"")
Thanks for making me go back to the investigate! :D
For a non-array alternative, you could try:
=LOOKUP(2,1/FREQUENCY(0,ABS(B2:D2-A2)),B$1:D$1)
in place of the INDEX(...) part of the formula.

Resources