Number.IsNaN

Number

Returns true if the number is NaN (Not a Number), such as the result of 0/0.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Number.IsNaN(number as number) as logical

Parameters

NameTypeRequiredDescription
numbernumberYesThe number to test for NaN.

Return Value

logicalTrue 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 1: Zero divided by zero produces NaN

Result
Result
1TRUE

Example 2: A finite number is not NaN

Result
Result
1FALSE

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
)
Result
OrderID
CustomerName
UnitPrice
Quantity
PricePerUnit
11Alice2546.25
22Bob50225
33Charlie15101.50
44Alice75175
55Diana2564.17

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks