List.Reverse

Updated on

List.Reverse is a Power Query M function that reverses the order of values in a list. The function returns a modified list with the values in reversed order.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

List.Reverse( list as list ) as list

Description

At its heart, the List.Reverse function does precisely what its name suggests: it flips the list. It takes the first item and places it last, takes the second and places it second to last, and continues this pattern for the entire list.

Examples

Here are a few practical applications of the List.Reverse function.

Reversing Numeric Lists

Consider a scenario where you possess a list of the first five consecutive numbers:

List.Reverse( {1, 2, 3, 4, 5} )  // Output: { 5, 4, 3, 2, 1 }

This can be especially useful when arranging data in descending order without the need for a separate sorting function.

Flipping textual Lists

Lists don’t just contain numbers. For textual data, like a list of fruits in alphabetical order, List.Reverse can be applied to change the sequence:

List.Reverse( {"Apple", "Pear", "Cherry", "Date"} )  // Output: {"Date", "Cherry", "Pear", "Apple"}

Handling Nested Lists

When working with more complex, nested lists (lists within lists), List.Reverse works just as effective:

List.Reverse( {{1, 2}, {3, 4}, {5, 6}} )  // Output: {{5, 6}, {3, 4}, {1, 2}}

Note: The function will reverse the order of the sub-lists but won’t affect the order of items within those sub-lists.

The List.Reverse function seamlessly reverses lists, whether simple numbers, text or other structured values. Understanding functions like List.Reverse ensures that you’re always prepared to shape your data exactly the way you want it.

Learn more about List.Reverse in the following articles:

Other functions related to List.Reverse are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/list-reverse