Table.FirstValue

Updated on

Table.FirstValue is a Power Query M function that returns the first column of the first row of a table or a specified default value. The function returns a single value.

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

Syntax

Table.FirstValue(
   table as table,
   optional default as any,
) as any

Description

The Table.FirstValue function returns the value in found in the first row of the first column in a table. When this table is empty, it returns null or an optional fallback value as specified in the second argument.

Examples

Let’s look at how we can make use of the Table.FirstValue function. Suppose you have a table called Source that looks as follows:

Table.First dataset as start in Power Query M

You can return the first value, in this case 1, by using:

// Returns: 1
Table.FirstValue( Source )

Working with Empty Tables

In case you provide an empty table to Table.FirstValue, it will return a null value as output:

// Output: null
Table.FirstValue( #table( type table ,{  } ) )

Default Return Value

When running into empty tables, you may want to return a default value. The function supports this by providing a value for its second argument.

// Output: 99
Table.FirstValue( 
  #table( type table, {} ),
  99
)

Other functions related to Table.FirstValue are:

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

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy