Smart Systems for Home

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

Power Query Each: How to Transform Lists Step by Step

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips

Power Query's each keyword is a shorthand for writing a function that operates on every item in a list, table, or record. It lets you apply a transformation to each row or element without manually defining a named function. You use it most often inside functions like Table.AddColumn, List.Transform, or Table.TransformColumns to create custom calculations. To use it, you need Power Query available in Excel or Power BI, and a basic understanding of the formula bar. The steps below walk you through writing and testing an each expression safely.

What You'll Need

  • Excel (Microsoft 365 or 2016+) with Power Query, or Power BI Desktop.
  • A data source loaded into Power Query (a table, list, or record).
  • Access to the formula bar (enable it from the View tab if hidden).
  • Basic familiarity with Power Query's M language, especially lists and records.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Get Data. The Power Query Editor opens with your data as a query.
  2. Decide where you need an each expression. Common places: adding a custom column to a table, transforming every item in a list, or updating every field in a record. For a table, you'll typically use Table.AddColumn.
  3. Open the Advanced Editor or the formula bar. For a custom column, go to Add Column > Custom Column. The formula bar shows the M code. You can also open the Advanced Editor from the Home tab to see the full query.
  4. Write the each expression. The syntax is each [ColumnName] or each _ for list items. For example, to double a column called Sales, type each [Sales] * 2. The underscore _ represents the current item when working with lists.
  5. Understand the scope. Inside each, field names like [Sales] refer to the current row's record. For a list, use _ to refer to the current element. You cannot mix table and list contexts in one each without converting.
  6. Test with a small sample. Before applying to the whole dataset, filter your query to a few rows or use the first step preview. Check that the expression returns the expected type (number, text, etc.).
  7. Apply the step. Click OK in the Custom Column dialog or confirm the formula. Power Query adds a new step. Review the column for errors (shown as Error in cells).
  8. Handle errors if needed. Wrap the expression in try ... otherwise .... For example: each try [Sales] * 2 otherwise null. This prevents a single bad row from breaking the whole column.
  9. Use each with list functions. For a list, use List.Transform(MyList, each _ * 2). The each here is equivalent to (x) => x * 2. You can also use each Text.Upper(_) to uppercase every string in a list.
  10. Use each with records. To update every field in a record, use Record.TransformFields(MyRecord, each _ * 2) if all fields are numeric. Be careful: mixed types will cause errors.
  11. Check the applied steps. Each transformation appears in the Applied Steps pane. You can click any step to review the result. If something looks wrong, delete the step and try again.
  12. Close and load. Once satisfied, go to Home > Close & Load (Excel) or Close & Apply (Power BI) to output the transformed data.

Common Mistakes

  • Using each without a function context. each is only valid inside a function that expects a function argument, such as Table.AddColumn or List.Transform. Writing each [Sales] as a standalone step will error.
  • Confusing _ and [Column]. In a table row, _ refers to the whole record, so _[Sales] works, but _ * 2 fails because a record can't be multiplied. In a list, [Column] is invalid because list items have no field names.
  • Forgetting type conversion. If a column contains text that looks like numbers, each [Sales] * 2 will error. Use Number.From([Sales]) first.
  • Not handling nulls. Null values propagate. Use try ... otherwise or if [Sales] = null then null else [Sales] * 2.
  • Overcomplicating with custom functions. each is shorthand for (x) => .... If you need multiple statements, define a proper function instead.

Tips

  • Use the formula bar to inspect the generated M code after adding a custom column; it shows exactly how each is used.
  • For simple row-level calculations, each is faster to write than a full let expression.
  • You can nest each inside Table.TransformColumns to apply different transformations per column: