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

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))))

Related

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

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

Referencing the previous row in Spotfire and a value in another column

I'm trying to do something that is very simple to do in Excel, but seems very tricky in Spotfire:
Imagine you have the following table:
A
1: 10
2: 15
3: 20
... and you want to produce the following:
A B
1: 10 10
2: 15 25
3: 20 45
In other words, add the current value of A to the previous value of B. If this was Excel, the formula in cell B3 would be = A3 + B2... However, I'm not in Excel, I'm using Spotfire... :) Any thoughts?
NB: If it makes any difference to the answer at all, I will need to use the Intersect() function in conjunction with this, as there is a categorical column to factor in as well.
Hope this helps, I have considered the first column as ID
ID A B
1 10 10
2 15 25
3 20 45
If(Sum([A]) over (AllPrevious([ID])) is null,sum([A]) over ([ID]),Sum([A]) over (AllPrevious([ID])))

Excel - Count of entries below cumulative threshold without helper column

I have the following little table. I'd like a formula that finds the number of values where the cumulative total (of column B) is less than some threshold (tx).
I tried
{=MIN((SUM(OFFSET(B1,0,0,A1:A17))>tx)*A1:A17)-1}
but OFFSET doesn't seem to be arrayable like that. Obviously, this would be trivial with a helper column, but for certain reasons that is not possible.
So the correct answer here should be 10.
tx = .8
A B
1 0.112106465
2 0.110981698
3 0.091959216
4 0.082163441
5 0.073292066
6 0.072407529
7 0.071646289
8 0.061646797
9 0.06011448
10 0.057566381
11 0.050341978
12 0.048227061
13 0.043207335
14 0.03940462
15 0.012914194
16 0.007603446
17 0.004417003
You're not really looking for a MIN; rather it should be MAX that follows your condition.
In E7 as a standard (non-array) formula,
=AGGREGATE(14, 6, ROW(1:17)/(SUBTOTAL(9, OFFSET(B1, 0, 0, ROW(1:17), 1))<D7), 1)
      
I prefer the following array formula** due to its non-volatility:
=MATCH(TRUE,MMULT(0+(ROW(B1:B17)>=TRANSPOSE(ROW(B1:B17))),B1:B17)>=0.8,0)-1
Regards
The most succinct way to do it I've found is
=SUM(--(SUBTOTAL(9,OFFSET(B1,,,A1:A17))<0.8))
entered as an array formula, or, equivalently,
=SUMPRODUCT(--(SUBTOTAL(9,OFFSET(B1,,,A1:A17))<0.8))

Countif after filterlist Excel

I would like to see a working example of how to get this formula properly working
=SUMPRODUCT(SUBTOTAL(3,OFFSET($P$7,ROW($P$8:$P$5500)-ROW($P$7),,1)),--($P$7:$P$5500="74"))
What im trying to achieve is count all the cells within a range that value is greater than
zero, but i need to get that working after i apply a filter. I have seen several examples and havent get it working, with the subtotal fx.
Thanks in advance, for any help!
Working example:
O P
4
5 6
6
7 Filter Data
8 1 74
9 0 74
10 1 74
11 0 74
12 1 74
13 0 74
Formula in P5:
=SUMPRODUCT(SUBTOTAL(103,OFFSET($P$7,ROW($P$8:$P$20)-ROW($P$7),,1)),--($P$8:$P$20=74))
Now you can filter column O and P5 counts only the visible 74.
With function 103 in SUBTOTAL, I really count only the visible cells. This means, also the manually hidden cells are not counted. With function 3 only the out filtered cells are not counted. If cells are manually hidden, they are counted, even if they are not visible.
And I have used the value 74 instead of the text "74". So in my example the column P contains numbers, not text.
How it works:
The formulas within SUMPRODUCT are in array (matrix) context. This means they are handled as if they are used in array formulas.
In array context {ROW($P$8:$P$20)-ROW($P$7)} gets ROW($P$8)-ROW($P$7) = 1, ROW($P$9)-ROW($P$7) = 2, ROW($P$10)-ROW($P$7) = 3 and so on.
OFFSET($P$7,1,,1) will get $P$7+1Row = $P$8, OFFSET($P$7,2,,1) will get $P$7+2Row = $P$9 and so on.
So {OFFSET($P$7,ROW($P$8:$P$20)-ROW($P$7),,1)} gets {$P$8,$P$9,$P$10,...}
Within SUBTOTAL(103, {$P$8,$P$9,$P$10,...}) it counts 1 if {$P$8,$P$9,$P$10,...} is visible and 0 if not.
So the SUMPRODUCT results in
SUMPRODUCT({1,0,1,0,1,0,0,...}, --($P$8:$P$20=74))
The {($P$8:$P$20=74)} results in {TRUE,TRUE,TRUE,FALSE,TRUE,...} depend of if $P$8:$P$20=74. The -- (*-1*-1) gets this in numeric context, so that the TRUE = 1 and FALSE = 0.
So the SUMPRODUCT finally results in
SUMPRODUCT({1,0,1,0,1,0,0,...}, {1,1,1,1,1,1,0,...})
Greetings
Axel

Google Docs VLOOKUP ISERROR IF function

Below is my excel function input but it does not seem to be working as it just returns -- in google docs.
=IF(ISERROR(VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE)),
VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE),
VLOOKUP(F11,Formulas!C2:D17, 2, FALSE))
Below is the information I am wanting to do a vlookup for.
A B C D
1 NYJ 27 PHI 20
2 BUF 13 DET 35
3 CIN 27 IND 10
4 MIA 24 NO 21
5 TB 12 WAS 30
6 CAR 25 PIT 10
7 ATL 16 JAC 20
8 NE 28 NYG 20
9 MIN 24 TEN 23
10 STL 24 BAL 21
11 CHI 16 CLE 18
12 KC 30 GB 8
13 DAL 6 HOU 24
14 DEN 24 ARI 32
15 SD 6 SF 41
16 SEA 22 OAK 6
Let's say a user inputs "GB" into cell F11. Point of the formula is to insert the points to the right of the GB. Formula is supposed to look for GB in the first column. IF it is TRUE, it will do a vlookup for the first column because it found GB in the first column. IF it is FALSE, it will do a vlookup for the 3rd column.
Not sure what is happening? FYI I did replace the last TWO vlookup functions in the formula with "TRUE" and "FALSE" and it worked as it should. Is this just a google docs issue?
Any help would be great! thanks
UPDATE
I tried this in excel and got a #N/A
As you are returning numbers an alternative here might be to use SUMIF, i.e.
=SUMIF(Formulas!A:C,F11,Formulas!B:D)
If F11 isn't found you'll get zero
Use IFERROR instead of ISERROR:
=IFERROR(VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE),VLOOKUP(F11,Formulas!C2:D17, 2, FALSE))
Your formula will always return #N/A with your current data. Your VLOOKUPs are good, but the issue is with the IF. Let me explain:
Let's call VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE) the function F1 and VLOOKUP(F11,Formulas!C2:D17, 2, FALSE) F2.
Your IF formula is:
=IF(ISERROR(F1),F1,F2)
Literally meaning: If F1 returns an error, use F1! If F1 does not return an error, use F2 (which by the way would now return an error).
Does this make sense? Try turning it around:
=IF(ISERROR(VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE)),
VLOOKUP(F11,Formulas!C2:D17, 2, FALSE),
VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE))
That should work now. You can also shortern it by using an IFERROR because you are repeating two operations:
=IFERROR(VLOOKUP(F11,Formulas!$A2:$B17, 2, FALSE),VLOOKUP(F11,Formulas!C2:D17, 2, FALSE))
Now it means if F1 gives an error, use F2, otherwise, use F1 itself.

Resources