Smart Systems for Home

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

Power Query Number.RoundAwayFromZero Guide

· 6 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

The Number.RoundAwayFromZero function in Power Query is used to round a number to a specified number of decimal places, ensuring that any value exactly halfway between two numbers is always rounded to the number further from zero. Unlike standard rounding (which may round to the nearest even number), this function treats positive and negative numbers symmetrically: positive values round up and negative values round down. To use it, you apply the function to a numeric column or value and specify the desired precision (number of decimal places).

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • Access to the Power Query Editor (Get & Transform Data).
  • A dataset containing numeric values (Decimal or Fixed Decimal Number types) that require precise rounding.

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab, select Get Data, and choose your source. In Power BI, click Transform Data on the Home ribbon.
  2. Identify the Target Column: Locate the column containing the numbers you wish to round. Ensure the data type is set to Decimal Number or Fixed Decimal Number. If it is set to Text, the function will return an error.
  3. Create a Custom Column: Go to the Add Column tab on the top ribbon and select Custom Column. This allows you to apply the function without overwriting your original data, which is a best practice for auditing your calculations.
  4. Enter the Function Formula: In the Custom Column dialog box, give your new column a name (e.g., "Rounded Value"). In the formula box, type the following syntax: Number.RoundAwayFromZero([ColumnName], digits). Replace [ColumnName] with the actual name of your column from the list on the right, and replace digits with the number of decimal places you want to keep. For example, Number.RoundAwayFromZero([SalesAmount], 2) will round to two decimal places.
  5. Validate the Calculation: Click OK. Power Query will generate a new column. Review the results, specifically looking at values ending in .5, .05, or .005 to ensure they are moving away from zero as expected.
  6. Set the Data Type: The new custom column often defaults to the "Any" data type. Right-click the column header, select Change Type, and choose Decimal Number to ensure subsequent calculations are accurate.
  7. Clean Up: If you no longer need the original unrounded column, right-click it and select Remove. Finally, click Close & Apply on the Home tab to load the data into your model or worksheet.

Common Mistakes

One of the most frequent errors is confusing Number.RoundAwayFromZero with Number.Round. By default, Number.Round in Power Query uses "Banker's Rounding" (Rounding to Even). In Banker's Rounding, 2.5 becomes 2 and 3.5 becomes 4. If your financial or regulatory reporting requires that 2.5 always becomes 3 and -2.5 always becomes -3, using the standard Number.Round without a rounding mode argument will lead to incorrect totals.

Another common mistake is applying the function to a column that is typed as "Text." Power Query functions are strictly typed. If you attempt to round a text string that looks like a number, the result will be an Expression.Error. Always verify the icon to the left of the column header is 1.2 (Decimal) and not ABC (Text) before adding the custom column.

Users also frequently forget the second argument of the function. While some rounding functions in other languages assume zero decimal places if left blank, Number.RoundAwayFromZero requires the precision argument. Omitting it will cause the formula to fail, as the function expects both the number to be rounded and the number of digits to round to.

Tips

To maintain a clean data model, consider creating a "Rounding Parameter" if you find yourself using the same precision (e.g., 4 decimal places) across multiple tables. Instead of hard-coding the number 4 into every formula, you can reference a parameter, making it easier to change the precision globally later without editing every single query step.

If you need to round to the nearest ten, hundred, or thousand, you can use negative numbers for the digits argument. For example, Number.RoundAwayFromZero([Amount], -1) will round to the nearest ten. A value of 15 would become 20, and -15 would become -20. This is incredibly useful for high-level executive summaries where granular decimals are distracting.

For those working with extremely large datasets, applying rounding at the very end of your transformation sequence is generally more efficient. Performing rounding early can sometimes lead to cumulative rounding errors if those rounded numbers are then used in further multiplications or divisions. Keep the raw precision as long as possible, then apply Number.RoundAwayFromZero as the final step before loading the data.

Troubleshooting

If your formula returns an error, the first step is to check for null values. If a row contains a null, the function may return a null or an error depending on the context. You can handle this by using an if statement: if [ColumnName] = null then null else Number.RoundAwayFromZero([ColumnName], 2). This ensures that the rounding logic only applies to actual numbers.

If the rounding does not seem to be happening correctly, double-check the data type of the source column. Sometimes data imported from CSVs is treated as text. Even if it looks like a number, Power Query cannot perform mathematical rounding on a text string. Use the Transform tab to change the type to Decimal Number before applying the function.

If you are seeing unexpected results with very small decimals (e.g., 1.0000000000001), you may be encountering floating-point precision issues inherent to how computers store decimal numbers. In these cases, try changing the data type to "Fixed Decimal Number" (which is essentially a Currency type) before rounding. This forces the system to use a more rigid decimal representation, which often resolves tiny precision discrepancies.

Frequently Asked Questions

How does this differ from Number.RoundUp?

Number.RoundUp always moves the number toward positive infinity. For a positive number like 2.1, both functions result in 3. However, for a negative number like -2.1, Number.RoundUp moves it to -2, while Number.RoundAwayFromZero moves it to -3.

Can I use this function in a calculated column in Power BI instead of Power Query?

No, Number.RoundAwayFromZero is an M language function used in Power Query. If you are creating a calculated column using DAX in the Power BI report view, you would use the ROUND function, though you must be aware that DAX rounding behavior differs from M rounding behavior.

What happens if I set the digits argument to 0?

Setting the digits to 0 will round the number to the nearest whole integer. For example, 1.5 becomes 2 and -1.5 becomes -2. This is the most common setting for creating counts or whole-unit measurements.

Does this function work with the "Fixed Decimal Number" type?

Yes, it works perfectly with Fixed Decimal Numbers. In fact, using Fixed Decimal Number is often recommended for financial data to avoid the floating-point errors mentioned in the troubleshooting section.

Is there a way to apply this to multiple columns at once?

While the Custom Column tool handles one column at a time, you can select multiple columns in the Power Query editor, go to the Transform tab, and use the Rounding menu. However, the UI menu typically uses standard rounding. To use RoundAwayFromZero on multiple columns, you would need to edit the M code in the Advanced Editor to apply the function across a list of columns using Table.TransformColumns.