Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query List.Transform: Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

List.Transform applies a custom function to every item in a list and returns a new list with the transformed values. You need Power Query (available in Excel and Power BI) and a list to work with. The steps below show how to use it in the Power Query Editor, from creating a simple list to handling errors and nested lists.

What You'll Need

  • Power Query Editor open in Excel (Data > Get Data > Launch Power Query Editor) or Power BI Desktop (Home > Transform data).
  • A list to transform. You can create one from scratch or use an existing column that contains lists.
  • Basic familiarity with the Power Query formula language (M). No advanced coding required.

Step-by-Step

  1. Open the Power Query Editor. In Excel, go to the Data tab and click Get Data > Launch Power Query Editor. In Power BI Desktop, click Transform data on the Home ribbon. Menu labels may vary slightly by version or region.
  2. Create or load a list. To start from scratch, click Enter Data and type values into a single column, then click OK. Alternatively, load a table and later convert a column to a list. For a quick test, use the formula bar: type = {1, 2, 3, 4, 5} and press Enter to create a list of numbers.
  3. Add a step to transform the list. With your list selected (or by adding a new step), open the formula bar (View > Formula Bar) and enter a formula like = List.Transform({1,2,3,4,5}, each _ * 2). This multiplies each item by 2. The each _ shorthand refers to the current item. Press Enter to apply.
  4. Use a named function instead of each _. For more complex logic, define a function. For example, = List.Transform({1,2,3}, (x) => x + 10) adds 10 to each item. You can also call built-in functions: = List.Transform({"a","b"}, Text.Upper) converts each string to uppercase.
  5. Apply to a column of lists. If you have a table column where each cell contains a list, you can transform each list. For example, add a custom column with formula = List.Transform([ColumnName], each _ * 2). This returns a new list for each row.
  6. Expand or inspect the result. After transforming, you can click the expand icon next to the list column header to extract values, or use List.Sum, List.Count, etc., to aggregate. To see the result, click on any cell containing a list to preview its contents at the bottom of the window.
  7. Handle errors. If your transformation might fail (e.g., text to number), wrap the function in try ... otherwise. Example: = List.Transform({1,"a",3}, each try Number.From(_) otherwise null). This replaces errors with null.
  8. Close and load. When finished, click Close & Load (Excel) or Close & Apply (Power BI) to load the transformed data into your worksheet or data model.

Common Mistakes

  • Forgetting the each keyword or using _ incorrectly. The underscore represents the current item; without each, the formula is not evaluated per item.
  • Mismatched data types. Applying arithmetic to text items causes errors. Use try ... otherwise or convert types first.
  • Assuming List.Transform modifies the original list. It returns a new list; the original remains unchanged.
  • Using List.Transform on a table column directly without converting to a list. If the column is not a list, you'll get an error. Use Table.ToList or reference the column as a list.
  • Ignoring nested lists. If items are themselves lists, you may need List.TransformMany or a nested List.Transform.

Tips

  • Use the formula bar to write and edit M code directly; it gives you full control and is often faster than the UI.
  • Test your transformation on a small list first to verify logic before applying to large datasets.
  • Combine List.Transform with other list functions like List.Select or List.Accumulate for powerful data shaping.
  • Name your steps clearly in the Applied Steps pane to keep your query readable.
  • Remember that each _ is shorthand for (x) => x; you can use explicit parameter names for clarity.

Troubleshooting

  • Error: "We cannot apply operator & to types Text and Number" – This means you're mixing types. Check the items in your list and ensure they are all the same type, or use try ... otherwise.
  • List.Transform returns a list of errors – Inspect the input list; some items may be null or of the wrong type. Use List.Transform with a function that handles errors, like each try ... otherwise ....
  • Nothing happens when you enter the formula – Make sure you're editing the correct step and that the formula is syntactically correct. Check for missing commas or parentheses.
  • The result is a list of lists – If your function returns a list for each item, you'll get a nested list. Use List.Combine to flatten if needed.
  • Performance is slow on large lists – List.Transform is efficient, but complex functions per item can slow down. Consider filtering or aggregating before transforming.

Frequently Asked Questions

What is the difference between List.Transform and List.TransformMany?

List.Transform applies a function to each item and returns one item per input. List.TransformMany can return multiple items per input and flattens the result.

Can I use List.Transform on a table column?

Yes, if the column contains lists. You can reference the column as a list, e.g., List.Transform(Table[Column], each _ * 2). If the column contains scalar values, convert it to a list first with Table.ToList or use a custom column.

How do I handle null values in List.Transform?

Use try ... otherwise or check for null with if _ = null then null else ... inside your function.

Does List.Transform change the original list?

No, it returns a new list. The original list remains unchanged.

Can I use List.Transform with a custom function defined in Power Query?

Yes, you can define a function using let and then pass it to List.Transform. For example: let MyFunc = (x) => x * 2 in List.Transform({1,2,3}, MyFunc).

What happens if the list is empty?

List.Transform returns an empty list. No error occurs.