Number.Log
NumberReturns the logarithm of a number to the specified base. If no base is provided, returns the natural logarithm (base e).
Syntax
Number.Log(number as nullable number, optional base as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | The positive number whose logarithm is computed. |
base | number | No | The logarithm base. Defaults to e (natural logarithm) when omitted. |
Return Value
number — The logarithm of number to the specified base, or the natural log if base is omitted.
Remarks
Number.Log computes the logarithm of a number to a specified base. When the base parameter is omitted, it returns the natural logarithm (base e) — identical to Number.Ln. When base is 10, it is equivalent to Number.Log10. For base 2, use Number.Log(x, 2) since there is no dedicated Number.Log2 function in M.
The number must be strictly positive for a real result. Passing 0 returns negative infinity; a negative number returns NaN. The base must be a positive number not equal to 1. Avoid computing Number.Log(x, 1) — it returns NaN or infinity.
A common pitfall: Number.Log(x) with no base returns the natural log, not the base-10 log. This differs from the behavior in some other languages where log() defaults to base 10. If you intend base-10, always specify 10 explicitly or use Number.Log10(x).
The base-change formula lets you compute any logarithm from the natural log: log_b(x) = Number.Ln(x) / Number.Ln(b), which is how Power Query internally evaluates Number.Log(x, b).
Examples
Example 4: Apply log base 2 transformation to UnitPrice column
Table.AddColumn(
Table.SelectColumns(Table.FirstN(Sales, 4), {"OrderID", "CustomerName", "UnitPrice"}),
"Log2Price",
each Number.Log([UnitPrice], 2),
type number
)OrderID | CustomerName | UnitPrice | Log2Price | |
|---|---|---|---|---|
| 1 | 1 | Alice | 25 | 4.64 |
| 2 | 2 | Bob | 50 | 5.64 |
| 3 | 3 | Charlie | 15 | 3.91 |
| 4 | 4 | Alice | 75 | 6.23 |