My use case is more complex than this but I think this example illustrates my problem clearly.
I have a simple table in Google Sheets. It is called test
.
Name | 1st Number | 2nd Number |
---|---|---|
Hat | 1 | 2 |
Cat | 4 | 8 |
Mat | 16 | 32 |
I am able to return the sum of the values in its 2nd column by using the formula: =sum(test[1st Number])
However, I am unable to copy that exact string of test[1st Number]
into a cell to reference it using INDIRECT =sum(indirect(B1))
to get the sum of that column.
The error I am getting is:
Function INDIRECT parameter 1 value is 'test[1st Number]'. It is not a valid cell/range reference.
I am hoping that there is an error in my formula rather than it being impossible to reference a named column in a table using INDIRECT.
I used index
and match
as recommended by @doubleunary below to have the formula
=sum(index(test, 0, match(C1, test[#HEADERS], 0)))
referencing the string 1st Number
in cell C1
Structured table references are not currently (December 2024) supported by the indirect()
function. Use this pattern instead:
=sum(index(Table1, 0, match(B1, Table1[#HEADERS], 0)))
...where cell B1
matches the name of the column you want to sum.