Lookup and reference functions
CHOOSECOLS
Matches all 17 recorded answers
Recorded: 17 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | CHOOSECOLS |
| Bulgarian | CHOOSECOLS |
| Czech | ZVOLITSLOUPCE |
| Danish | VÆLGKOL |
| German | CHOOSECOLS |
| Greek | CHOOSECOLS |
| English (Australia) | CHOOSECOLS |
| English (United Kingdom) | CHOOSECOLS |
| English (United States) | CHOOSECOLS |
| Spanish | ELEGIRCOLS |
| Estonian | CHOOSECOLS |
| Finnish | VALITSESARAKKEET |
| French | CHOISIRCOLS |
| Hebrew | CHOOSECOLS |
| Croatian | CHOOSECOLS |
| Hungarian | OSZLOPVÁLASZTÁS |
| Indonesian | CHOOSECOLS |
| Italian | CHOOSECOLS |
| Japanese | CHOOSECOLS |
| Korean | CHOOSECOLS |
| Lithuanian | CHOOSECOLS |
| Latvian | CHOOSECOLS |
| Norwegian | CHOOSECOLS |
| Dutch | KIES.KOLOMMEN |
| Polish | WYBIERZ.KOLUMNY |
| Portuguese (Brazil) | CHOOSECOLS |
| Portuguese (Portugal) | ESCOLHERCOLS |
| Romanian | CHOOSECOLS |
| Russian | ВЫБОРСТОЛБЦ |
| Slovak | CHOOSECOLS |
| Slovenian | CHOOSECOLS |
| Serbian (Latin) | CHOOSECOLS |
| Swedish | VÄLJKOL |
| Thai | CHOOSECOLS |
| Turkish | SÜTUNSEÇ |
| Ukrainian | CHOOSECOLS |
| Vietnamese | CHOOSECOLS |
| Chinese (Simplified) | CHOOSECOLS |
| Chinese (Hong Kong) | CHOOSECOLS |
| Chinese (Traditional) | CHOOSECOLS |
Names from Microsoft's support site.
What it does
CHOOSECOLS(array, col_num1, [col_num2], ...)
Three properties follow from "in the order given" and are the reason the function exists at all:
- It reorders.
CHOOSECOLS(A, 3, 1, 2)is a column permutation. - It duplicates. An index may repeat;
CHOOSECOLS(A, 1, 1)yields a two-column array whose columns are equal. The output column count is the number of indices, not the number of distinct indices. - It projects to fewer or more columns than the input has. Fewer by omission, more by repetition.
Row count is invariant: the result has exactly as many rows as array. Only the column axis is
touched.
Indices are one-based, and Microsoft documents that a negative index counts from the end of
the array — -1 is the last column, -2 the second to last. There is no zero index; zero is an
error, which is the natural consequence of one-based counting from both ends.
Arguments
| Argument | Meaning |
|---|---|
array | The array or range whose columns are to be selected. Required. |
col_num1 | The first column to return. One-based; negative counts from the last column. Required. |
col_num2, … | Further columns, in output order. Optional, up to the arity ceiling of 255 arguments. |
An index argument may itself be an array — CHOOSECOLS(A, {1,3,5}) — which is how you select a
computed set of columns without writing them out. The interaction between an array-valued index
argument and several index arguments (CHOOSECOLS(A, {1,2}, 4)) is a shape question the
Handbook has not settled.
The position readers misjudge is the first: array is a single argument, so a multi-area
reference or a comma-separated list of ranges does not work here the way it does for HSTACK.
If you want to combine several sources and then select, stack first, select second.
Try it
Quirks
Result and edge cases
Return kind: Array, of shape (rows of array) × (number of index values). The result spills
in dynamic-array Excel; the shared spill and adaptation rules are the host-side concern
described in the call pipeline, not function semantics.
- A scalar or 1×1
array. One column exists, soCHOOSECOLS(x, 1)is defined; anything else is out of range. - A reference argument.
arrayis prepared underValuesOnlyPreAdapter: the reference is resolved to values before the function runs, so the result is an array of values and carries no reference structure. ConsequentlyCHOOSECOLScannot be used where a reference is required. - Mixed types. No coercion is applied to the selected elements; text, logicals and errors pass through as themselves.
Errors
Microsoft's page documents the error condition directly: CHOOSECOLS returns #VALUE! if any
col_num argument is zero or exceeds the number of columns in array. By the symmetry of the
documented negative indexing, an index more negative than the column count is out of range on
the same rule.
Beyond that, an error value supplied as an argument (rather than sitting inside the array) propagates under the universal rule in coercion and lifting.
Whether a fractional index is truncated or rejected is not established here.
How to implement
Notes for implementers
- Output width is the index count, not the distinct-index count. Any implementation that deduplicates or sorts the index list silently changes the answer. This is the easiest bug to write and the hardest to notice, because the common case has distinct ascending indices.
- Negative indices must be resolved against the input width before bounds checking, and the bounds check must reject zero. The three cases — positive, negative, zero — are one branch each; folding zero into either sign's path produces an off-by-one.
- The whole family shares one module in the reference implementation
(
dynamic_array_reshape_family.rs, shared withCHOOSEROWS,DROP,EXPAND,FILTER,SORT,SORTBY,TAKE,TOCOL,TOROW,TRANSPOSE,UNIQUE,VSTACK,WRAPCOLS,WRAPROWS). Shared code means a shared shape-and-bounds discipline, and it means a test that passes here may be exercising machinery the sibling functions also depend on. - Empty results are not representable. There is no zero-column array in the value model, so a selection that yields nothing has to become an error rather than an empty result. That is the structural reason the zero index is an error rather than a no-op.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
CHOOSECOLS · 3 lines · calc-func/src/catalogue/arrays.rs on GitHub9 choosecols_fn "CHOOSECOLS" (2, 255) [R "array", R "col_num1", R "col_num2"] |s, a, sv| {
choose(s, a, sv, k::eval_choosecols_prepared)
}
eval_choosecols_prepared · 18 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHubpub fn eval_choosecols_prepared(
args: &[CalcValue],
) -> Result<CalcValue, DynamicArrayReshapeEvalError> {
let array = materialize_array_arg(&args[0]);
let cols: Vec<usize> = args[1..]
.iter()
.map(parse_integer)
.map(|result| result.and_then(|idx| resolve_selector(idx, array.shape().cols)))
.collect::<Result<_, _>>()?;
let mut cells = Vec::with_capacity(array.shape().rows * cols.len());
for row in 0..array.shape().rows {
for col in &cols {
cells.push(array.get(row, *col).expect("validated selector").clone());
}
}
build_array(array.shape().rows, cols.len(), cells)
}
Kernels shared with other functions
source_errorcatalogue/arrayspreparedcatalogue/arraysprepared_onecatalogue/arraysresultcatalogue/arrayschoosecatalogue/arraysas_arraycatalogue/arrayscoerce_prepared_to_numberported/dynamic_array_reshape_familyscalar_cellported/dynamic_array_reshape_familymaterialize_array_argported/dynamic_array_reshape_familyshapeported/dynamic_array_reshape_familygetported/dynamic_array_reshape_familyparse_integerported/dynamic_array_reshape_familyresolve_selectorported/dynamic_array_reshape_familybuild_arrayported/dynamic_array_reshape_familymap_dynamic_array_reshape_error_to_wsported/dynamic_array_reshape_family
Argument and result plumbing
failcatalogue/kitgridcatalogue/kitscalar_errorcatalogue/kitnumbercoerce
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
CHOOSEROWSis the same function on the other axis, with the same negative-index rule and the same error condition. The pair is symmetric by construction.TAKEandDROPselect a contiguous block from an edge.CHOOSECOLSselects an arbitrary list. If your selection is "the first three columns",TAKEsays it more directly and does not require you to enumerate.HSTACKis the inverse operation in spirit:CHOOSECOLSsplits columns out of one array,HSTACKjoins columns from several.FILTERselects along an axis too, but by predicate rather than by index, and it filters rows or columns according to the shape of itsincludeargument.CHOOSEshares a prefix and is unrelated: it selects among arguments, not among columns of an array.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents