Classify a variance direction with Number Sign in Power Query
Use Number.Sign in a Power Query custom column to distinguish positive, negative, and zero values without changing the original variance. The result is 1, -1, or 0 respectively. A null input produces null. This is useful when you want a direction flag beside a numerical difference, rather than replacing the difference with a label that hides its size. This guide uses a fictional workshop stock check, with expected results calculated from the documented function behavior rather than a claimed application test.
Decide what the sign means
Suppose a workshop planned to use twelve sheets of card. One session used fifteen sheets, another used nine, and a third used twelve. Define Variance as actual usage minus planned usage. Those three differences are positive three, negative three, and zero. With this definition, a positive value means more material was used than planned. It does not automatically mean good performance. Write the subtraction order in your query notes so another person does not interpret the flag backwards.
A fourth session has no recorded usage yet. Represent that missing measurement as null rather than zero. Zero says that the quantities matched; null says that a measurement is unavailable. Combining those meanings would make a summary misleading. Number.Sign preserves the distinction because a null input returns null. Keep the original actual and planned quantities available when investigating a discrepancy, even if a final report only displays the difference and direction.
Build a small practice table
In Power BI Desktop, use Home and Enter data to create a practice table with Session and Variance columns. Enter Morning with 3, Afternoon with -3, Evening with 0, and Unrecorded with an empty variance cell. Open Transform data to inspect the query. Confirm that Variance has a numeric data type and that the unrecorded row appears as null. If it contains an empty text string instead, correct the practice input before continuing. Text and missing numbers are different data problems.
Choose Add Column and Custom Column in Power Query Editor. Name the new field Direction and enter Number.Sign([Variance]) as the expression. The custom column dialog accepts the expression without an initial Excel equals sign. Confirm the dialog, then inspect all four rows before closing the editor. Menu wording can vary with the current Desktop build and display language. This is Power Query M inside the query editor, rather than a DAX calculated column in the report model.
Check each expected result
Morning should return 1 because three is positive. Afternoon should return -1 because negative three lies below zero. Evening should return 0. The unrecorded session should remain null. These four cases form a better check than one positive example: they exercise both directions, the boundary, and the missing input. If any result disagrees, inspect the source value and the formula before adding further transformations. A correct-looking column name does not prove that it references the intended field.
Now change Morning to 0.5 in the practice source. Its direction should still be 1. Change Afternoon to -0.5 and expect -1. The output describes direction rather than magnitude: three and one half have the same positive sign. Consequently, adding Direction values is not a substitute for adding Variance values. One large positive difference and several small negative differences could produce a negative count of directions while their total numerical variance remains positive.
Use the flag without hiding context
A sensible final table might retain Session, Variance, and Direction. Readers can sort or filter by Direction while still seeing the quantity involved. Explain the code in a visible legend: 1 means above plan, -1 means below plan, and 0 means matched plan. If you later create friendly text labels, preserve a separate missing state. Avoid labeling every nonpositive result as below plan, because zero belongs in its own category and null has not supplied a measurement.
The function does not apply a tolerance. A tiny positive residual is still positive. When measured quantities need an agreed rounding rule or a permitted tolerance, document that separate business rule before classifying direction. Do not quietly round all values merely to make the display appear cleaner. A displayed zero may conceal a small stored difference. Inspect the underlying value when a visible zero receives a positive or negative flag, and decide whether the source precision is appropriate for your task.
Troubleshoot the expression
If the column errors, check that you entered Number.Sign with its documented capitalization and supplied a numeric field. A column named Variance Amount requires the matching field reference [Variance Amount]. Do not paste a quoted column name as the argument; that supplies text instead of a row value. If the source contains numbers stored as text, investigate conversion and locale before applying the function. Keep conversion errors visible until you understand them instead of replacing every error with zero.
Before applying the query, check whether the new field needs an explicit numeric type for downstream work. Refresh the practice table after changing the source and verify that the direction recalculates. Power Query transformations run when the query evaluates; this is not an interactive cell formula that updates independently inside a report visual. Keep the applied step so a colleague can inspect the calculation and its position relative to any cleaning or rounding steps.
Try a direction audit
Create five practice differences: 8, -2, 0, null, and -0.25. Predict their flags on paper before evaluating the query. The expected sequence is 1, -1, 0, null, and -1. Then reverse the subtraction definition from actual minus planned to planned minus actual. Which flags change, and which stay the same? Explain why the missing measurement remains missing. This exercise checks both your understanding of the function and the meaning you intend readers to attach to the result.














