Excel - Lookup value in multiple columns - excel

I have a datasheet with multiple columns that I want to search through - ending up with returning the top row value(s) in the found column(s). How to do this?
My idea would be to combine index with match, but I am rather lost for specific ideas...
January February March April May June
1 2 3 4 5 6
7 8 9 10 11 12
2 7 1 8 4 5
9 10 11 12 6 3
E.g. Search for: ID 3 - should return: March, June
Regards,
Nyborg

You need to add a VLOOKUP for each columns and after build the result
Following the Scheme:
A7 -> =IF(IFERROR(VLOOKUP($A$9;A1:A5;1;);"")="";"";A1) and autocomplete
D9 -> =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCATENATE(A7;",";B7;",";C7;",";D7;",";E7;",";F7);",,";",");",,";",");",,";",")
D10 -> =IF(RIGHT(D9;1)=",";LEFT(D9;LEN(D9)-1);D9)
Formula for D9 & D10 it's only to have a good display of the results.
UPDATE Version:
Considering you agree to have the Row 7 ... You can simplyfy using the Result formula:
=INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);1))&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);2));"")&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);3));"")
List it's the name Range of Row 7. The formula shall be apply with Ctrl+Shift+Enter.
This formula collect the first 3 value.
If you want more, add for each nth value you have:
&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);3));"")
changing the last numer (in this case 3) and putting 4, 5, 6 ...
Obviusly if the result can be a lot, have few sense... Consider to use VBA !

Related

Find and adjacent cell with criteria

I have the following spreasdheet:
pserial
sex
marstatb
age
10105101
1
5
92
10115101
1
1
63
10120101
2
4
56
10127101
1
2
38
10127102
2
2
25
10135101
2
1
37
10135102
2
-1
14
10135103
2
-1
10
10137101
1
2
35
10137102
2
2
29
Where pserial: Serial number of individual
Sex: male/female
marstatb: Marital status including cohabitees
I know that the person is divorced if marstatb= 4, and that the person is female if sex=2
I need to find the pserial value for the oldest divorced female.
I was thinking of using the filtering function, IF function for the criterias but I'm not sure how.
I think the INDEX function would be useful for this too.
UPDATE: This is my function so far:
=#FILTER(A2:A9282,MAXIFS(D2:D9282,B2:B9282,2,C2:C9282,4)=D2:D9282)
Using FILTER() & MAXIFS()
• Formula used in cell F2
=FILTER($A$2:$D$12,(MAXIFS(D2:D12,B2:B12,2,C2:C12,4)=D2:D12)*(B2:B12=2)*(C2:C12=4))
Another alternative is using INDEX() & AGGREGATE()
• Formula used in cell F4
=INDEX(A2:D12,AGGREGATE(15,7,ROW(A2:D12)/
((D2:D12=AGGREGATE(14,7,D2:D12/((B2:B12=2)*(C2:C12=4)),
ROW($ZZ1)))*(B2:B12=2)*(C2:C12=4))-1,1),0)
Using SORT() & TAKE()
• Formula used in cell F6
=LET(x,SORT(A2:D12,4,-1),
TAKE(FILTER(x,(INDEX(x,,2)=2)*(INDEX(x,,3)=4)),1))
With Headers:
=LET(x,SORT(A1:D12,4,-1),VSTACK(TAKE(x,1),
TAKE(FILTER(x,(INDEX(x,,2)=2)*(INDEX(x,,3)=4)),1)))
EDIT
For MS365 Users
• Formula used in cell F9
=TAKE(SORT(FILTER(A2:D12,(B2:B12=2)*(C2:C12=4)),4,-1),1)
With Headers:
• Formula used in cell F11
=VSTACK(A1:D1,
TAKE(SORT(FILTER(A2:D12,(B2:B12=2)*(C2:C12=4)),4,-1),1))

Subtotals grouped by value using COUNTIF to create ranges for SUMIF, but in a single formula

End-goal: A column with the subtotals of groups (defined in the below table as all foods listed above Zucchini, incl Zucchini).
Current attempt: create a column to define groups using COUNTIF('count all 'zucchini' thus far'). Then use SUMIF to get the total cost for the current group.
Problem: I don't know how to do this without the COUNTIF column (since SUMIF needs range C:C to be resolved first). I'd like to have it in a single formula. I looked into array formulas but not sure if/how to apply that here.
FOOD COST COUNTIF(A2:A$2;"Zucchini") SUMIF(C:C;C2;B:B)
Apple 3 0 12
Pecan 7 0 12
Zucchini 2 0 12
Apple 4 1 23
Olive 8 1 23
Pecan 6 1 23
Zucchini 5 1 23
Apple 4 2 16
Olive 9 2 16
Zucchini 3 2 16
Any ideas on how to solve either the current problem or the end-goal problem? Thanks!
Put this in C2 and copy down:
=IF(A2="Zucchini",SUM($B$1:B2)-SUM($C$1:C1),"")
It basically sums everything to the row and subtracts what is already accounted for.

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

How to check value with all previous row value

I am trying to write a formula in excel to check if the given number is less than any of the previous row value.
For eg.
My excel document is as follows:
A B
1 01/05/2017 10
2 02/05/2017 5
3 03/05/2017 7
4 04/05/2017 11
what m hoping to achieve is
A B C
1 01/05/2017 10 -
2 02/05/2017 5 TRUE (5<10 = true)
3 03/05/2017 7 TRUE (7<5=false & 7<10=true therefor its true)
4 04/05/2017 11 FALSE (11<7=false & 11<5=false and 11<10=false)
So if the current value is less than any of the previous value the field should be true or else false.
Note : the sheet is sorted according to timestamp which cannot change
Thanks for you answers.
If you start in C2 then this formula does what you want:
{=SUM(IF(B2<B$1:B1,1,0))<>0}
Please note, this is an array formula, so you need to hit CTRL+SHIFT+ENTER when you enter the formula for it to work.
It gives me this:
If you prefer R1C1 mode, like I do, the formula is:
{=SUM(IF(RC[-1]<R1C[-1]:R[-1]C[-1],1,0))<>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.

Resources