List.Last Function (Power Query M)

List.Last returns the last item in a list. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

If you want to grab the final value in a list, the last value in a column, or the last piece of a split-up string, this is the function you reach for.

Syntax of List.Last Function

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

where

  • list (required, list). The list you want the last item from.
  • defaultValue (optional, any). The value returned when list is empty. Omit it and an empty list returns null.

Returns: the last item of the list, with its own type kept (text stays text, a number stays a number). If the list is empty, it returns defaultValue, or null when no default is given.

In plain terms, you hand it a list and it gives you back the item sitting at the very end.

Example 1: Get the last item of a list

Pull the final genre out of a short list.

let
Source = List.Last({"Mystery","Sci-Fi","Romance"})
in
Source

Result: Romance

Romance is the last item, so that is what comes back.

Example 2: Handle an empty list with no default

Ask for the last item of an empty list to see what happens.

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

Result: null

An empty list has no last item, so List.Last returns null instead of throwing an error.

Example 3: Return a fallback value for an empty list

Pass a second argument so an empty list returns something readable instead of null.

let
Source = List.Last({},"No entries found")
in
Source

Result: No entries found

The list is empty, so List.Last returns defaultValue rather than null.

Example 4: Get the last value of a table column

Grabbing the last value of a column is where you will use this most.

Say you have an Invoices table with an InvoiceID and a Client column.

You want the most recently added invoice ID, which sits in the last row.

Here is the starting data:

InvoiceIDClient
INV-90Northwind
INV-91Contoso
INV-92Fabrikam

Pull the InvoiceID column into a list, then take its last item:

let
Source = Excel.CurrentWorkbook(){[Name="Invoices"]}[Content],
Result = List.Last(Table.Column(Source,"InvoiceID"))
in
Result

Table.Column turns the column into a list and List.Last returns its final value.

Result: INV-92

INV-92 is the value in the last row of InvoiceID.

Example 5: Get the last segment of split text

Split a file path on the backslash and keep only the file name at the end.

let
Source = List.Last(Text.Split("reports\2026\summary.xlsx","\"))
in
Source

Result: summary.xlsx

Text.Split breaks the path into a list of parts, and List.Last grabs the last one, which is the file name.

Things to keep in mind with List.Last

  • defaultValue only fires for an empty list. A list whose last item is null still returns null, not the default. The default is purely the empty-list fallback.
  • “Last” means by position, not by value. It returns whatever sits at the end of the list, not the largest or the most recent. If you want the biggest value, sort the list first or use List.Max.
  • It is the cheap alternative to positional access. Reaching the last item with myList{...} needs List.Count(myList)-1 and throws on an empty list. List.Last handles the empty case for you with null or your default.
  • Pair it with functions that produce lists. It works well on top of Text.Split (last segment of a path or string) and Table.Column (last value of a column), as in Examples 4 and 5. The same goes for any list you build with List.Transform.

Performance and query folding

List.Last does not fold to a database source, so the query runs locally. On a large foldable source, reading the last row this way pulls the whole column into memory first, which is slow. When the table is big, sort the source the other way and take the first row, or use Table.LastN.

Common questions about List.Last

What is the difference between List.First and List.Last?

List.First returns the item at the start of the list and List.Last returns the item at the end. Both take the same optional defaultValue for an empty list.

How is List.Last different from indexing with myList{...}?

myList{2} grabs a specific position by number and errors if that position does not exist. List.Last always targets the end and returns null or your default on an empty list, so you do not have to calculate List.Count(myList)-1 yourself.

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.