Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Number.Ln in Power Query: Natural Log Step by Step

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Number.Ln is Power Query's function for the natural logarithm — the logarithm to base e (roughly 2.71828). You pass it one number and it returns that value's natural log: Number.Ln(10) returns about 2.302585. You can use it anywhere a Power Query expression is accepted: in a custom column, in a step of the Advanced Editor, or inside a transformation. It takes exactly one argument, returns a decimal number for any positive input, returns an error for zero and negatives, and returns null if you feed it null. That single-argument behaviour is the most important thing to understand, because almost every problem people hit with it comes from the wrong base, a non-positive input, or a column whose values are stored as text.

What You'll Need

  • Power Query available in your tool — Power BI Desktop, Excel (Data > Get Data), or another host that ships the Power Query engine. The function is part of the core library, so no add-in or extra package is required.
  • A query containing at least one numeric column, or a table of sample values to practise on.
  • Enough familiarity with the Power Query Editor to open the Advanced Editor and add a custom column. Menu labels vary slightly between Excel and Power BI and between software versions, so if a button is not exactly where described, look for the closest equivalent.

Step-by-Step

  1. Load your data into the Power Query Editor. In Excel, select your table and choose Data > Get Data > From Table/Range. In Power BI Desktop, choose Home > Transform data to open the editor on an existing table, or use Get data to import one. Confirm your numeric column shows numbers in the column-header data type icon, not the ABC text icon.
  2. Check the column's data type first. Right-click the column header and choose Change Type > Decimal Number (or Whole Number if appropriate). Number.Ln needs a real number; a column of text values that look like numbers returns errors such as We cannot convert the value to type Number.
  3. Add a custom column. On the Add Column tab, choose Custom Column. Give it a name such as Ln or Log of Amount.
  4. Write the formula. In the formula box type Number.Ln([Amount]), replacing Amount with the exact name of your numeric column. Column names are case-sensitive in Power Query and are enclosed in square brackets; the function name itself is case-sensitive too, so Number.LN will fail.
  5. Press OK and inspect the result. The new column appears with the logarithm values. Click the data type icon in its header and set it to Decimal Number if Power Query has inferred something else.
  6. Test the base before you rely on it. Natural log is base e. If you actually wanted base 10, use Number.Log10([Amount]); for a custom base use Number.Log([Amount], [Base]). If you wanted base 2, use Number.Log([Amount], 2). Mixing these up is a very common source of numbers that look almost right.
  7. Handle zero and negative values deliberately. Nothing is hidden: any value of zero or below produces an error in the new column. If your data can contain them, wrap the call: if [Amount] > 0 then Number.Ln([Amount]) else null. Keeping the row and returning null is usually safer than letting an error propagate, because a single error can block a downstream load.
  8. Add a guard for missing values if needed. Number.Ln passes null straight through, so nulls are generally harmless. Only add handling if you need a specific substitute value such as 0.
  9. Verify with a known value. Add a temporary custom column Number.Ln(1), which must return 0, and Number.Ln(Number.E), which must return 1. These two checks confirm the function is behaving as expected before you trust the whole column.
  10. Rename and close. Rename the appended column descriptively, then choose Home > Close & Load (or Close & Apply) to push the result back to your worksheet or data model.

Common Mistakes

Assuming it is base 10. The name Ln specifically means natural log. Engineers expecting a log10 result see smaller numbers than they anticipated. Use Number.Log10 for base 10.

Forgetting the brackets around the column name. Writing Number.Ln(Amount) instead of Number.Ln([Amount]) produces an error about an unrecognised identifier. Column references always sit in square brackets.

Feeding text. Values imported from CSV or pasted sheets are often typed as text. The function has no coercion, so convert the type first.

Feeding zero or a negative. The natural log is undefined there. Decide in advance whether to filter, clamp to a small positive number, or return null.

Wrong case. M is case-sensitive. number.ln, Number.LN and Number.Ln are not interchangeable.

Confusing it with Number.Power. If you need e raised to a power, that is Number.Exp, the inverse of Number.Ln. Using the wrong one produces silently wrong results rather than an error.

Tips

Use logarithms to compress wide-ranging values before charting — income, population and file sizes often span several orders of magnitude and look better on a log scale. You can also compute growth rates by differencing logs: Number.Ln([End]) - Number.Ln([Start]) approximates the continuous rate of change. For a ratio, the difference of logs equals the log of the ratio, which is handy when the raw ratio is unstable at small counts. Consider applying the transform inside a Table.TransformColumns step instead of adding a whole custom column when you simply want to replace an existing column's values. And document the base in the column name — Ln versus Log10 — so the next person reading the query does not have to guess.

Troubleshooting

If the column shows errors instead of numbers, click the error message in a cell to read the detail. A conversion error almost always means the source type is text or contains mixed values; filter out blanks and non-numeric rows, then change the type to Decimal Number.

If every row is null, the argument is null for each one — check whether the column name in the formula actually matches the column, and whether upstream steps replaced the values with null.

If results look implausibly small, confirm you are not comparing natural log against a base-10 expectation. Natural log of 100 is about 4.605; base-10 log of 100 is 2.

If the query fails to load, one errored cell can stop the refresh. Locate the errors, decide whether to remove those rows, replace them with null, or leave the row out of the log column, then refresh again.

Frequently Asked Questions

Does Number.Ln return base 10?

No. It returns the natural logarithm, base e. Use Number.Log10 for base 10.

What does Number.Ln(0) return?

An error, because the natural log is undefined at zero. Wrap the call in a conditional if zeros are possible.

Can I pass a whole table or list?

No. It accepts a single number. Apply it per row with a custom column, or use List.Transform for a list.

How do I reverse a natural log?

Use Number.Exp, which raises e to the given power and undoes Number.Ln.

Does it work on negative numbers?

No. Only positive values have a real natural log, so negatives return an error.