A
- AccessControlEntry.ConditionToIdentities
- Access.Database
- ActiveDirectory.Domains
- AdobeAnalytics.Cubes
- AdoDotNet.DataSource
- AdoDotNet.Query
- AnalysisServices.Database
- AnalysisServices.Databases
- AzureStorage.BlobContents
- AzureStorage.Blobs
- AzureStorage.DataLake
- AzureStorage.DataLakeContents
- AzureStorage.Tables
B
- BinaryFormat.Binary
- BinaryFormat.Byte
- BinaryFormat.ByteOrder
- BinaryFormat.Choice
- BinaryFormat.Decimal
- BinaryFormat.Double
- BinaryFormat.Group
- BinaryFormat.Length
- BinaryFormat.List
- BinaryFormat.Null
- BinaryFormat.Record
- BinaryFormat.SignedInteger16
- BinaryFormat.SignedInteger32
- BinaryFormat.SignedInteger64
- BinaryFormat.Single
- BinaryFormat.Text
- BinaryFormat.Transform
- BinaryFormat.UnsignedInteger16
- BinaryFormat.UnsignedInteger32
- BinaryFormat.UnsignedInteger64
- BinaryFormat.7BitEncodedSignedInteger
- BinaryFormat.7BitEncodedUnsignedInteger
- Binary data
- Binary.ApproximateLength
- Binary.Buffer
- Binary.Combine
- Binary.Compress
- Binary.Decompress
- Binary.From
- Binary.FromList
- Binary.FromText
- Binary.InferContentType
- Binary.Length
- Binary.Range
- Binary.Split
- Binary.ToList
- Binary.ToText
- Binary.View
- Binary.ViewError
- Binary.ViewFunction
- Byte.From
C
- Cdm.Contents
- Character.FromNumber
- Character.ToNumber
- Combiner.CombineTextByDelimiter
- Combiner.CombineTextByEachDelimiter
- Combiner.CombineTextByLengths
- Combiner.CombineTextByPositions
- Combiner.CombineTextByRanges
- Comparer.FromCulture
- Comparer.Ordinal
- Comparer.OrdinalIgnoreCase
- Controlling byte order
- Csv.Document
- Cube.AddAndExpandDimensionColumn
- Cube.AddMeasureColumn
- Cube.ApplyParameter
- Cube.AttributeMemberId
- Cube.AttributeMemberProperty
- Cube.CollapseAndRemoveColumns
- Cube.Dimensions
- Cube.DisplayFolders
- Cube.MeasureProperties
- Cube.MeasureProperty
- Cube.Measures
- Cube.Parameters
- Cube.Properties
- Cube.PropertyKey
- Cube.ReplaceDimensions
- Cube.Transform
- Currency.From
D
- DateTime.AddZone
- DateTime.Date
- DateTime.FixedLocalNow
- DateTime.From
- DateTime.FromFileTime
- DateTime.FromText
- DateTime.IsInCurrentHour
- DateTime.IsInCurrentMinute
- DateTime.IsInCurrentSecond
- DateTime.IsInNextHour
- DateTime.IsInNextMinute
- DateTime.IsInNextNHours
- DateTime.IsInNextNMinutes
- DateTime.IsInNextNSeconds
- DateTime.IsInNextSecond
- DateTime.IsInPreviousHour
- DateTime.IsInPreviousMinute
- DateTime.IsInPreviousNHours
- DateTime.IsInPreviousNMinutes
- DateTime.IsInPreviousNSeconds
- DateTime.IsInPreviousSecond
- DateTime.LocalNow
- DateTime.Time
- DateTime.ToRecord
- DateTime.ToText
- Date.AddDays
- Date.AddMonths
- Date.AddQuarters
- Date.AddWeeks
- Date.AddYears
- Date.Day
- Date.DayOfWeek
- Date.DayOfWeekName
- Date.DayOfYear
- Date.DaysInMonth
- Date.EndOfDay
- Date.EndOfMonth
- Date.EndOfQuarter
- Date.EndOfWeek
- Date.EndOfYear
- Date.From
- Date.FromText
- Date.IsInCurrentDay
- Date.IsInCurrentMonth
- Date.IsInCurrentQuarter
- Date.IsInCurrentWeek
- Date.IsInCurrentYear
- Date.IsInNextDay
- Date.IsInNextMonth
- Date.IsInNextNDays
- Date.IsInNextNMonths
- Date.IsInNextNQuarters
- Date.IsInNextNWeeks
- Date.IsInNextNYears
- Date.IsInNextQuarter
- Date.IsInNextWeek
- Date.IsInNextYear
- Date.IsInPreviousDay
- Date.IsInPreviousMonth
- Date.IsInPreviousNDays
- Date.IsInPreviousNMonths
- Date.IsInPreviousNQuarters
- Date.IsInPreviousNWeeks
- Date.IsInPreviousNYears
- Date.IsInPreviousQuarter
- Date.IsInPreviousWeek
- Date.IsInPreviousYear
- Date.IsInYearToDate
- Date.IsLeapYear
- Date.Month
- Date.MonthName
- Date.QuarterOfYear
- Date.StartOfDay
- Date.StartOfMonth
- Date.StartOfQuarter
- Date.StartOfWeek
- Date.StartOfYear
- Date.ToRecord
- Date.ToText
- Date.WeekOfMonth
- Date.WeekOfYear
- Date.Year
- DB2.Database
- Decimal.From
- Diagnostics.ActivityId
- Diagnostics.Trace
- DirectQueryCapabilities.From
- Double.From
- Duration.Days
- Duration.From
- Duration.FromText
- Duration.Hours
- Duration.Minutes
- Duration.Seconds
- Duration.ToRecord
- Duration.TotalDays
- Duration.TotalHours
- Duration.TotalMinutes
- Duration.TotalSeconds
- Duration.ToText
E
F
G
H
I
L
- Lines.FromBinary
- Lines.FromText
- Lines.ToBinary
- Lines.ToText
- List.Accumulate
- List.AllTrue
- List.Alternate
- List.AnyTrue
- List.Average
- List.Buffer
- List.Combine
- List.ConformToPageReader
- List.Contains
- List.ContainsAll
- List.ContainsAny
- List.Count
- List.Covariance
- List.Dates
- List.DateTimes
- List.DateTimeZones
- List.Difference
- List.Distinct
- List.Durations
- List.FindText
- List.First
- List.FirstN
- List.Generate
- List.InsertRange
- List.Intersect
- List.IsDistinct
- List.IsEmpty
- List.Last
- List.LastN
- List.MatchesAll
- List.MatchesAny
- List.Max
- List.MaxN
- List.Median
- List.Min
- List.MinN
- List.Mode
- List.Modes
- List.NonNullCount
- List.Numbers
- List.Percentile
- List.PositionOf
- List.PositionOfAny
- List.Positions
- List.Product
- List.Random
- List.Range
- List.RemoveFirstN
- List.RemoveItems
- List.RemoveLastN
- List.RemoveMatchingItems
- List.RemoveNulls
- List.RemoveRange
- List.Repeat
- List.ReplaceMatchingItems
- List.ReplaceRange
- List.ReplaceValue
- List.Reverse
- List.Select
- List.Single
- List.SingleOrDefault
- List.Skip
- List.Sort
- List.Split
- List.StandardDeviation
- List.Sum
- List.Times
- List.Transform
- List.TransformMany
- List.Union
- List.Zip
- Logical.From
- Logical.FromText
What is the List.Reverse function in Power Query?
The List.Reverse function is used to reverse the order of items in a list. It takes a list as its input and returns a new list with the items in reverse order. This function is commonly used to sort data in descending order or to reverse the order of columns in a table.
The M code behind the List.Reverse function
The M code behind the List.Reverse function is relatively simple. The function takes a list as its input and uses the List.Buffer function to create a new list with the same items. The List.Buffer function is used to improve performance by storing the list in memory as a buffer.
After creating the new list, the M code uses a for loop to iterate through each item in reverse order. The loop starts with the last item in the list and moves backwards to the first item. The loop uses the List.InsertRange function to insert each item into the new list in reverse order.
The M code for the List.Reverse function looks like this:
(List as list) =>
let
Source = List.Buffer(List),
Result = List.Generate(
() => List.Count(Source) – 1,
each _ >= 0,
each _ – 1,
each Source{_}
)
in
Result
The code creates a new list called "Source" using the List.Buffer function. The "Result" variable uses the List.Generate function to loop through each item in the source list in reverse order. The List.Count function is used to determine the number of items in the list, and the "each _ >= 0" expression is used to iterate through each item in reverse order.
Examples of using the List.Reverse function
Let's look at some examples of how the List.Reverse function can be used in Power Query.
Sorting data in descending order
One common use of the List.Reverse function is to sort data in descending order. For example, let's say we have a list of sales data that we want to sort by the total sales amount. We can use the List.Sort function to sort the data in ascending order and then use the List.Reverse function to reverse the order and get the data in descending order.
The M code for this operation looks like this:
let
Source = Table.FromRows({{1, “Product A”, 100}, {2, “Product B”, 200}, {3, “Product C”, 150}}, {“ID”, “Product”, “Sales”}),
Sorted = List.Sort(Table.Column(Source, “Sales”), Order.Ascending),
Reversed = List.Reverse(Sorted),
Result = Table.FromColumns({Sorted}, {“Sorted Sales”})
in
Result
The code creates a new table called "Source" with three columns: ID, Product, and Sales. The List.Sort function is used to sort the "Sales" column in ascending order. The List.Reverse function is then used to reverse the order of the sorted list. Finally, the sorted and reversed list is converted into a new table with a single column called "Sorted Sales".
Reversing the order of columns in a table
Another use of the List.Reverse function is to reverse the order of columns in a table. For example, let's say we have a table with three columns: Name, Age, and Gender. We can use the List.Reverse function to reverse the order of columns and get a new table with the columns in the order Gender, Age, Name.
The M code for this operation looks like this:
let
Source = Table.FromRows({{“John”, 25, “Male”}, {“Jane”, 30, “Female”}, {“Bob”, 40, “Male”}}, {“Name”, “Age”, “Gender”}),
Reversed = Table.FromColumns(List.Reverse(Table.ToColumns(Source)), {“Gender”, “Age”, “Name”})
in
Reversed
The code creates a new table called "Source" with three columns: Name, Age, and Gender. The List.Reverse function is used to reverse the order of the columns and create a new table called "Reversed".
The List.Reverse function is a powerful tool in Power Query that enables users to reverse the order of items in a list. The M code behind the function is relatively simple and uses functions like List.Buffer, List.Generate, and List.InsertRange to create a new list with the items in reverse order. The function can be used for a variety of tasks like sorting data in descending order and reversing the order of columns in a table.