Sub topic 7
Handling nulls: replace, fill down, and remove empty rows
This chapter assumes you can open the Power Query Editor, read the Applied Steps pane, and profile a column with Column quality. It also assumes you have set data types, as covered earlier.
What a null is
A null in Power Query means "no value". It is not the same as an empty string ("") or a string of spaces. Nulls show as the word null in italics in the grid. Column quality reports them as "Empty", but that count only includes true nulls and empty strings, not whitespace. Trim text first so that blank-looking cells become empty and can be handled with the same steps.
Nulls matter because aggregations skip them, comparisons with them return null instead of true or false, and a null in a key column can break relationships later.
Choose a strategy
Pick the fix based on why the value is missing.
| Situation | Approach | Editor command |
|---|---|---|
| A known default exists | Replace with a constant | Transform > Replace Values |
| A group header appears once, then blanks below it | Copy the value downward | Transform > Fill > Down |
| The whole row carries no information | Drop the row | Home > Remove Rows > Remove Blank Rows |
| The value is unknown and a default would mislead | Leave the null | None |
Replace nulls with a value
Select the column, choose Replace Values, enter null in Value To Find, and enter the new value. The editor writes a Table.ReplaceValue step. This example comes from the cleaning query:
let
Source = #table(
{"Customer", "Region", "Amount"},
{
{"Alice Smith", "West", 120},
{"Bob Jones", null, 80}
}
),
FilledRegion = Table.ReplaceValue(Source, null, "Unknown", Replacer.ReplaceValue, {"Region"})
in
FilledRegionThe last argument is the list of columns to change. Without the right column list, the step would touch only the columns you selected, so check the formula bar after you apply it.
Fill down
Reports exported from spreadsheets often show a label once and leave the rows beneath it blank. Fill Down copies the last non-null value into the nulls below it.
let
Source = #table(
{"Region", "Product", "Sales"},
{{"West", "Widget", 10}, {null, "Gadget", 7}, {"East", "Widget", 5}, {null, "Gadget", 9}}
),
FilledDown = Table.FillDown(Source, {"Region"})
in
FilledDownFill Down depends on row order. Sort or filter before the fill and you can copy a value into the wrong rows. Place it directly after promoting headers and removing junk rows. Fill Up works the same way in the other direction.
Remove empty rows
Remove Blank Rows deletes rows where every column is null or an empty string. A row with even one value stays.
let
Source = #table(
{"Customer", "Amount"},
{{"Alice", 120}, {null, null}, {"Bob", null}}
),
RemovedBlanks = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
RemovedBlanksThis is the code the editor generates for the command. Bob's row survives because Amount is null but Customer is not. To drop rows based on one column, filter that column and clear the null check box in the filter list.
Exercise
A sheet lists a department name on the first row of each group and leaves the other rows blank. Which transformation fills the blanks, and why must you apply it before sorting?
Show answer
Use Fill Down on the department column. It copies values by row position, so sorting first would move rows away from their group header and fill the wrong department into them.
Exercise
Why does Remove Blank Rows keep a row that has a customer name but a null amount?
Show answer
The command removes only rows where every column is null or empty. That row has one value, so it stays.