Conditionally Replace Values in Specific Rows Only in Power Query M

Replaces a column's value only where a condition is true, leaving every other row untouched.

Conditional LogicIntermediateconditional replacetable.transformcolumns

Power Query M code

let
    Source = YourTable,
    AddedCorrected = Table.TransformColumns(
        Source,
        {{"Amount", each if _ < 0 then 0 else _, type number}}
    )
in
    AddedCorrected

Notes

The underscore (_) refers to the current cell's value inside Table.TransformColumns.

Requirements

How to use this snippet

  1. In Power BI Desktop, choose Transform data to open Power Query, then open the Advanced Editor on a query (or start from a blank query).
  2. Paste the snippet and replace the placeholder names (tables, columns, file paths) with your own. Check the requirements above first.
  3. Run it through the Power Query M Formatter to tidy the layout.

More Power Query M resources

Browse all 145 snippets in the Power Query M Code Snippets, or search the library for something similar to Conditionally Replace Values in Specific Rows Only.