Forum Discussion
Hogstad_Raadgivning
Jul 14, 2023Steel Contributor
Add the table name to a column using VSTACK.
Hi, When I combine multiple tables in Excel using Vstack, is there an easy way to add the table name to the dynamic list? All tables have the same structure. One workaround is to add a new co...
- Jul 14, 2023
Hogstad_Raadgivning I don't know of a way to dynamically grab the Table Name but given a Table Name you can easily ADD that column using EXPAND():
=VSTACK(EXPAND(t_appelsin,,4,"t_appelsin"),EXPAND(t_plommer,,4,"t_plommer"),EXPAND(t_pærer,,4,"t_pærer"))
flexyourdata
Jul 14, 2023Iron Contributor
You can create a simple LAMBDA to add the table name to any column, thought it does use INDIRECT, so may have performance impacts on workbooks with many calculations or large datasets:
ADDTABLENAMECOLUMN = LAMBDA(tableName,
LET(
tbl, INDIRECT(tableName),
EXPAND(tbl, , COLUMNS(tbl) + 1, tableName)
)
);
This works because we can pass the string version of the table name to INDIRECT to return a reference to the Table.
We can then use it in your formula, like this:
=VSTACK(
ADDTABLENAMECOLUMN("t_appelsin"),
ADDTABLENAMECOLUMN("t_plommer"),
ADDTABLENAMECOLUMN("t_pærer")
)
- Hogstad_RaadgivningJul 15, 2023Steel ContributorThank you for your tip.