Skip to content

Instantly share code, notes, and snippets.

@ExcelRobot
Last active May 14, 2024 01:37
Show Gist options
  • Save ExcelRobot/e54ef43a981362c0b414ee27cf3e0fcb to your computer and use it in GitHub Desktop.
Save ExcelRobot/e54ef43a981362c0b414ee27cf3e0fcb to your computer and use it in GitHub Desktop.
Choose Table Columns LAMBDA Function
/*
Name: Choose Table Columns (CHOOSETABLECOLUMNS)
Description: Similar to CHOOSECOLUMNS but can accept an array of column header names or
array of column indexes. If column headers are used, assumes first row of Table is
header row.
Author: Excel Robot (@ExcelRobot)
Category: Table
*/
CHOOSETABLECOLUMNS = LAMBDA(Table, ColumnsToSelect, LET(
FirstColumnToSelect, INDEX(ColumnsToSelect,1,1),
ColumnIndexes, IF(
AND(ISNUMBER(FirstColumnToSelect),IFERROR(AND(FirstColumnToSelect>0,FirstColumnToSelect<=COLUMNS(Table),TRUNC(FirstColumnToSelect)=FirstColumnToSelect),
FALSE)),
ColumnsToSelect,
MATCH(ColumnsToSelect,INDEX(Table,1,),0)),
SelectedColumns, INDEX(Table,SEQUENCE(ROWS(Table)),ColumnIndexes),
SelectedColumns
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment