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
| Parameter | Type | Description |
|---|---|---|
list | list | A list with one item or none. |
default | any 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"