CHOOSECOLS

Short answer

Grab just the columns you need from an extract

CHOOSECOLS(array, col_num1, [col_num2], ...)
Excel version
2024+
Also searched as
chooserows, select columns from array, return specific columns, reorder columns formula, last row of array, pick columns from ledger export

What it returns

CHOOSECOLS returns the columns of array you name by number, in the order you name them. CHOOSECOLS(Raw, 3, 7, 12) returns a three-column array: the third, seventh and twelfth columns of Raw, side by side. Every row comes along.

You can repeat a column, reorder columns, and count from the right. A negative number counts from the last column, so -1 is the rightmost column of the array.

CHOOSEROWS is the same function turned on its side. CHOOSEROWS(array, row_num1, [row_num2], ...) returns the rows you name, and -1 is the last row. Both spill, and both arrived together in Microsoft 365 and Excel 2024.

Arguments that matter

ArgumentRequiredWhat it does
arrayYesThe source block. A Table such as LedgerRaw, a range, or another formula’s spilled result.
col_num1YesThe first column to return. Positive counts from the left, negative from the right.
further col_numNoMore columns, in output order. An array of numbers works too: {3,7,12}, or an XMATCH result.

The column numbers are where the risk sits. A hard-coded 7 means “whatever is in the seventh column today”. If the ERP adds a field to the export next quarter, column 7 is now something else, and the model keeps calculating. Drive the numbers from the header row with XMATCH and the formula follows the field, not the position.

Zero, or a number larger than the width of array, returns #VALUE!.

In a financial model

The job is trimming. A general ledger export can arrive with 40 columns: company, ledger, journal ID, batch, period, posting date, account, sub-account, cost center, project, currency, debit, credit, amount, description, user, timestamps. The calculation needs three or four of them.

CHOOSECOLS cuts the block down before anything aggregates it. That keeps the raw tab untouched, per raw data stays raw, and gives every downstream formula a narrow, predictable input.

Where it fits:

  • Feeding GROUPBY or PIVOTBY a short array instead of the full dump.
  • Reordering columns so the key sits first, which some downstream functions and loaders expect.
  • Pulling the latest month from a monthly grid with CHOOSECOLS(grid, -1), which follows the grid as months are added.
  • CHOOSEROWS to grab the closing row of a debt schedule, or the first and last periods for a growth calculation.

If the trim happens every month on a large file, consider doing it in Power Query instead, per transform in Power Query, not in cells. CHOOSECOLS suits workbooks where the extract is pasted or loaded as a Table and you want the logic visible in a cell.

Worked example

A ledger export loaded to tab Raw as a Table called LedgerRaw, 40 columns wide. The fields the model needs are Posting Date, Account and Amount, which today sit in columns 6, 7 and 14.

The quick version:

=CHOOSECOLS(LedgerRaw, 6, 7, 14)

The version that survives a layout change:

=CHOOSECOLS(LedgerRaw, XMATCH({"Posting Date","Account","Amount"}, LedgerRaw[#Headers]))

XMATCH returns {6,7,14} today. If the export gains a column before Posting Date, it returns {7,8,15} and the output does not move.

Company…Posting DateAccount…Amount…
UK01…03-Jan-266100…1,240.00…
UK01…03-Jan-264000…(18,500.00)…

Returns:

Posting DateAccountAmount
03-Jan-2661001,240.00
03-Jan-264000(18,500.00)

The latest month from a P&L grid on tab IS, line items down rows 12 to 40, months across from column D:

=CHOOSECOLS(IS!$D$12:$O$40, -1)

And the closing balance row of a debt schedule held in Debt!$D$8:$O$14:

=CHOOSEROWS(Debt!$D$8:$O$14, -1)

Old way vs new way

Before CHOOSECOLS, a trimmed column was often one OFFSET per field, sized by a count:

=OFFSET(Raw!$A$1, 1, 5, COUNTA(Raw!$A:$A)-1, 1)

The new way:

=CHOOSECOLS(LedgerRaw, XMATCH({"Posting Date","Account","Amount"}, LedgerRaw[#Headers]))

OFFSET is volatile, recalculating on every change in the workbook (see avoid volatile functions), and it needs one formula per column. CHOOSECOLS is one non-volatile formula that picks fields by name.

Where it breaks

CHOOSECOLS returns #VALUE!. A column number is zero, or larger than the number of columns in array. It often follows an export that lost a field. Fix: check the width with COLUMNS(LedgerRaw), and drive the numbers from XMATCH so a missing header shows as #N/A from XMATCH instead.

The figures moved but nothing errored. The column numbers are hard-coded and the export layout changed, so 14 now points at Credit instead of Amount. Fix: match headers by name with XMATCH, and keep a check row that ties the trimmed total to the source total.

CHOOSECOLS returns #NAME?. The file is open in Excel 2021 or earlier. CHOOSECOLS and CHOOSEROWS arrived in Excel 2024, so a 2021 user has FILTER and XLOOKUP but not these. Fix: if the model must run in 2021, use INDEX(LedgerRaw, SEQUENCE(ROWS(LedgerRaw)), {6,7,14}).

CHOOSECOLS returns #SPILL!. The output block is not empty, or the formula sits inside a Table. Fix: put it on a plain range with clear space below and to the right.

A header row turns up in the totals. The source is LedgerRaw[#All] or a range that starts on the header row, so the first output row is text. Fix: point at the Table name alone, which excludes headers.

CHOOSEROWS with -1 picks up a blank row. The range was sized past the last real row, so the last row is empty. Fix: point at a Table or a spilled range that ends where the data ends, or combine with TAKE.

Related functions

  • XMATCH. Turns header names into the column numbers CHOOSECOLS needs. Use the two together on any extract you do not control.
  • FILTER. Picks rows by condition. Wrap it around CHOOSECOLS to cut both rows and columns in one formula.
  • TAKE. Returns the first or last n rows or columns. Reach for it over CHOOSEROWS when you want a block, such as the last 12 months.
  • GROUPBY. Takes the trimmed array and summarizes it.
  • VSTACK. Stacks several trimmed entity extracts into one table.
  • The play on raw data stays raw covers why the trim happens in a formula and not by deleting columns.

All functions