List.SingleOrDefault

Updated on

List.SingleOrDefault is a Power Query M function that returns the single item in a list if the list contains only one item, null if the list is empty, and an error if the list contains more than one item. The function returns the single item, null, or an error.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

List.SingleOrDefault(
   list as list,
   optional default as any,
) as any

Description

If there is only one item in the list list, returns that item. If the list is empty, the function returns null unless an optional default is specified. If there is more than one item in the list, the function returns an error.

Examples

Find the single value in the list {1}.

// Output: 1
List.SingleOrDefault( {1} )

Find the single value in the list {}.

// Output: null
List.SingleOrDefault( {} )

Find the single value in the list {}. If is empty, return -1.

// Output: -1
List.SingleOrDefault( {}, -1 )

Other functions related to List.SingleOrDefault are:

BI Gorilla Blog

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/list-singleordefault