Power Query List.RemoveNulls: How to Use It
In this article
Power Query's List.RemoveNulls function takes a list and returns a new list with every null value removed, leaving everything else in its original order. You write it as List.RemoveNulls(list) in the Advanced Editor or in a custom column formula, and it is one of the simplest ways to clean up lists built from columns, splits, or imported data. It works in Power Query for Excel, Power BI Desktop, and anywhere else the M language runs.
What You'll Need
- Excel (with the Get & Transform / Power Query features), Power BI Desktop, or another tool that hosts Power Query.
- A query already loaded with some data, or at least a blank workbook where you can open a blank query.
- Basic familiarity with the Power Query Editor window (Data > Get Data > Launch Power Query Editor in Excel, or Transform Data in Power BI Desktop).
Step-by-Step
- Open the Power Query Editor. In Excel, go to Data > Get Data > Launch Power Query Editor. In Power BI Desktop, click Transform Data. Exact labels can differ slightly between versions.
- Create a list to work with if you do not have one. The quickest way is a blank query: right-click in the Queries pane, choose New Query > Blank Query, then open Advanced Editor and type something like:
= {1, null, 3, null, 5} - Click Done. You will see a list preview with the nulls shown as null.
- Open Advanced Editor again and wrap the list in the function:
= List.RemoveNulls({1, null, 3, null, 5}) - Click Done. The result is a new list: 1, 3, 5. The nulls are gone and the original order is preserved.
- To apply it to a real column, first convert the column to a list. A common pattern is:
= List.RemoveNulls(Table.Column(Source, "ColumnName"))
where Source is the previous step name and "ColumnName" matches the column header exactly. - If you want the result back inside your table rather than as a standalone list, use it inside a custom column instead. Go to Add Column > Custom Column, name the column, and enter a formula such as:
= List.RemoveNulls(Text.Split([Tags], ","))
This splits a comma-separated text field into a list and drops any empty or null entries in one step. - Click OK, then review the new column. Expand it back to rows or text as needed using the expand icons in the column header.
- When you are happy with the result, click Close & Load (Excel) or Close & Apply (Power BI) to commit the query.
Common Mistakes
- Passing a table instead of a list.
List.RemoveNullsonly accepts a list; feeding it a table step name throws an error. Convert first withTable.Columnor reference the list step directly. - Expecting it to remove empty strings. The function removes only actual null values. An empty text value "" is not null and stays in the list. Filter those separately, for example with
List.Select(yourList, each _ <> ""). - Case sensitivity. The M language is case-sensitive, so
list.removenullsin the wrong casing can cause problems in some editors. Type it asList.RemoveNulls. - Forgetting that it returns a new list. It does not modify anything in place; you must use the returned value in a new step or column.
- Quoting column names incorrectly in
Table.Column. The column name must be a text string in double quotes and match the header exactly, including spaces.
Tips
- Combine it with
Text.SplitandList.Distinctto clean delimited fields: split, remove nulls, then deduplicate. - If you only need to drop nulls from a single table column's values, selecting the column and using the filter dropdown to uncheck null can be simpler than writing M by hand.
- Name your steps meaningfully in Advanced Editor (for example
CleanedList = ...) so the query stays readable. - To count how many nulls were removed, compare
List.Countof the original list against the cleaned one.
Troubleshooting
- "Expression.Error: We cannot convert the value to type List" - you passed something that is not a list, most likely a table. Use
Table.Column(StepName, "Column")to get a list first. - Nulls still appear after running the function - they are probably empty strings, spaces, or text that looks empty. Inspect the value's type in the preview, or filter with
List.Select(yourList, each _ <> "" and _ <> null). - "The name 'ColumnName' wasn't recognized" - you referenced the column without quotes. In
Table.Column, the name must be a quoted string; in a custom column, use square brackets like[ColumnName]. - Ambiguous step name errors in Advanced Editor - make sure each step references the previous step name exactly, and there are no duplicate step names.
- Unexpected row order after loading -
List.RemoveNullspreserves order, so any reordering happened in another step, such as a sort applied afterwards. Check the Applied Steps pane.
Frequently Asked Questions
Does List.RemoveNulls exist in both Excel and Power BI?
Yes. It is part of the shared M language, so any product hosting Power Query has it, including Excel, Power BI Desktop, and Power Query Online.
Does List.RemoveNulls remove empty strings or zeros?
No. It removes only null values. Empty strings (""), zeros, and blanks from other systems remain unless you filter them out separately.
Is there a button for this, or do I have to write M code?
There is no dedicated ribbon button, but the column filter dropdown (unchecking null) achieves a similar result for a table column. For standalone lists, you need the formula bar or Advanced Editor.
How is it different from replacing nulls?
Replacing nulls (for example with List.ReplaceValue or the Replace Values button) keeps the item in place with a substitute value. List.RemoveNulls deletes the entry entirely, shortening the list.
Can I use it on nested lists?
It only removes nulls at the top level. To clean nested lists, combine it with List.Transform, applying List.RemoveNulls to each inner list.
Is the original list changed?
No. M is functional, so the function returns a new list and the original step is untouched.