OpenBI Docs Buy

List.SingleOrDefault

The one item of a list, or a default when the list is empty.

Group: List. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

List.SingleOrDefault(list as list, optional default as any) as any
ParameterTypeDescription
listlistA list with one item or none.
defaultany
optional
What to give for an empty list; null when left out.

Returns

any. The one item; when there is none, what default says.

Remarks

  • Two or more items are still an error.

Examples

One item

List.SingleOrDefault({"Oslo"})
"Oslo"

No match, a default instead

List.SingleOrDefault(List.Select({"Oslo", "Bergen"}, each Text.StartsWith(_, "T")), "none")
"none"

List.Single, List.First.

Last updated · OpenBI Studio 0.3.79