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

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