List.Transform Function in Power Query

The List.Transform function performs the transform function on each item in the list and returns the result as the new list.

Syntax

List.Transform(list as list, transform as function) as list

The function has the following parameters:
1. list: The list we want to transform. This is the input list containing the elements we wish to modify.
2. transform: A function that defines the transformation to be applied to each element in the list. This function takes a single argument (the current list item) and returns the transformed value.

Example: If we want to generate a list of Months on the fly, we can use the following M code.

Power Query M

let
  Source = List.Transform({1 .. 12}, each Date.MonthName(#date(2024, _, 1)))
in
  Source  

The output of the above code is shown below:

List.Transform function in Power Query

Example: Add 1 in each value in the list.

Power Query M

let
  Source = List.Transform({1, 2}, each _ + 1)
in
  Source  

The output of the above code is shown below:

List.Transform function in Power Query

Example:

Power Query M

let
  Source = {"Ashish", "Esha", "Alia", "Diksha", "Katrina"},
  transformed = List.Transform(Source, (a)=> if Text.StartsWith(a, "A") then "yes" else "no")
in
  transformed   

The output of the above code is shown below:

List.Transform function in Power Query