HLOOKUP on external data table - wrong header row - excel

Trying to run a Hlookup on a table that is linked to a query in a MS database.
The data table is in a separate tab and starts in row 3, and includes a header row. So headers are in row 3, data is from row 4 onwards. data table is named My_Table
My HLOOKUP formula is;
=HLOOKUP("Product1",My_Table,A3,false)
Product1 is the actual header of the column to find, and the cell A3 contains the row number for the lookup. However, this didn't return the data expected. Stepping through the evaluate formula function, Excel is calculating the table to begin in row 4, so is looking for the header in the wrong row (ie row 4). Checking the name manager, the table is locked and shows as starting in row 3.
Has anyone encountered/found a way around this? I would like to keep the table as a table so that it dynamically extends rows as needed based on the results of the query.

To reference the whole table, use
=HLOOKUP("Product1",My_Table[#All],A3,FALSE)
This is called Structured Referencing
Other examples
The entire table =TableName[#All]
The table headers =TableName[#Headers]
To the entire column =TableName[[#All], [ColumnName]]
The header value of a column =TableName[[#Headers], [ColumnName]]
The same row in the table =TableName[[#This Row][ColumnName]]
In Excel 2010 or later =TableName[#ColumnName]
Heading of table =TableName[#Headers]
Entire table (2) =TableName[#All]
Table total row =TableName[#Totals]

Related

Extract rows from table, into another table, where value in column = external value

I'm looking for a formula that would allow me to extract rows from a table where the value in the first column is equal to a reference?
See the table below:
If the value in the first column is equal to 13:00:00, as it is on the right of the pic, extract the relevant row onto a new table. I have attached the spreadsheet to play with.
https://www.mediafire.com/file/eaz7no3263vl3sd/Table.xlsx/file
Just FILTER the range against the reference value:
https://support.microsoft.com/en-us/office/filter-function-f4f7cb66-82eb-4767-8f7c-4877ad80c759

Excel formula referencing hidden table is returning zero when value should not be zero

I have worksheet that displays a table of data that was pulled in by Power Query from another workbook. This table is just a reference table and I have grouped the rows the table is in to make the worksheet less busy/easier to view for the users.
There is a lookup formula that pulls the necessary value from that reference table using table referencing.
=SUMIF(tableName[#Headers],TEXT(AB$7,"m/d/yyyy"),tableName[#Totals])
However, while the table is hidden/the grouping is collapsed, the lookup formula returns zero when it should return something not zero.
When the table is not hidden/the grouping is not collapsed, the lookup formula returns the correct value.
How do I force the lookup formula to return the correct value when the table is hidden/the grouping is collapsed?

find value within specific columns of named tables

Im doing a check for the value in C2 in a table (call it M1table), using this part of the formula:
(C$2=M1table)
Whole formula:
=RIGHT(INDEX(M1table,(SUMPRODUCT((C$2=M1table)*ROW(M1table))-ROW(M1table)),20),1)
How do I specify columns instead of checking the whole table? Unfortunately I don't have named columns, is there a way to do it with column number (look for value of C2 in 2nd to 8th column)? If using column names is the only way, I can name them.
Thank you
If M1table is a real Excel table, then the column header is the name and you can reference like M1table[colName]
If M1table is just a range, and not a real table, then you can use the INDEX function to reference a single column. eg: for the 2nd column in the table:
C$2=INDEX(M1table,0,colNumber)
For columns 2-8 you could use:
=$C2=INDEX(M1table,,2):INDEX(M1table,,8)

How to reference table column header name and table row number?

I'm trying to populate a new table in a new worksheet with data from an existing table in a different worksheet. I need to reference the column header name because the positions of the columns may change.
I currently have this:
=TableName[#[ColumnHeaderName]]
This works but the problem is when I try to sort any of the columns in the new table, it doesn't sort because it is referencing the same row in the existing table. I'm guessing I need to reference the column name and row number, but when I try "=TableName[#[ColumnHeaderName]] 2:2" it displays #VALUE!.
Any help would be greatly appreciated.
It seems that you are working with excel tables (i.e. ListObjects).
The formula:
=TableName[#[ColumnHeaderName]]
refers to the
- Table: TableName
- Column: ColumnHeaderName
- Row: Row of the cell where the formula is entered from the Worksheet where the Table is located.
Therefore if the TableName header is located at row 6 of Sheet1 and the formula is entered in row 8 of Sheet2 it will return the value in column ColumnHeaderName, row 8 of Sheet1 which is the row 2 of the Table.Body (e.i. DataBodyRange)
To return the first value in column ColumnHeaderName of the TableName use this formula:
=INDEX(TableName[ColumnHeaderName],1)
TableName[#[ColumnHeaderName]] refers to the same row of the table and
TableName[ColumnHeaderName] refers to the entire column.
Also, any of the above formulas exclude the header of the Table.
To refer to the header use:
=TableName[[#Headers],[ColumnHeaderName]]
if you want to refer the entire header use:
=TableName[#Headers]
Since you are entering the formula in another excel table, lets named it Table2, in order to have the row number dynamically updated enter this formula:
=INDEX(TableName[ColumnHeaderName],ROW()-ROW(Table2[#Headers]))

Value of Table Cell Referenced In Different Table Cell

I have 2 tables on the same sheet. The first table "Rank" has values in column 1 (or column A) and rows 2 through 8.
I want to use the rows in the Rank table as the header row in the second table "DataTable".
I have tried using =INDEX(A2:E8,2,1) as well as structured references like
=Count(Indirect("Rank["$A$2"]"))
and
=Count(Indirect(Rank[[Attribute]],[A2])).
I either get an error that the formula has a mistake OR I get a value of 0 in the cell with the formula gone.
How do I get the text from the Rank table in cell A2 to be the header in column E of the DataTable?
Column() will return the number of the column in your new table. You can use this to relate to the row in the first table.
Something along the lines of =INDIRECT("RankSheet!A"&COLUMN()-3)
The "-3" assumes that this is going in cell E1 of the new sheet, but that you want cell A2 in the Rank table, so the formula evaluation looks like:
INDIRECT("RankSheet!A" & 5-3)
INDIRECT("RankSheet!A" & 2)
INDIRECT("RankSheet!A2")
Then, as you drag this across, the increasing COLUMN reference will refer to an increasing row reference on the RANK table.

Resources