The List.Last function in Power Query gives you the last item in a list. If the list is empty, it returns null, or a default value you choose.
You can turn a column, a filtered set of rows, the words in a text, or even a table’s column headers into a list. That makes List.Last useful for things like getting the closing balance, the most recent match, or the latest non-blank value.
Follow along with the example file
List.Last Function Examples.xlsx
List.Last Function Syntax
List.Last(list as list, optional defaultValue as any) as any
- list – the list you want the last 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 last 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.Last 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.Last Function
Use this function when you need to:
- Get the last value in a column, like a closing balance or the latest reading
- Find the last row that meets a condition, like the most recent shipment that was delayed
- Pick the last non-blank value from a few columns in the same row
- Get the latest value for each group (each product, customer, or project) with Table.Group
- Get the last word in a text, like the last name from a full name
- Refer to the last column of a table without typing its name
Example 1: Get the Last Item in a List
Let’s start with the simplest use. Suppose you have a list of software versions in release order, and you want the latest one.
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.Last({"v1.0","v1.4","v2.0","v2.3"})
Result: v2.3

Here, the curly brackets create a list of four text values, and List.Last returns the one at the end, which is “v2.3”.
You’ll rarely type the list yourself like this. But it shows the one thing List.Last 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 Last Value in a Column
This is the one you’ll probably use the most. Below is a month-end balance log in an Excel Table named AccountBalance, and I want the closing balance (the balance in the last row).

In the code below, the Source line uses the Excel.CurrentWorkbook function to pull the AccountBalance 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 “AccountBalance”.
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="AccountBalance"]}[Content],
ClosingBalance = List.Last(Source[Balance])
in
ClosingBalance
Result: 5088.95

Here, Source is the name of the first step, and it holds the AccountBalance table. Source[Balance] takes the Balance column and returns it as a list, and List.Last returns its last item, 5088.95.
List.Last goes by position, not by size. The highest balance in this log is 5410.35 (August), but List.Last still returns 5088.95 because that’s the value in the last 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 last one, use the List.Max function instead.
Example 3: Return a Default Value When the List Is Empty
Before we use List.Last on filtered data, it helps to see what happens when there’s nothing in the list. This example puts the same empty list in a small table twice, once without a default value and once with one.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = #table({"Formula","Result"},{
{"List.Last({})",List.Last({})},
{"List.Last({},""None yet"")",List.Last({},"None yet")}})
in
Source
Result: A small table where the first row shows null and the second row shows None yet

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 ""None yet"" are only there because that formula is stored as text, and the table shows it as List.Last({},"None yet"). In your own formula, type it with one pair of double quotes: List.Last({},"None yet").
{} is an empty list, so with no second argument, List.Last returns null for it. With “None yet” as the second argument, it returns “None yet” 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.
You may also see x{List.Count(x)-1} used to get the last item of a list named x. A number in curly brackets after a list picks the item at that position, counting from 0, so the last item is at the count minus 1.
On an empty list, that position works out to -1, so you get the error “The index cannot be negative.” List.Last returns null or your default instead.
Example 4: Find the Last Row That Meets a Condition
Now let’s combine List.Last with a filter. Below is a shipment log in a table named ShipmentLog, in date order, and I want the Order ID of the most recent shipment that was delayed.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="ShipmentLog"]}[Content],
LastDelayed = List.Last(Table.SelectRows(Source,each [Status]="Delayed")[Order ID],"No delays")
in
LastDelayed
Result: SO-1046

Here, the Table.SelectRows function keeps only the rows where Status is “Delayed”. That’s SO-1042, SO-1045, and SO-1046.
[Order ID] at the end takes the Order ID column from those rows as a list ({“SO-1042”, “SO-1045”, “SO-1046”}), and List.Last returns the last one, SO-1046.
Since the log is in date order, the last delayed row is also the most recent one. If no shipment had been delayed, the list would be empty, and the formula would return “No delays” (the second argument) instead of null.
Follow along with the example file
List.Last Function Examples.xlsx
Example 5: Get the Last Non-Blank Value in a Row
This next one comes up a lot with scores and readings. Below is a table named TestScores with up to four test scores for each student, and I want a Latest Score column with each student’s most recent score.

Some students missed a test, and their 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="TestScores"]}[Content],
#"Added Latest Score" = Table.AddColumn(Source,"Latest Score",each List.Last(List.RemoveNulls({[Test 1],[Test 2],[Test 3],[Test 4]})),type number)
in
#"Added Latest Score"
Result: A new Latest Score column (85, 70, 90, 79, and 77)

Here, the Table.AddColumn function adds a Latest Score column and runs the formula after each once for every row.
For each row, {[Test 1],[Test 2],[Test 3],[Test 4]} builds a list of that student’s four scores. The List.RemoveNulls function then drops the nulls, and List.Last takes the last score that’s left.
For example, Jacqueline Campbell has scores for Test 1 and Test 3 only. Her list becomes {74, 79} after the nulls are removed, so List.Last returns 79.
With only four fixed columns, you could also write [Test 4] ?? [Test 3] ?? [Test 2] ?? [Test 1], where the ?? operator moves on to the next value whenever the one on its left is null.
The List.Last version is easier to extend when you have more columns to check.
Important: Don’t skip List.RemoveNulls. List.Last returns the last item even when it’s null, so List.Last({[Test 1],[Test 2],[Test 3],[Test 4]}) would give Lawrence Moore, Holly Richardson, and Jacqueline Campbell a blank (null) Latest Score.
Example 6: Get the Latest Value for Each Group
This is a common use of List.Last with grouping. Below is a price history in a table named PriceHistory, in date order, and I want each product’s current price (its most recent price) in a Current Price column.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="PriceHistory"]}[Content],
#"Grouped Rows" = Table.Group(Source,{"Product"},{{"Current Price",each List.Last([Price]),type number}})
in
#"Grouped Rows"
Result: One row per product with its Current Price (Desk Lamp 36.99, Office Chair 179.99, and Monitor Stand 48.99)

Here, the Table.Group function groups the rows by Product. For each product, [Price] is the list of prices from that product’s rows only, and List.Last returns the last one.
For example, Desk Lamp has three rows with 34.99, 32.49, and 36.99, so its current price is 36.99.
Important: This works only because the price history is in date order, so each product’s last row is its latest price. If your data isn’t sorted, sort it by date first, or you’ll get the wrong price.
If you’d rather not depend on the row order at all, you can use Table.Max(_,"Effective Date")[Price] in place of List.Last([Price]).
Inside Table.Group, _ stands for the current product’s rows, so Table.Max picks the row with the latest Effective Date (wherever it sits) and [Price] reads its price.
If you need the last few values for each group instead of just one, the List.LastN function does that.
Example 7: Get the Last Word in a Text
This one combines List.Last with a text function. Below is a member list in a table named Members with each person’s full name, and I want their last name in a Last Name column.

Some names have a middle name, so I can’t just take the second word. Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="Members"]}[Content],
#"Added Last Name" = Table.AddColumn(Source,"Last Name",each List.Last(Text.Split([Full Name]," ")),type text)
in
#"Added Last Name"
Result: A new Last Name column (Lawrence, Barnes, Adams, Reed, and Hall)

Here, the Text.Split function splits each full name at the spaces and returns the words as a list. For “Douglas Evan Adams”, that’s {“Douglas”, “Evan”, “Adams”}.
List.Last then returns the last word in that list, which is the last name. It works the same whether a name has two words or three.
If a name has an extra space at the end, the last item in the list is empty text, so clean the column with the Text.Trim function first.
You can also get the same result with the Text.AfterDelimiter function, Text.AfterDelimiter([Full Name]," ",{0,RelativePosition.FromEnd}), which returns the text after the last space.
Example 8: Keep Only the Latest Month Column
This last one uses List.Last on column names. Below is a table named MonthlyUnits with units sold per product, where a new month column gets added to the right every month, and I want only the Product column and the latest month.

If you select the columns by clicking them, Power Query writes “Apr” into the step. Next month, when May is added, the query still returns April, because it doesn’t know Apr is no longer the latest.
Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="MonthlyUnits"]}[Content],
#"Latest Month" = Table.SelectColumns(Source,{"Product",List.Last(Table.ColumnNames(Source))})
in
#"Latest Month"
Result: A table with the Product and Apr columns

Here, the Table.ColumnNames function returns the table’s column headers as a list ({“Product”, “Jan”, “Feb”, “Mar”, “Apr”}), and List.Last takes the last one, “Apr”.
The Table.SelectColumns function then keeps Product and that column. Since the code never types “Apr”, it picks up May automatically once you add it and refresh.
Other Excel Articles You May Also Like:
- List.Average
- Splitter.SplitTextByEachDelimiter Function in Power Query M
- List.First – Use List.First in Power Query M to get the first item in a list.
- List.Reverse – Use List.Reverse in Power Query M to reverse the order of a list.
- Table.Max – Use Table.Max in Power Query M to get the row with the largest value.
- Table.ReverseRows – Use Table.ReverseRows in Power Query M to flip row order.
- List.FirstN – Use List.FirstN in Power Query M to get the first items of a list.
- List.Min – Use List.Min in Power Query M to find the smallest value.