List.Transform
Applies a function to every item in a list and returns a new list of the results.
List.Transform(list, transform)Returns: A list of the same length, with each item replaced by the function's result.
What it does
List.Transform takes each item in a list, runs your function on it, and collects the results in order. Use it when you want the same change applied to every value, such as adding sales tax to a list of amounts or converting text to numbers before you total them. The original list is not changed.
Syntax and arguments
list: the list to work through. A table column is a list, for exampleInvoices[amount].transform: a function that takes one item and returns the new value.eachis the shortest way to write it. Insideeach,_is the current item.
Example
A controller wants invoice amounts with 8 percent sales tax added, as a check on a customer statement. The amounts are already in a list.
let
Amounts = {100, 250, 1200},
WithTax = List.Transform(Amounts, each _ * 1.08),
Rounded = List.Transform(WithTax, each Number.Round(_, 2))
in
Rounded
The first step multiplies every amount by 1.08. The second rounds each result to cents. The answer is a new list with the same three items, each one 8 percent higher. For a whole table, use Table.TransformColumns instead, which works on a column of rows.
Example: a second, different use
Turning text from a CSV into numbers before any totals. List.Transform({"120.50", "80"}, Number.FromText) returns the numbers 120.5 and 80.
Things to watch
- List.Transform keeps every item, including nulls. A null passed to
_ * 1.08returns null, so remove blanks first with List.RemoveNulls if you do not want them. - The output has the same number of items as the input. To drop items, use List.Select.
- Inside
each,_is the current item. If you need a column from a row, you are working with a table, not a list: use Table.TransformColumns or Table.AddColumn. - Use Number.Round for money. Repeated multiplication in binary floating point can leave tiny differences.
In business terms
Finance teams use List.Transform to apply rates, convert currencies, add tax or fees, or clean text such as stripping a currency symbol before a total. It is the step that comes before a sum, a check or a lookup.