Number.Log

Number

Returns the logarithm of a number to the specified base. If no base is provided, returns the natural logarithm (base e).

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

Syntax

Number.Log(number as nullable number, optional base as nullable number) as nullable number

Parameters

NameTypeRequiredDescription
numbernumberYesThe positive number whose logarithm is computed.
basenumberNoThe logarithm base. Defaults to e (natural logarithm) when omitted.

Return Value

numberThe 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 1: Base-2 logarithm — how many doublings reach 1024?

Number.Log(1024, 2)
Result
Result
110

Example 2: Omitting base returns the natural logarithm (base e)

Result
Result
11

Example 3: Base-10 log of 1000

Number.Log(1000, 10)
Result
Result
13

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
)
Result
OrderID
CustomerName
UnitPrice
Log2Price
11Alice254.64
22Bob505.64
33Charlie153.91
44Alice756.23

Compatibility

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