List.First Function (Power Query M)

List.First returns the first item of a list, or an optional default value when the list is empty. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

If you want to pull the first value out of a list, or out of a table column, this is the function to reach for.

Syntax of List.First Function

List.First(list as list, optional defaultValue as any) as any

where

  • list (required, list). The list to take the first item from.
  • defaultValue (optional, any). The value to return when the list is empty. Omit it and an empty list returns null.

Returns: a value of type any, the first item in the list. If the list is empty, it returns defaultValue, or null when no default is given. An empty list never causes an error.

In plain terms, you hand it a list and it gives you back whatever sits in position one.

Example 1: Get the first item of a list

Say you have a list of cities in travel order and want the starting point.

let
Source = List.First({"Denver","Tucson","Boise"})
in
Source

Result: Denver

Denver is the first item, so that is what you get back.

Example 2: Call it on an empty list

What happens when the list has nothing in it? No error, just null.

let
Source = List.First({})
in
Source

<!– UNVERIFIED: result not machine-validated, manual check needed – null scalar loads as an empty cell so the validator skipped value comparison; MS Learn documents empty list -> null –>

Result: null

That makes List.First safe to call on lists that might come back empty, like a filtered column.

Example 3: Return a default value instead of null

When a later step needs real text rather than null, pass a defaultValue.

let
Source = List.First({},"No orders yet")
in
Source

Result: No orders yet

The list is empty, so the function falls back to the default you supplied.

Example 4: Get the first value of a table column

A very common real-world use: grab the first value of a column in a query.

Say you have a Shipments query and you want the first ShipmentID.

Here is the starting data:

ShipmentIDCarrier
SHP-4412FastFreight
SHP-4413BlueLine
SHP-4414FastFreight

Table.Column turns the column into a list, and List.First takes it from there:

let
Source = Excel.CurrentWorkbook(){[Name="Shipments"]}[Content],
Result = List.First(Table.Column(Source,"ShipmentID"))
in
Result

Result: SHP-4412

The result is the value from the first row of the ShipmentID column. The same Table.Column trick feeds any list function, such as List.Count for row counts.

Example 5: Get the first segment of split text

List.First pairs nicely with functions that produce lists, like Text.Split or List.Transform. Here it grabs the part of an email address before the @.

let
Source = List.First(Text.Split("ops-desk@brightlayer.io","@"))
in
Source

Result: ops-desk

Text.Split breaks the address into {"ops-desk","brightlayer.io"}, and List.First returns the first segment.

Things to keep in mind with List.First

  • defaultValue only kicks in when the list is empty. A list whose first item happens to be null still returns null. The default never replaces a real first item.
  • First means first by position, not smallest or earliest. If you want the lowest or oldest value, sort the list with List.Sort before taking the first item.
  • It does not fold to a database source. On a large foldable table, apply Table.FirstN(Source,1) first so the source returns a single row, then read the value from that.
  • Need more than one item? Use List.FirstN. It returns the first N items as a list, or every item from the start while a condition holds.

Common questions about List.First

What is the difference between List.First(myList) and myList{0}?

On a non-empty list they return the same item. On an empty list, {0} throws Expression.Error: There weren't enough elements in the enumeration to complete the operation. while List.First returns null or your default. The null-safe positional form is myList{0}?.

Is List.First the same as List.Min?

No. List.First returns whatever happens to be first, regardless of value. List.Min scans the whole list and returns the smallest value, wherever it sits.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.