List.First Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The List.First function in Power Query gives you the first item in a list. If the list is empty, it returns null, or a default value you choose.

Since a column, a filtered set of rows, or a few cells from the same row can all be turned into a list, List.First is handy for things like getting the opening value, the first match, or the first non-blank value.

Follow along with the example file

List.First Function Examples.xlsx

Download

List.First Function Syntax

List.First(list as list, optional defaultValue as any) as any
  • list – the list you want the first item from. It can be a list you type in curly brackets, such as {"A","B","C"}, or a column of a table.
  • defaultValue (optional) – the value to return if the list is empty. If you leave it out, an empty list gives you null.

What it returns: The first item in the list, whatever its type (text, number, date, and so on). If the list is empty, you get the default value, or null when there’s no default.

The List.First function is part of the Power Query M language, so it works wherever Power Query does in Excel: Excel 365, 2024, 2021, 2019, and 2016 for Windows, and Excel for Microsoft 365 on Mac.

When to Use the List.First Function

Use this function when you need to:

  • Get the first value in a column, like an opening price or a starting balance
  • Find the first row that meets a condition, like the first month that hit a target
  • Pick the first non-blank value from a few columns in the same row
  • Get the first value for each group (each customer, project, or region) with Table.Group
  • Look up the first match from another table, with a fallback when there is no match
  • Refer to the first column of a table without typing its name

Example 1: Get the First Item in a List

Let’s start with the simplest use. Suppose you have a list of order status stages, and you want the first stage.

In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor that opens, type this formula in the formula bar:

= List.First({"Pending","Approved","Shipped","Delivered"})

Result: Pending

List.First returns Pending, the first item in the list of order stages

Here, the curly brackets create a list of four text values, and List.First returns the one at the top, which is “Pending”.

You’ll rarely type the list yourself like this. But it shows the one thing List.First needs, which is a list, and the rest of the examples are about getting that list out of your data.

In the example file, Examples 1 and 3 type their values right into the query, so they don’t have a sheet. You can open them from Data > Queries & Connections.

Example 2: Get the First Value in a Column

Here’s a common use. Below is a weekly price log for a product in an Excel Table named PriceLog, and I want the starting price (the price in the first row).

PriceLog table with a weekly price for six weeks

In the code below, the Source line uses the Excel.CurrentWorkbook function to pull the PriceLog table into Power Query by its name.

If you try this on your own data, format it as a table (Ctrl + T) and put your table’s name in place of “PriceLog”.

Create a new blank query (as in Example 1), open the Advanced Editor (Home > Advanced Editor), and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="PriceLog"]}[Content],
StartingPrice = List.First(Source[Price])
in
StartingPrice

Result: 24.5

List.First of the Price column returns the starting price, 24.5

Here, Source is the name of the first step, and it holds the PriceLog table. Source[Price] takes the Price column and returns it as a list, and List.First returns its first item, 24.5.

List.First goes by position, not by size. The lowest price in this log is 21.9 (Week 5), but List.First still returns 24.5 because that’s the value in the first row.

So if your rows aren’t in the order you need, sort them first with the Table.Sort function. And if you want the highest value rather than the first one, use the List.Max function instead.

Example 3: Return a Default Value When the List Is Empty

Before we use List.First on filtered data, it helps to see what happens when there’s nothing in the list. This example puts both cases side by side in a small table.

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = #table({"Formula","Result"},{
{"List.First({})",List.First({})},
{"List.First({},""No items"")",List.First({},"No items")}})
in
Source

Result: A small table where the first row shows null and the second row shows No items

List.First on an empty list returns null, or No items when a default is given

Here, the #table function builds a two-row table. The Formula column shows each formula as text, and the Result column shows what it returns.

The doubled quotes in ""No items"" are only there because that formula is stored as text, and the table shows it as List.First({},"No items"). In your own formula, type it with one pair of double quotes: List.First({},"No items").

{} is an empty list, so with no second argument, List.First returns null for it. With “No items” as the second argument, it returns “No items” instead.

This matters when the list comes from a filter, because a filter that matches no rows gives you an empty list. Without a default, you get null, which shows as a blank cell once the result is loaded to a sheet.

A default value like “Not found” or 0 tells anyone looking at the result what happened.

You may also see {0} used to get the first item, as in Source[Price]{0}. The difference is that {0} gives the error “There weren’t enough elements in the enumeration to complete the operation.” on an empty list, while List.First returns null or your default.

Example 4: Find the First Row That Meets a Condition

Now let’s combine List.First with a filter. Below is a table named MonthlySales with the sales for each month, and I want the first month where sales reached the target of 50,000.

MonthlySales table with sales for January to August

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="MonthlySales"]}[Content],
FirstMonth = List.First(Table.SelectRows(Source,each [Sales]>=50000)[Month],"Not reached")
in
FirstMonth

Result: May

May is the first month with sales of 50,000 or more

Here, the Table.SelectRows function keeps only the rows where Sales is 50,000 or more. That’s May, Jul, and Aug.

[Month] at the end takes the Month column from those rows as a list ({“May”, “Jul”, “Aug”}), and List.First returns the first one, May.

If no month had reached the target, the filter would return no rows and the list would be empty. In that case, the formula returns “Not reached” (the second argument) instead of null.

Follow along with the example file

List.First Function Examples.xlsx

Download

Example 5: Get the First Non-Blank Value in a Row

This next one comes up a lot with contact lists. Below is a table named Contacts with up to three phone numbers for each person, and I want a Best Phone column with the first number available, checking Mobile, then Work, then Home.

Contacts table with Mobile, Work and Home numbers, some of them blank

The blank cells come into Power Query as null. Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Contacts"]}[Content],
#"Added Best Phone" = Table.AddColumn(Source,"Best Phone",each List.First(List.RemoveNulls({[Mobile],[Work],[Home]}),"No phone"),type text)
in
#"Added Best Phone"

Result: A new Best Phone column (555-0187, 555-0142, 555-0119, No phone, and 555-0175)

A new Best Phone column with the first available number, or No phone

Here, the Table.AddColumn function adds a Best Phone column and runs the formula after each once for every row.

For each row, {[Mobile],[Work],[Home]} builds a list of that row’s three numbers, in the order you want them checked. The List.RemoveNulls function then drops the nulls, and List.First takes the first number that’s left.

For example, Emily Wood has no mobile number, so her list becomes {“555-0187”, “555-0123”} after the nulls are removed, and List.First returns her work number, 555-0187.

Philip Rogers has no numbers at all, so his list is empty after removing the nulls, and the formula returns “No phone”.

With only three fixed columns, you could also write [Mobile] ?? [Work] ?? [Home] ?? "No phone", where the ?? operator moves on to the next value whenever the one on its left is null. The List.First version is easier to extend when you have more columns to check.

Important: Don’t skip List.RemoveNulls. List.First returns the first item even when it’s null, so List.First({[Mobile],[Work],[Home]}) would give Emily Wood and Spencer Gibson a blank (null) Best Phone.

Example 6: Get the First Value for Each Group

This is a common use of List.First with grouping. Below is a log of plan changes in a table named PlanChanges, in date order, and I want each customer’s starting plan in a Starting Plan column.

PlanChanges table with each customer's plan changes in date order

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="PlanChanges"]}[Content],
#"Grouped Rows" = Table.Group(Source,{"Customer"},{{"Starting Plan",each List.First([Plan]),type text}})
in
#"Grouped Rows"

Result: One row per customer with their Starting Plan (Douglas Brooks Basic, Jennifer Hughes Pro, and Leslie Owens Basic)

Table.Group with List.First gives each customer's starting plan

Here, the Table.Group function groups the rows by Customer. For each customer, [Plan] is the list of plans from that customer’s rows only, and List.First returns the first one.

For example, Douglas Brooks has three rows with Basic, Pro, and Team, so his starting plan is Basic.

This works because the log is already in date order, so each customer’s first row is their earliest change. If your log isn’t sorted, the first row may not be the earliest one, so sort it by date first.

If you need the first few values for each group instead of just one, the List.FirstN function does that.

Example 7: Look Up the First Match from Another Table

This one is useful when the data you need is in a separate table. Below is a list of support tickets in a table named Tickets, and I want an Agent column with the agent who handles each ticket’s region.

Tickets table with the region of each support ticket

The agents are in a separate table named Agents, on the Example 7 Agents sheet. West has two agents (the first one listed is the main contact), and no agent covers Central.

Agents table with two agents for West and none for Central

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="Tickets"]}[Content],
Agents = Excel.CurrentWorkbook(){[Name="Agents"]}[Content],
#"Merged Agents" = Table.NestedJoin(Source,{"Region"},Agents,{"Region"},"Agent",JoinKind.LeftOuter),
#"First Agent" = Table.TransformColumns(#"Merged Agents",{{"Agent",each List.First([Agent],"Unassigned"),type text}})
in
#"First Agent"

Result: A new Agent column (Jill Edwards, Todd Thomas, Unassigned, Jill Edwards, and Gerald Johnson)

A new Agent column with the first matching agent, or Unassigned

Here, the Table.NestedJoin function merges the two tables on the Region column. It’s the same step Power Query writes when you use Home > Merge Queries with a Left Outer join.

After the merge, each ticket’s Agent cell holds a small table with the matching rows from the Agents table. A ticket in West gets a table with two rows, and the ticket in Central gets an empty table.

The Table.TransformColumns function then changes every cell in the Agent column. For each cell, [Agent] takes the Agent column of that small table as a list, and List.First returns the first name in it.

For West, the list is {“Jill Edwards”, “Alyssa Shaw”}, so both West tickets get Jill Edwards, the main contact.

No agent covers Central, so the list for TK-203 is empty, and List.First returns “Unassigned” (the second argument) instead of null.

Example 8: Rename the First Column Without Typing Its Name

This last one uses List.First on column names. Below is a sales export in a table named SalesExport, where the first column’s header changes every month (here it’s “Store (Nov 2026)”), and I want to rename that column to Store.

SalesExport table whose first column header is Store (Nov 2026)

If you rename the column by double-clicking its header, Power Query writes the old name “Store (Nov 2026)” into the step. Next month the header is different, so the refresh stops with the error “The column ‘Store (Nov 2026)’ of the table wasn’t found.”

Create a new blank query, open the Advanced Editor, and use this code:

let
Source = Excel.CurrentWorkbook(){[Name="SalesExport"]}[Content],
#"Renamed First Column" = Table.RenameColumns(Source,{{List.First(Table.ColumnNames(Source)),"Store"}})
in
#"Renamed First Column"

Result: The first column is renamed to Store

The first column is renamed to Store without typing its old name

Here, the Table.ColumnNames function returns the table’s column headers as a list ({“Store (Nov 2026)”, “Units”, “Revenue”}), and List.First takes the first one.

The Table.RenameColumns function then renames that column to Store. Since the code never types the old header, it keeps working when the header changes next month.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.