The Table.ReverseRows function in Power Query flips the order of the rows in a table, so the last row becomes the first and the first row becomes the last.
It’s handy when your data is stored oldest to newest and you want the latest entries on top.
I’ll show you six examples below, including how it’s different from sorting, how to get the last few rows newest first, how to keep the last duplicate, and how to reverse rows inside each group.
Follow along with the example file
Table.ReverseRows Function Examples.xlsx
Table.ReverseRows Function Syntax
= Table.ReverseRows(table as table) as table
- table – the table whose rows you want to reverse. This is usually the previous step in your query, which is named
Sourcein most of the examples below.
What it returns – the same table with its rows in the opposite order. The columns and the values in each row don’t change, only the position of the rows.
I’ve tested the Table.ReverseRows function in Power Query in Excel for Microsoft 365. It’s also part of the Power Query M language that Power BI uses.
When to Use the Table.ReverseRows Function
Use this function when you need to:
- Show the latest entries at the top of a log that adds new rows at the bottom
- Get the last few rows of a table with the newest one first
- Remove duplicates but keep the last entry instead of the first one
- Flip a grid upside down, together with its columns
- Reverse the order of the rows within each group of a table
Example 1: Show the Latest Entries at the Top
Let’s start with the most common use, where new rows get added at the bottom of a table and you want the newest one first.
Below is an Excel table named ReleaseNotes with the version history of an invoicing app, from the first release at the top to the latest one at the bottom. I want to reverse it so the latest version is at the top.

To follow along, select any cell in the table and go to Data > From Table/Range to open it in the Power Query Editor. If Power Query adds a Changed Type step, use #"Changed Type" in place of Source in the formula below.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.ReverseRows(Source)
Result: the six versions in reverse order, from v2.1 at the top to v1.0 at the bottom

Here, Table.ReverseRows takes the table in the Source step and turns it upside down. The column names stay at the top, and each row keeps its own values, so v2.1 still goes with “Added multi-currency support”.
You can also do this from the ribbon. In the Power Query Editor, go to the Transform tab and click Reverse Rows.
Example 2: Reversing the Rows Is Not the Same as Sorting
Table.ReverseRows doesn’t look at any values in the table. It only flips the position of the rows, which matters when your rows have dates.
Below is an Excel table named RepairLog with the machine repairs reported in a warehouse, and I want to show the newest repair first.
The rows are mostly in date order, but the 10/6/2026 flat tire was entered late, after the 10/15/2026 entry.

Create a blank query (Data > Get Data > From Other Sources > Blank Query). In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code.
The Source line reads the table by its name, so if your table has a different name, change RepairLog to that name. The same goes for the table names in the later examples.
let
Source = Excel.CurrentWorkbook(){[Name="RepairLog"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Logged On",type date}}),
#"Reversed Rows" = Table.ReverseRows(#"Changed Type")
in
#"Reversed Rows"
Result: the six repairs in reverse order, with 10/6/2026 showing up above 10/15/2026

Here, the Changed Type step sets the Logged On column to the date type, so it shows dates without a time. Then Table.ReverseRows flips the rows.
The newest repair (10/27/2026) is now at the top, but the late entry is still out of place. Its row was fourth from the top, so after the flip it’s third from the top, above the 10/15/2026 and 10/9/2026 repairs.
When you want the rows in date order, sort by the date column instead. Create another blank query and use this code, which uses the Table.Sort function:
let
Source = Excel.CurrentWorkbook(){[Name="RepairLog"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Logged On",type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Logged On",Order.Descending}})
in
#"Sorted Rows"
Result: the six repairs from 10/27/2026 down to 10/2/2026, with 10/6/2026 in its right place

Here, Table.Sort orders the rows by the Logged On dates, from the newest to the oldest, so it doesn’t matter in which order the rows were entered.
So use Table.Sort when the table has a column that holds the order you want (like a date). Use Table.ReverseRows when the row order itself is the order you care about, like a log where each new row is added at the bottom.
Example 3: Get the Last Few Rows, Newest First
A dashboard or a summary often shows only the latest few entries, with the newest one on top.
Below is an Excel table named CustomerReviews with product reviews in the order they came in, so the latest review is at the bottom. I want the three latest reviews, with the newest one first.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="CustomerReviews"]}[Content],
#"Kept Last Rows" = Table.LastN(Source,3),
#"Reversed Rows" = Table.ReverseRows(#"Kept Last Rows")
in
#"Reversed Rows"
Result: three reviews, from Ian Sullivan at the top to Ellen Reynolds at the bottom

Here, the Kept Last Rows step uses the Table.LastN function to keep the last three rows. Table.LastN keeps them in their original order, so Ellen Reynolds is still first and Ian Sullivan is last.
The Reversed Rows step then flips those three rows, which puts the latest review (Ian Sullivan) at the top.
To get a different number of reviews, change the 3 in the Table.LastN step.
Follow along with the example file
Table.ReverseRows Function Examples.xlsx
Example 4: Remove Duplicates but Keep the Last Entry
When you remove duplicates from an Excel table like this one, Power Query keeps the first row it finds for each value. That’s a problem when the last row is the one you need, like the latest update in a log.
Below is an Excel table named OrderUpdates where a new row is added every time an order’s status changes, so the latest status of each order is its lowest row. I want one row per order, with its latest status.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="OrderUpdates"]}[Content],
#"Reversed Rows" = Table.ReverseRows(Source),
#"Removed Duplicates" = Table.Distinct(#"Reversed Rows",{"Order ID"})
in
#"Removed Duplicates"
Result: four rows, one per order: ORD-1044 Placed, ORD-1042 Delivered, ORD-1043 Cancelled, and ORD-1041 Shipped

Here, Table.ReverseRows first puts the latest updates at the top. Then the Table.Distinct function removes the rows with a repeated Order ID, and since it keeps the first row it finds, that’s now the latest update of each order.
The Updated By column comes along too, because Table.Distinct keeps or removes whole rows. The orders show up in the reversed order, so the order that was updated last (ORD-1044) is at the top.
Important: Microsoft’s documentation doesn’t say which duplicate Table.Distinct keeps. It keeps the first one with an Excel table like this, but check the result if your data comes from another source, like a database.
Example 5: Reverse the Order of Rows and Columns
Table.ReverseRows only changes the order of the rows. If you need to flip the columns too, you can add one more step.
Below is an Excel table named SeatingChart with a classroom seating chart, drawn as the teacher sees the class from the front. I want to flip it to show the room as the students see it, with the rows and the seats reversed.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="SeatingChart"]}[Content],
#"Reversed Rows" = Table.ReverseRows(Source),
#"Reordered Columns" = Table.ReorderColumns(#"Reversed Rows",List.Reverse(Table.ColumnNames(Source)))
in
#"Reordered Columns"
Result: the columns go from Seat 4 to Seat 1, and the first row is Catherine, Addison, Gerald, and Roger

Here, the Reversed Rows step moves the last row of the chart to the top. Then the Reordered Columns step reverses the columns, and each header moves with its column, so Seat 4 is now first.
The Table.ColumnNames function gives the list of column names (Seat 1 to Seat 4), and the List.Reverse function flips that list. The Table.ReorderColumns function then puts the columns in that new order.
So Logan, who was in the top-left corner of the chart, ends up in the bottom-right corner.
Note that Table.ReverseRows works only on tables. For a list, like the list of column names here, you need the List.Reverse function.
Example 6: Reverse the Rows Within Each Group
Sometimes you don’t want to flip the whole table, only the rows that belong to each person or item.
Below is an Excel table named QuizAttempts with the scores of each quiz attempt, in the order the students took them. I want each student’s last two attempts, with the latest one first, while keeping each student’s rows together.

Create a new blank query, open the Advanced Editor, and use this code:
let
Source = Excel.CurrentWorkbook(){[Name="QuizAttempts"]}[Content],
#"Grouped Rows" = Table.Group(Source,{"Student"},{{"Recent",each Table.FirstN(Table.ReverseRows(_),2),type table}}),
#"Combined Tables" = Table.Combine(#"Grouped Rows"[Recent])
in
#"Combined Tables"
Result: eight rows, two per student, starting with Joel 78 and Joel 70

Here, the Table.Group function makes a small table of attempts for each student, where the underscore _ stands for that table. Table.ReverseRows flips it so the latest attempt is on top, and the Table.FirstN function keeps the first two rows.
Each student’s two-row table goes into a new column named Recent.
In the next step, #"Grouped Rows"[Recent] takes that column of small tables, and the Table.Combine function stacks them into one table. The students stay in the order they first show up in the table (Joel, Lori, Anthony, and Rebecca).
Table.ReverseRows is the right tool here because the table has no date or attempt number. The position of each row is the only thing that tells you which attempt came last.
Other Excel Articles You May Also Like:
- Table.RemoveRows – Use Table.RemoveRows in Power Query M to delete rows by position.
- Table.Max – Use Table.Max in Power Query M to get the row with the largest value.
- List.Sort – Use List.Sort in Power Query M to sort a list.
- Table.Buffer – Guide to the Table.Buffer function in Power Query M.
- Table.AddRankColumn – Use Table.AddRankColumn in Power Query M to rank rows.
- Table.Skip – Use Table.Skip in Power Query M to remove rows from the top of a table.
- Table.Unpivot – Use Table.Unpivot in Power Query M to turn columns into rows.
- Table.Pivot – Use Table.Pivot in Power Query M to turn row values into columns.