In the dummy table below, I can use the formula below to lookup a value in the third column:
=VLOOKUP(1, Table1[A]:Table1[C],3)
I am wondering if there is any way to define the lookup range as just column-A and column-B using a union operator?
The formula works fine - the motivation for using only two columns is when working with more complex tables that may change, I would always know that the lookup index is 2.
The short answer is, no, there is no way to do two disconnect columns.
So we do:
=VLOOKUP(1,Table1[A]:Table1[C],COLUMNS(Table1[A]:Table1[C]),TRUE)
Now it will count the number of column that that range reference encompass. In your example it would be 3, if another column is added between it would be 4 thus always referring to the correct column.
Related
I am trying to lookup a value from another table based on a reference table.
See below my data sample:
SHEET 1 ("CalculationLiability"):
SHEET 2 ("KeyMetrics"):
In sheet 1, cell G7 I am trying to look up the value from Sheet 2 based on 3 criteria (supplier unique ID, type and season) I tried the following formula, but it is returning a #REF error.
=INDEX(KeyMetrics!$F$6:$AS$100,
SUMPRODUCT((KeyMetrics!$D$6:$D$39=CalculationLiability!$D7)*
(KeyMetrics!$E$6:$E$39=CalculationLiability!$G$6)*
(KeyMetrics!$F$5:$AS$5=CalculationLiability!$E7)))
Anyone knows what I am doing wrong here? I can get it to work for two criteria, but for three criteria it doesn't work. Any help or push into the right direction is much appreciated!
The Index uses a multi column, multi row reference. That means that you need two additional arguments, one argument for row, and another for column.
Your formula currently only provides one additional argument. When you step through the formula with the Evaluate Formula tool you can see that in the last step.
You can use an Index with two Match functions. The first one to find the row, the second one to find the column.
=INDEX(KeyMetrics!$F$6:$AS$100,
MATCH($D7&$G$6,INDEX(KeyMetrics!$D$6:$D$100&KeyMetrics!$E$6:$E$100,0),0),
MATCH(CalculationLiability!E7,KeyMetrics!$F$5:$AS$5))
You can also use Sumproduct, but in that case, don't use Index.
=SUMPRODUCT(KeyMetrics!$F$6:$AS$39,
(KeyMetrics!$D$6:$D$39=CalculationLiability!$D7)*
(KeyMetrics!$E$6:$E$39=CalculationLiability!$G$6)*
(KeyMetrics!$F$5:$AS$5=CalculationLiability!$E7))
I have a table that I am using to summarize some data from other tables; the data is almost entirely text so a pivot table isn't the answer. I have a table on a worksheet as follows...
Here is a typical formula for columns D:L...
FORMULA: =INDEX(tblITPM,MATCH(tblHCSmry[[#Headers],[Data Source]],tblITPM[[#All],[Column1]],0),MATCH([#MetricName],'SheetA'!$A$2:$D$2,0))
Individally, the formulae seem to work fine but the total of the calculations only works in the first 3 rows of my summary table (tblHCSmry). There are two issues that I don't know how to solve:
In the "array" section of the INDEX I am referencing table
names that are listed in column B (TableName); hard-coding like I
have above (tblTableA) makes all of the items that need to reference
a separate table on a separate worksheet to fail.
The MATCH formula (MATCH([#MetricName],'1_ITPM_Summary'!$A2:$D2,0)) have a similar issue; I get the correct answer for the first 3 tables (2, 3, or 4) which I expect since the "lookup_array" is hard-coded. So, the issue again arises though when I want to reference a different table such as tblTableB by pointing to Column B of tblHCSmry.
I suppose the main question is: can I use a named range of a table, or do I need to use the "'SheetA'!A3:D3" format? If so, is there a way to dynamically change, "'SheetA'!" to "'SheetB'!" by referencing Column B of the tblHCSmry? FWIW: I tried to CONCATENATE the Sheet name with the reference and that didn't work.
You can use named ranges, but you'd need to have pointers to the location of the data in cells, which appears to be what you already have in Columns A and B. You can then reference those dynamically using using =INDIRECT(). =INDIRECT() allows you to take a value of a cell and use that as a reference as opposed to the reference being to the cell itself.
For instance
=INDEX(INDIRECT([#TableName]),MATCH(tblHCSmry[[#Headers],[Data Source]],tblITPM[[#All],[Column1]],0),MATCH([#MetricName],INDIRECT("'" & [#TabName] & "'!$A$2:$D$2"),0))
Would make your return array whatever is referenced in [#TableName], and your array parameter in your second MATCH function would be whatever is referenced in [#TabName]
MSDN has very basic documentation of INDIRECT() here, but there's quite a bit you can accomplish with it as far as creating more dynamic formulas.
In the sheet1 i have a table called working days of the countries as shown in the below image.
In the Sheet2 i have 10 columns in that based on the country and month by referring the this table i am trying to populate the values, When i tried doing by Vlookup the first row alone getting populated, but in the second row the header from F1:T1 is getting changed to F2:T2 so rest of the cells showing as #NA.
Anyone can you please give a solution for my issue. Here is the formula i have used.
=VLOOKUP(I1,Sheet1!F2:T7,MATCH(Sheet2!M1,Sheet1!F1:T1,0))
Thanks in Advance.
You are missing the symbol $ to lock the ranges, and the false condition to match exact values in the VLOOKUP.
It should be like:
=VLOOKUP(I1,Sheet1!$F$2:$T$7,MATCH(M1,Sheet1!$F$1:$T$1,0),0)
Or instead of VLOOKUP use HLOOKUP like:
=HLOOKUP(M1,Sheet1!$F$1:$T$7,MATCH(I1,Sheet1!$F$2:$F$7,0),0)
In general, combining the INDEX and MATCH functions is a superior option to VLOOKUP. For example, =INDEX(Sheet1!F:F,MATCH(Sheet2!M1,Sheet1!F1:T1,0)). This allows you to go left-to-right or right-to-left as well.
Snip for Index Match functions Using Vlookup won't work here because in the 2nd table you are repeating the country, unlike the first table. Use a combination of index match function, this is little trickier than the vlookup but it will fulfill your requirements.
Since I don't have the exact table you shared so I created a table on my end and sharing the snip here.
I don't know if I'm going about this the wrong way but it seems like it should be simple. Column A has a list of Names. Along each row is several "W"'s. Another separate field has a drop down representing Column A names. I want to count the number of "W"'s in a row corresponding to what name I select. I've tried using VLOOKUP and COUNTIF but I can't figure out how to select the entire array and then single out the one row that matches my selected name. I can get it working with a bunch of IF statements but thats far too time consuming as I'm manually matching the name to the row (and it isn't future proof).
There are a few ways to first 'narrow in' on the row you're looking for, after which point you can use a simple COUNTIFS to check the number of W's in that row.
One method would be to simply use INDIRECT, and create the row reference on the fly, like so [assumes your search cell is C1]:
=COUNTIFS(INDIRECT(MATCH(C1,A:A,0)&":"&MATCH(C1,A:A,0)),"W")
This first uses MATCH to find the appropriate row, and then builds a reference to that row [like "24:24"], which becomes the row that INDIRECT passes to COUNTIFS, which counts that row for W's.
For only one use of INDIRECT, the high computing costs of INDIRECT should not be an issue.
Another method would be to point out the full possible box that data could be contained in [let's assume that at most only column H would be used], and then use INDEX to give us the appropriate row number, like so:
=COUNTIFS(INDEX(A:H,MATCH(C1,A:A,0)),0,"W")
This again uses MATCH to find the row which contains the value found in C1 within column A. Then it takes the full possible box from INDEX, and returns all columns from the particular row [note that telling index to return 0 for the column # actually returns all columns instead].
Other methods would be possible [for example OFFSET], but I believe these two show the principle fairly well.
You could use the "Helper" Column method:
In the helper column:
=COUNTIF(B2:H2,"W")
Then use SUMIF() in the totals column:
=SUMIF($A$2:$A$9,K2,$I$2:$I$9)
I try to avoid using Excel too much, but when I do I like using structured references as they seem a lot cleaner to write.
If I create a table called "table1" with columns "col1" and "col2" how would I reference the first row in "col1" using a structured reference in another table? I have tried the syntax =table1[[#this row],[col1]], and just get an error. Is there a syntax like =table1[1,1] or =table1[1,[col1]]? Of course, this doesn't work either, but what's the equivalent?
It's very annoying, as it seems like this should be simple.
Table1[[#This Row][Column1]] does work, but the formula must be on the same row as the table row you wish to reference.
To reference the first row, elsewhere, use either COUNTIFS(criteria_range1, criteria1 [, criteria_rangen, criterian]) Or the slightly more complex SUMIFS() if you need numeric values instead of counts, as mentioned by studgeek:
SUMIFS(sum_range1, criteria_range1, criteria1 [, criteria_rangen, criterian])
You will of course need a unique row criteria by which to select the row. So, for example:
Table1
ID Value Name
1 2 Two
2 4 Four
3 8 Eight
SUMIF(Table1[Value], Table1[ID], 2) ... returns a value of 4 (or zero if ID=2 not found). If your value is not numeric, then you can't use this method, obviously.
However, akuhn almost hit the real answer, but he didn't go quite far enough in his explanation/example, IMO.
INDEX(Table1[Name], 2) returns "Four"
INDEX(Table1, 1, 1) returns 1
try
=INDEX(col1,1)
you can even address cells in a 2-dim table, using
=INDEX(reference,row_num,column_num)
The trick in such cases is to use Excel OFFSET function:
Accessing 1st row of column named Column1 in the same table: OFFSET([Column1],0,0,1)
Accessing 2nd row OFFSET([Column1],1,0,1)
etc.
Of course you can use this to accces another table and column by just prefixing it with the table name. For example OFFSET(Table2[Column3],4,0,1)will access the 4th row of the column 'Column3' of 'Table2'
There does not seem to be an explicit way of using structured referencing to particular rows in a table.
As Adrian says, you can use INDEX.
Or you can use implicit intersection to reference the same row:
if table1 is on row 5:10 and table 2 is also on row 5:10 then using a structured reference with column names will implicitly intersect the same row.
Or you can enter the structured reference as a multirow array formula (select multiple cells, enter the formula and use Ctrl-shift-Enter) in different rows and it will work.
Instead of INDEX I would suggest SUMIF. It will let you use table values rather than explicit row numbers (which can break if you start filtering or ordering). For example (from the following link), this sums the Amount column and only include those rows where Type equals Check and where Account equals Utilities:
=SUMIFS(Table1[Amount],Table1[Type],“Check”,Table1[Account], “Utilities”)
See this link more info: http://office.microsoft.com/en-us/excel-help/using-structured-references-with-excel-tables-HA010155686.aspx
It would be nice if a table could have a column designated as the primary key (which could be numeric or string), and then a structured ref could include a way to reference a row by it's primary key.
This would be syntax sugar around VLOOKUP, but the table could know if it was sorted on the primary key, and do efficient lookups only in that case. Seems that VLOOKUP embeds evil in it that finds the wrong row if you depend on sorted, especially when tables have a convenient way to sort rows.