Power Query Problems

Update an Amount Column with IF Logic in Excel Power Query

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

The user needs conditional logic to update an amount column using two source amount fields while preserving the existing value when both sources are zero.

Update an Amount Column with IF Logic in Excel Power Query
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
Combine payment or accounting query data and select an amount from Amt_NEW, Amt1, or Amt2.
Observed behavior
The desired result keeps a nonzero Amt_NEW first, otherwise uses a nonzero Amt1 or Amt2, and retains Amt_NEW when neither source provides a nonzero value.
Before you start

Open the query in Power Query Editor and confirm that Amt_NEW, Amt1, and Amt2 are numeric columns. Check the exact column names, including capitalization, because Power Query M references are case-sensitive.

Solution 1Recommended

Add a custom column with Power Query IF logic

Use a custom column to select the first nonzero amount in the order Amt_NEW, Amt1, then Amt2.

This logic preserves an existing nonzero Amt_NEW even if Amt1 or Amt2 also contains a nonzero value. It treats null source values as unavailable and returns the original Amt_NEW if neither source supplies a nonzero amount.

1
Open the query

In Excel, go to Data > Queries & Connections, then double-click the query to open it in Power Query Editor.

2
Add a custom column

Select Add Column > Custom Column and name the new column Amt_Result.

3
Enter the formula

In the Custom column formula box, enter: if [Amt_NEW] <> null and [Amt_NEW] <> 0 then [Amt_NEW] else if [Amt1] <> null and [Amt1] <> 0 then [Amt1] else if [Amt2] <> null and [Amt2] <> 0 then [Amt2] else [Amt_NEW]. Click OK.

4
Replace the original column

Check the Amt_Result values. To use them as Amt_NEW, right-click the original Amt_NEW column and select Remove, then right-click Amt_Result and select Rename. Enter Amt_NEW and set its data type if needed.

5
Load the result

Select Home > Close & Load to return the updated query results to Excel.

Add a custom column with Power Query IF logic
Preserve nulls when needed: If Amt_NEW is null and both source amounts are zero or null, the result remains null. Replace nulls with zero before applying the formula only if that matches your accounting rules.
WPS Spreadsheet solution

Apply the same amount-selection logic in WPS Spreadsheet

Use a worksheet IF formula in WPS Spreadsheet to choose between the existing amount and two source amounts. This calculates on the sheet rather than modifying or refreshing a Power Query.

  1. 1. Open the workbook: Open your Excel workbook in WPS Spreadsheet and locate the sheet containing the amount fields.
  2. 2. Check the columns: For this example, place or identify Amt_NEW in column A, Amt1 in column B, and Amt2 in column C, with numeric data starting in row 2. Use zero for missing amounts if that matches your data rules.
  3. 3. Enter the formula: In an empty result cell such as D2, enter =IF(A2<>0,A2,IF(B2<>0,B2,IF(C2<>0,C2,A2))). Adjust the references if your columns are different.
  4. 4. Fill and save: Drag the fill handle down column D. If you need to replace Amt_NEW, copy the results and use Paste Special > Values on the original cells, then save the workbook.
Apply the same Amt_NEW, Amt1, and Amt2 priority with an IF formula.Open and save Microsoft Excel XLSX files.Use a familiar spreadsheet interface to review and fill formulas.Work with a free, lightweight Office alternative.
microsoft office alternative - wps office

Frequently Asked Questions

What happens if both Amt1 and Amt2 are nonzero?

The formula keeps Amt_NEW if it is nonzero. Otherwise, it chooses Amt1 before Amt2. Change the order of the conditions in Add Column > Custom Column if your business rules require a different priority.

Can I add the three amounts instead of using IF logic?

Adding them works only when nulls have been handled and at most one of the three amounts is nonzero in each row. If multiple amounts are nonzero, summing them produces a different result from the priority-based IF formula.

How does the formula handle null values?

The custom-column formula skips null values when checking for a nonzero amount. If no source provides one, it returns Amt_NEW, including a null Amt_NEW. To use zero instead, select the relevant columns in Power Query Editor and replace nulls with zero before adding the formula.

Will the custom column update when I refresh the query?

Yes. The custom column is a query step, so Excel recalculates it when you use Data > Refresh All, provided the source columns and their names remain available.