I'm trying to get a value from a table in another sheet based on two values in the current sheet.
This is what I have in the first sheet
And this is what I have in the second sheet
At the moment I get the expected indicador from sheet 2 for A1 cell (can be P01, P02, P03,...). But I want it to search based the cells A1 and B3, because B3 can assume equal values to different A1 values (P01, P02, P03,...).
Is it possible to select more than one value on =VLOOKUP (value, table, col_index, [range_lookup]) ?
You can look into using a combination of INDEX and MATCH:
Formula in F3:
=INDEX(A2:A3,MATCH(1,INDEX((B2:B3=F1)*(C2:C3=F2),),0))
If you were looking to return the value 11 with the other two parameters, you can adapt this to a formula in F2:
=INDEX(A2:A3,MATCH(1,INDEX((A2:A3=F3)*(B2:B3=F1),),0))
You can obviously adapt this to your needs...
Related
I have a matrix dataset with values in Excel, where row and column names are identical. I have put all matrix values in a single column, but would now like a formula that returns the matching row name and/ or column name for that value. I have tried VLOOKUP and versions of INDEX and MATCH, but can't get it to work.
Here's an illustration of the data:
Setup:
Source table range A1:D4
Values populated in column H for checking.
Formula in cell F2:
=IFERROR(INDEX($A$1:$A$4,MIN(IF($B$2:$D$4=H2,ROW($B$2:$D$4),10^10))),"")
Formula in cell G2:
=IFERROR(INDEX($A$1:$D$1,1,MIN(IF($B$2:$D$4=H2,COLUMN($B$2:$D$4),10^10))),"")
Depending on your version, you may have to use CTRL+SHIFT+ENTER to implement these formulas. Output will be like below.
You are not looking for a rowname or a columnname, you are looking for the content of the first row or column:
Imagine you want to know the "columnname" of cell "C4", then you just ask for Cell(3,1) (3 meaning "C").
Imagine you want to know the "rowname" of cell "C4", then you just ask for Cell(1,4).
I have several lists of general categories in different columns, with each category title in row 1 and each having several different items in rows below it. Picture for reference:
On this same worksheet I want to be able to enter any of the items (Pork, Apple, Cheese, etc.) in cell E2 (my lookup value). What formula can I put in cell F2 to have it return the header of the list that item belongs to (Meat, Fruit, Dairy, etc.)? With my current understanding of V/HLOOKUP and INDEX/MATCH formulas I believe you can only lookup values in a single row or , but here I want to be able to have a lookup array of multiple rows and columns, and have it return the value of the top row of the appropriate column.
Edit:
Here is what I have tried so far:
=HLOOKUP(E2,A1:D5,1,FALSE)
=INDEX(A1:D5,1,MATCH(E2,A2:D5,0))
I am using Excel 2016
The answer is to use SUMPRODUCT.
If your lookup value is in E2 and your formula in F2, use this formula:
=INDEX(A1:D1,SUMPRODUCT((A2:D5=E2)*COLUMN(A2:D5)))
This formula is not an array formula, and doesn't require the ctrl+shift+enter.
=INDEX(A1:D1,,MIN(IF(E2=A2:D5,COLUMN(A:D))))
Enter the formula with ctrl + shift + enter
MIN searches for the first TRUE where E2=A2:D5 and returns in which column A:D that was and returns that number for use in your INDEX.
I have 2 worksheets that are connected through a unique ID column shared by the two sheets. I made the two below spreadsheets to test the formula as my actual data is quite long.
I am using the INDEX and MATCH formulas to pull a value from Sheet2 to populate a cell in Sheet1 if the ID value found in the row of Sheet1 matches an ID value found in Sheet2. I can accomplish this with the following formula
=INDEX(Sheet2!B:B,MATCH(Sheet1!A:A,Sheet2!A:A,0))
However, what I am actually after is for the INDEX to SUM of all values in the WGT column on Sheet2 on Sheet1 when there is a MATCH between the two ID columns (I know with this test data there are two instances of every ID on Sheet2). The above formula only INDEXes the first WGT value when a MATCH is found between the ID columns.
I am pretty sure I am supposed to use some variation of the SUMIF formula but I can't seem to get one that works at all. Thanks for any help!
The syntax for Sumif is Sumif(criteria range, criterion, [sum range]). So, you would need in Sheet2, cell B2
=sumif(Sheet1!A:A,Sheet2!A2,Sheet1!B:B)
In words: generate a sum or all numbers in column B of Sheet1, where column A of Sheet1 equals the value of cell A2 on Sheet2.
Copy that down.
Alternatively, you could click in the data of Sheet1 and insert a pivot table. Drag the ID field into the Rows area and the WGT field into the Values. Just a few clicks, no formula.
Another option to use Sum + Index function
In sheet1, B2 array formula copied down :
=SUM(INDEX(Sheet2!B:B,N(IF(1,(Sheet2!A:A=A2)*ROW(Sheet2!A:A)))))
This is an array formula and needs to be confirmed by pressing with Ctl + Shift + Enter.
I am wondering if there is a simple way to count the number of rows after filtering a subset of columns by value considering multiple selections for a given column in an excel table object.
Let's say I have the following excel table:
A B C
a1 b1 c1
a2 b2 c1
a1 b2 c2
a2 b1 c2
a1 b3 c3
a3 b1 c3
saved in an excel table under the name: Table1 and I would like to find all rows that the column A has the value a1 or a2 and column B has the value: b1. The result should be 2.
I am able to do it using SUMPRODUCT function and converting the logical value into [0,1] using the -- operator:
= SUMPRODUCT(--(Table1[A]="a1"),--(Table1[B]="b1"))
+ SUMPRODUCT(--(Table1[A]="a2"),--(Table1[B]="b1"))
In my real example, I have more than three columns and at least one of them can satisfy multiple criteria so I am wondering if there is a way to do it with a less verbose syntax. For example, I was trying something like this, but it does not work:
= SUMPRODUCT(--(Table1[A]="a1|ab2"),--(Table1[B]="b1"))
or
=SUMPRODUCT(--(Table1[A]=OR("a1", "a2")), --(Table1[B]="b1"))
the OR function does not help, because it does not return an array result, and I cannot use the array formula in my real example because I would need to apply just for one column with more than one selection, but for the rest of the columns I am selecting it is just a single value.
It seems to be a good trick for representing in an excel formula a multiple filter criteria action, but the excel formula is very verbose when within a column it has to satisfy more than one condition, like in the above example.
Under my solution, it would something like this for counting rows in a Table where for each column we filter by only one value except for the first column A that we filter by two possible values:
= SUMPRODUCT(--(Table1[A]="a1"),--(Table1[B]="b1"),
--(Table1[C]="c1"), ...Table1[Z]="z1"))
+ SUMPRODUCT(--(Table1[A]="a2"),--(Table1[B]="b1"),
--(Table1[C]="c1"), ...Table1[Z]="z1"))
Try:
=SUMPRODUCT((Table1[A]="a1")+(Table1[A]="a2"),--(Table1[B]="b1"))
Since any given cell's cannot both be "a1" and "a2", the sum will be 1 if either is true and 0 if neither is true
To return a value corresponding to another cell from a range if it matches with a cell, I found Chuff's solution helpful (in
Excel - match data from one range to another and get the value from the cell to the right of the matched data ):
=iferror(vlookup(b31,$f$3:$g$12,2,0),"")
However, if there are more than one cells within the column F which match with b1, the formula returns the value of only one cell from the column G.
Could it be modified so as to attract the value of more than one cell?
Thank you!
To return multiple corresponding Vlookup values you should use this formula: =IFERROR(INDEX($B$2:$B$9,SMALL(IF($E1=$A$2:$A$9,ROW($A$2:$A$9)-ROW($A$2)+1),COLUMN(A1))),"")
Because it it an array formula, please enter it using combination of CTRL+SHIFT+ENTER . For example, if you have you lookup range in A:B column, and lookup values in D column, then please enter formula above to F1 cell, then drag it to the right and to the bottom. You should now see all instances of Vlookup next to the lookup value in D column.
If you have only values which you want to sum in case they correspond to your value in cell B31, then simply use SUMIF formula like this =SUMIF($F$3:$F$10,$B31,$G$3:$G$10) entered in cell C31.