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.
Related
In a spreadsheet I'm making for my Thermodynamics class, I created an appendix with important values for certain molecules, such as the molar mass of Ethane. I have named the rows to the molecule names and columns to the important variables.
I want to be able to simply type some version of =Ethane_molarmass or something like that to call the specific cell. Is this possible, and how?
Assuming you have named the column molarmass and the row ethane, you can simply get the intersecting value using this formula:
=ethane molarmass
Try:
=INTERSECT(ColumnRangeName, RowRangeName)
or without the named ranges, for example,
=INTERSECT(B:B,2:2) for the value in Col B, Row 2
or dynamically (not ideal):
=INTERSECT(INDIRECT("ColumnRangeName"),INDIRECT("RowRangeName"))
I'm using following dynamic table reference several times in my workbook which is causing performance issues:
SUMIFS(INDIRECT(VLOOKUP($A$1,$A$2:$B$4,2,0)&"[kpi_name]"),INDIRECT(VLOOKUP($A$1,$A$2:$B$4,2,0)&"[filter1]"),UPPER($H13))
based on the input in A1 I need to switch between table1, table2 and table3.
I do this by building a vlookup map in A2:B4 that return the appropiate table names and using this + column name in a indirect formula.
I would like to move to a better solution using INDEX or another named range.
I tried to use a named range with a formula returning the right table reference:
=IF(A1=1,table1,IF(A1=2,table2,IF(A1=3,table3,0)))
But this way I can't use named_range[column of table]
Also I can't get a working solution with INDEX...
Thanks to the comments of the initial question I came up with follow:
SUMIFS(INDEX(CHOOSE(A1,TABLE1,TABLE2),,MATCH(VAR_COLUMN_NAME,INDEX(CHOOSE(A1,TABLE1,TABLE2),1,0),0)),INDEX(CHOOSE(A1,TABLE1,TABLE2),,MATCH("filter1",INDEX(CHOOSE(A1,TABLE1,TABLE2),1,0),0)),UPPER(ABC))
I'm working on an Excel 2010 worksheet that uses a table that references a secondary table to generate a list of values.
More specifically, I have two tables: Table_Players and Table_ChallengeCalc. In Table_Players, I have the columns Players, Experience, and Level. I input the total number of points that a given player has under the experience table, and using this formula the level column tells me what level the player is:
Table_Players:
=LOOKUP(C6,
{-1;0;300;900;2700;6500;14000;23000;34000;48000;64000;85000;100000;120000;140000;165000;195000;225000;265000;305000;355000},{"0";"1";"2";"3";"4";"5";"6";"7";"8";"9";"10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"20"})
Table_ChallengeCalc resides on a different sheet in the workbook, and references the Level value in Table_Players to pull a list of additional values from another table, Table_Difficulty.
Before I implemented the above lookup formula, I was just manually inputting the player's levels and in turn, the Table_ChallengeCalc was pulling the correct values for the remaining columns, using this to load the player's assigned level on Table_Players:
Table_ChallengeCalc:
=VLOOKUP([Players],Table_Players[Level],3,FALSE)
(Here's what it looks like when it works correctly):
However, as soon as I added the first LOOKUP value, the second VLOOKUP immediately became #N/A and in turn, so did all of the rest of the reference columns. If I remove the first lookup and manually enter the level again, the VLOOKUP immediately starts working again. I tried using a nested INDEX/MATCH statement, but it had the same results. As long as I'm using that first LOOKUP, Table_ChallengeCalc can't seem to pull the level value.
If I didn't know any better, it would seem to me that the workbook is trying to run the VLOOKUP simultaneously, if not immediately prior, the LOOKUP formula. Any ideas on how I can counter this, or is this one of those things where I've kind of hit the limitations of what an Excel workbook can do without additional software like VBA?
If I understand your issue correctly, then using the following formula should work for you:
=VLOOKUP([Players], Table_Players, 3, FALSE)
You currently have this in your table_array: Table_Players[Level], but your "[Level]" column is coming from the col_index_num: 3 in the formula, so you should not include this in your table array.
I have a pricelist, with currently 5 different categories of products. Each product will have to have two different prices. Depedning of the product and the type of price, the calculation will be different. Therefor I've used INDEX/MATCH to find the formula needed, from a table I created.
Below a screendump, and I wanted to attach the Excel fil, but canøt seem to work out how.
Question: HOW do I then "run" the formula I fetched? -I've tried different suggestions on using EVALUATION, but it doesn't seem to cut it? Also I've tried "Indirect' on the whole formula, without success.
I would like to avoid any VBA for this case.
Can anybody provide some insight?
You could but if I understand properly, the only thing changing in the formulas is the "muliplier" number, then it's better to lookup that number instead of the whole formula. The other method (which would use Evaluate etc) is not be considered "good practice" for a number of reasons.
EDIT:
I didn't see the 2nd varying value (since I was on the SO mobile app) but it's still not an issue since it would a target column. You could be thinking of the opposite: sometimes lookups based on multiple criteria can get complicated, but this a matter of more data, as opposed to adding criteria for the lookup.
VLookup would have been the simplest method, like G2 could have been:
=VLOOKUP(E2, $J$4:$L$8, 2, False)
...to return the second column of range J4:L8 where the first column equals E2. (Then for the next required column, same formula except with 3 instead of 2.)
Since I wasn't sure more columns could be added one day, I allowed for that by, instead of specifying "Column 2 or 3" etc, it finds the column dynamically by name. (So the multiplier/factor used in G2 will change if you change the title in G1 to the name of a different column existing in the target data chart.
For the sake of neatness as well as potential of additional columns like G & H, I moved the lookup table to a separate sheet. It can stay out of the way since you won't need to see or change it very often. (If the same chart was going to be referenced by many workbooks, you could even move it to a separate workbook and point all formulas at that, since it's always best to have one copy of identical data instead of many in different workbooks.
Also to assist with potential future changes (and just to be tidier), instead of referring to the target table range addresses (like "J4:L8" etc) I named two ranges:
the table of multiplier/factor data can be referred to by it's address, or by myMultipliers
the titles of the same table is also called myMultiplierTitles (used to match to the titles of column G & H on the original sheet.
Formula
After those changes, the lookup formula in G2 is:
=INDIRECT(VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0),FALSE)&ROW())*VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0)+1,FALSE)
INDIRECT returns the value of a cell that you refer to by name (text/string) as opposed to directly (as a range). For example:
=INDIRECT("A1")
returns the same as
=A1
...but with INDIRECT we can get the name from elsewhere (a cell, function or formula). So if x="A1" then =INDIRECT(x) returns the same as the 2 above examples.
Your original plan of storing the entire formula in a table as text would have worked with the help of INDIRECT and/or EVALUATE but I think this way is considered better practice partly because it facilitates easier future expansion.
The formula is longer than it would have been, but that's mostly because it's dynamically reading the field names. And size doesn't matter. :-)
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.