Power QueryExercises

Expression.Error: We cannot convert the value null to type Logical

By Tahir Nas · Examples run in our simulator · Updated

Expression.Error: We cannot convert the value null to type Logical.

if and filter conditions need true or false. When a condition evaluates to null, for example because the column is empty on some rows, if raises this error.

Common causes

How to fix it

  1. Compare explicitly: if [Flag] = true then … treats null as not true.
  2. Supply a default with the coalesce operator: if [Flag] ?? false then ….
  3. Replace nulls in the column before the step: Table.ReplaceValue(…, null, false, Replacer.ReplaceValue, {"Flag"}).

Find the step that fails

Minimal example

Raises the error:

let Flag = null in if Flag then "Yes" else "No"

Fixed:

let Flag = null in if Flag ?? false then "Yes" else "No"

Both snippets are run by the Power Query Exercises simulator on every build: the first must raise Expression.Error, the second must run.

Practise avoiding it

Related lessons

Similar errors