Smart Systems for Home

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

Power Query Value.Divide: How to Divide Columns

· 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

Value.Divide is the Power Query M function that divides one number by another. It takes two arguments, a dividend and a divisor, and returns the quotient as a number. You can use it in a custom column formula, in a calculated table expression, or anywhere the M language accepts an expression. The main advantage over the / operator is that Value.Divide handles nulls more predictably and makes the intent of the formula explicit, which helps when you are building reusable queries or documenting your work.

What You'll Need

  • Power BI Desktop, Excel with Power Query, or another tool that hosts Power Query (the steps below use Power BI Desktop; labels in Excel's Power Query Editor are nearly identical).
  • A query that already contains at least two numeric columns, or two columns you can convert to numbers.
  • Basic familiarity with the Power Query Editor window and the formula bar.

Step-by-Step

  1. Open your report in Power BI Desktop and click Transform data on the Home ribbon to launch the Power Query Editor. In Excel, go to Data > Get Data > Launch Power Query Editor.
  2. Select the query that holds your numeric columns from the Queries pane on the left.
  3. Check that both columns are numeric. Click the column header icon to confirm the data type shows a number (whole number, decimal number, or similar). If it shows Text or Any, click the icon and choose a numeric type before continuing. Value.Divide returns an error if either argument is text.
  4. Go to Add Column > Custom Column. The Custom Column dialog opens.
  5. In the New column name box, type a name such as Ratio or Unit Price.
  6. In the Custom column formula box, enter a formula that calls Value.Divide with your two columns. For example, to divide a column named Total by a column named Quantity, type:
    Value.Divide([Total], [Quantity])
    Column names must be enclosed in square brackets and match exactly, including spaces.
  7. Click OK. Power Query adds the new column and shows the step in the Applied Steps list on the right.
  8. Review the new column for errors. Cells that show Error usually mean a text value slipped through, a null was used as the divisor, or the divisor is zero. Click the error to read the message.
  9. If you need to change the formula, select the new column and edit the formula in the formula bar, or double-click the step in Applied Steps to reopen the dialog.
  10. When the result looks right, click Close & Apply on the Home tab to load the query back into your model.

To divide by a fixed number instead of a column, replace the second argument with a literal, for example Value.Divide([Total], 1000) to convert a value to thousands. To guard against zero divisors, wrap the call in an if expression: if [Quantity] = 0 then null else Value.Divide([Total], [Quantity]). This returns null instead of an error when the divisor is zero.

Common Mistakes

  • Forgetting the square brackets. Writing Value.Divide(Total, Quantity) treats the names as text or unknown identifiers. Column references always need brackets.
  • Dividing text columns. If either column is typed as Text, the function returns an error. Change the data type first, then add the custom column.
  • Dividing by zero. Value.Divide does not silently return null for a zero divisor; it raises an error. Use the if-expression guard shown above when zeros are possible.
  • Assuming nulls behave like zero. A null in either argument generally produces a null result, not an error. That is often what you want, but check your totals if nulls are present.
  • Case and spacing in column names. [Total Sales] and [total sales] are not the same reference. Match the header exactly.
  • Editing the wrong step. If you change a step earlier in Applied Steps, later steps that reference the renamed or removed column will break. Insert the custom column after the type-change step, not before it.

Tips

  • Use Value.Divide rather than the / operator when you want the formula to be self-documenting, especially in shared queries.
  • Set the data type of the new column explicitly after creation. Power Query often infers Decimal Number, but choosing the type yourself avoids surprises downstream.
  • For percentage results, divide as normal and then format the column as a percentage in the data model or report, rather than multiplying by 100 in the formula.
  • If you need to divide many column pairs, consider unpivoting the columns first so a single custom column handles all of them.
  • Keep the guard expression in a separate step or a named function if you reuse it across queries.

Troubleshooting

If the new column shows errors, click one error cell to read the message. A "cannot convert" message points to a text value in one of the columns; filter or replace it, or change the column type. A "divide by zero" message means the divisor is zero for that row; add the if-expression guard. If the custom column dialog will not accept the formula, check that you used square brackets and that the column names exist in the current step. If the column disappears after you close and apply, look at the Applied Steps list to confirm the step was saved and that no later step removed the column. If results look wrong rather than erroring, compare a few rows against the source data to confirm you divided the intended columns in the intended order; division is not commutative, so swapping arguments changes the answer.

Frequently Asked Questions

What is the difference between Value.Divide and the / operator?

Both divide two numbers. Value.Divide is a named function, which makes formulas easier to read and reuse, and it is the form you will see in many generated queries. The / operator is shorter and works the same way for ordinary numeric values.

Does Value.Divide handle nulls?

Yes. If either argument is null, the result is generally null rather than an error, which lets you keep rows without breaking the query.

Why do I get an error when dividing by zero?

Division by zero is undefined, so Power Query raises an error. Wrap the call in an if expression that checks for zero and returns null or a default value instead.

Can I use Value.Divide on a calculated table or in a measure?

Value.Divide is an M function, so it belongs in Power Query, not in DAX measures. In DAX, use the DIVIDE function, which handles division by zero by returning a blank or an alternate result.

How do I divide a column by a fixed number?

Replace the second argument with the number, for example Value.Divide([Amount], 100). The number does not need brackets.

Do I need to change the data type before using Value.Divide?

Yes, in practice. Both arguments must be numeric. If a column is typed as Text or Any, change it to a number first, then add the custom column.