Number.IsNaN
NumberReturns true if the number is NaN (Not a Number), such as the result of 0/0.
Syntax
Number.IsNaN(number as number) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | The number to test for NaN. |
Return Value
logical — True if the value is NaN, false otherwise.
Remarks
Number.IsNaN returns true when the input is the special IEEE 754 "Not a Number" (NaN) value. NaN is the result of undefined floating-point operations such as 0 / 0, Number.Sqrt(-1), Number.Acos(2) (out-of-domain input), or arithmetic involving existing NaN values.
The critical behavior that makes Number.IsNaN necessary: NaN is not equal to itself. In M, (0/0) = (0/0) evaluates to false, not true. This means you cannot use the = operator or Value.Equals to detect NaN — you must use Number.IsNaN.
NaN propagates silently through arithmetic: adding, multiplying, or comparing with NaN produces NaN or incorrect results without raising an error. This makes NaN values dangerous in pipelines — they can corrupt aggregations and summaries without any visible error. Always guard against NaN at data ingestion or when dividing values.
Important limitation: Number.IsNaN does not accept null as input and will raise an error if the value is null. Always filter out nulls before calling this function: if value = null then null else Number.IsNaN(value).
Examples
Example 3: Guard against division-by-zero NaN when computing a ratio
Table.AddColumn(
Table.SelectColumns(Table.FirstN(Sales, 5), {"OrderID", "CustomerName", "UnitPrice", "Quantity"}),
"PricePerUnit",
each let ratio = [UnitPrice] / [Quantity]
in if Number.IsNaN(ratio) then null else ratio,
type number
)OrderID | CustomerName | UnitPrice | Quantity | PricePerUnit | |
|---|---|---|---|---|---|
| 1 | 1 | Alice | 25 | 4 | 6.25 |
| 2 | 2 | Bob | 50 | 2 | 25 |
| 3 | 3 | Charlie | 15 | 10 | 1.50 |
| 4 | 4 | Alice | 75 | 1 | 75 |
| 5 | 5 | Diana | 25 | 6 | 4.17 |