Sub topic 8
Filling Down and Handling Nulls
This chapter assumes you can open the Power Query Editor, read the Applied Steps pane, and set data types. Here you will learn to fill blank cells in grouped layouts and to decide what to do with null values.
Why blanks appear
Reports often show a label once and leave the cells below it empty. A Region column might say "North" in the first row and then nothing for the next five rows. People read this easily. A query cannot, because each row must stand on its own.
In Power Query, an empty cell is a null, which means "no value". Null is not the same as an empty text string ("") or the number 0. Filters, joins, and Group By treat these differently, so check which one you have.
Fill Down and Fill Up
Fill Down copies the last non-null value into the null cells below it. Fill Up does the reverse and copies the next value upward.
- Select the column, such as Region.
- Choose Transform, then Fill, then Down.
The editor records this step:
let
Source = Excel.CurrentWorkbook(){[Name="SalesByMonth"]}[Content],
Filled = Table.FillDown(Source, {"Region"})
in
FilledYou can pass several column names in the list to fill them in one step.
Fill only after the blanks are real nulls
Fill Down only acts on true nulls. Cells that look blank may hold a space or an empty string. In that case nothing fills, and no error appears.
To fix this, replace the empty values with null first:
- Select the column.
- Choose Transform, then Replace Values.
- Replace
""withnull. For cells that hold only spaces, run Trim first so they become empty strings.
Then apply Fill Down. Step order matters here, and the Applied Steps pane shows it.
Common mistake: sorting before filling
Fill Down depends on row order. If you sort the table first, the rows no longer follow the original layout, and values fill from the wrong rows. Fill first, then sort.
Handling the remaining nulls
Some nulls are real gaps, not layout blanks. You have three options.
- Remove them. Use the column filter and clear the
(null)checkbox, or use Remove Rows, then Remove Blank Rows. This removes only rows where every column is empty. - Replace them. Use Replace Values with
nullas the value to find, and a default such as0or"Unknown"as the replacement. - Keep them. Aggregations such as sum ignore nulls, so this is often fine.
Replacing nulls in a numeric column with 0 changes averages. A missing value is not the same as zero, so replace only when the meaning is clear.
Combining fill and unpivot
Fill Down usually comes right before an unpivot, as in the earlier SalesByMonth example. Fill the label columns first so that every unpivoted row keeps its Region.
Exercise
A table has Region filled only on the first row of each group. You apply Fill Down, but the blank cells stay blank. What is the most likely cause, and how do you fix it?
Show answer
The blank cells probably hold empty strings or spaces, not true nulls. Trim the column if needed, use Replace Values to change "" to null, and then apply Fill Down again.