Excel structured reference table syntax
Asked Answered
T

6

12

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.

Toscano answered 10/12, 2009 at 10:49 Comment(1)
This seems somewhat at odds with the spirit of a structured table. A good practice would be that there should be no information captured in the ordering of the rows. Columns are attributes, rows are instances or observations. Consider adding an index column (Like Order or Date, or Sequence), and then pick out the one with Sequence equal to 1.Sawyer
S
13

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

Starling answered 16/6, 2012 at 17:13 Comment(0)
B
5

try

=INDEX(col1,1)

you can even address cells in a 2-dim table, using

=INDEX(reference,row_num,column_num)
Bejewel answered 10/12, 2009 at 10:58 Comment(0)
J
2

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'

Justifiable answered 1/3, 2018 at 9:53 Comment(0)
S
0

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.

Spiculum answered 10/12, 2009 at 11:55 Comment(0)
S
0

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

Syrian answered 17/8, 2011 at 19:2 Comment(0)
V
0

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.

Viperish answered 26/8, 2017 at 14:45 Comment(1)
The range_lookup fourth parameter to the VLOOKUP() function requires exact matches and works even in tables that are not sorted. It returns an error if no match is located.Sydelle

© 2022 - 2024 — McMap. All rights reserved.