Power Query List.IsEmpty: A How-To Guide
In this article
List.IsEmpty is a Power Query M function that returns true if a list contains no items, and false if it has at least one. It is the quickest way to test for an empty list before you try to expand, combine, or extract from it, which helps you avoid errors and blank rows in your queries. You do not need any special setup beyond access to Power Query (in Excel or Power BI) and a basic understanding of how to open the Power Query Editor and write a custom column or step.
What You'll Need
- Excel (Microsoft 365, Excel 2021, or Excel 2019) or Power BI Desktop. The steps below use the Power Query Editor, which is nearly identical in both; labels can differ slightly by version, device, or region.
- A query that produces at least one list value, or the ability to create a list manually for testing (for example, using the formula bar or a blank query).
- Basic familiarity with the Power Query Editor: opening it, adding a custom column, and editing the formula bar.
Step-by-Step
- Open the Power Query Editor. In Excel, go to the Data tab and select Get Data > Launch Power Query Editor (or From Table/Range if your data is already in a worksheet). In Power BI Desktop, select Transform data on the Home ribbon. The exact button names can vary slightly between versions.
- Load or create a query that contains a list. If you already have a query with a column that holds lists (for example, after using Table.Group or Text.Split), select that query. If you just want to test List.IsEmpty, create a blank query: Home > New Source > Blank Query, then use the formula bar to enter a list such as
{1, 2, 3}or{}. - Add a custom column or a new step. To test a list in an existing column, go to Add Column > Custom Column. In the dialog, give the column a name (for example, "IsEmpty") and enter a formula that calls List.IsEmpty on the list column. For a column named "MyList", the formula is
List.IsEmpty([MyList]). If you are testing a single list value in a query step, you can instead add a step in the formula bar:= List.IsEmpty(Source)where Source is the list. - Confirm the result type. List.IsEmpty returns a logical value (true or false). In a custom column, the new column will show true for empty lists and false for non-empty lists. If you see errors instead, the column probably contains nulls or values that are not lists; see Troubleshooting below.
- Use the result to filter or branch. You can filter the new column to keep only rows where IsEmpty is false (to remove empty lists) or true (to isolate them). You can also use List.IsEmpty inside an if expression:
if List.IsEmpty([MyList]) then null else List.Sum([MyList]). This prevents errors when summing an empty list. - Apply and close. When you are done, select Close & Load (Excel) or Close & Apply (Power BI) to load the results back to your worksheet or data model. The custom column and any filters will be applied.
Common Mistakes
- Passing a table or a record instead of a list. List.IsEmpty expects a list. If you pass a table, a record, or a single value, you will get an error. Use Table.ToList or Record.ToList first if needed.
- Forgetting that null is not an empty list. List.IsEmpty(null) returns an error because null is not a list. If your column can contain nulls, wrap the call:
if [MyList] = null then true else List.IsEmpty([MyList]). - Assuming an empty list is the same as a list with one null. A list containing a single null (
{null}) is not empty; List.IsEmpty returns false. Check the list contents if you need to treat null-only lists as empty. - Using List.IsEmpty on a column that contains text. Text values are not lists, so you will get an error. Convert the text to a list first (for example, with Text.Split) if that is your intent.
- Expecting List.IsEmpty to modify the list. It only returns a logical value; it does not remove items or change the list. Use List.RemoveNulls or List.Select to clean the list before testing if needed.
Tips
- Use List.IsEmpty as a guard before any function that fails on empty lists, such as List.First, List.Last, or List.Sum. For example:
if List.IsEmpty(MyList) then null else List.First(MyList). - Combine with List.NonNullCount to check for lists that contain only nulls:
List.IsEmpty(MyList) or List.NonNullCount(MyList) = 0gives a broader "no real data" test. - In the Power Query Editor, you can quickly test List.IsEmpty in the formula bar by creating a blank query and entering
= List.IsEmpty({})(returns true) or= List.IsEmpty({1})(returns false). This is a safe way to see the behavior without changing your main query. - If you are working with grouped data, List.IsEmpty is handy to flag groups that have no items after filtering. Add a custom column with
List.IsEmpty([GroupedRows])and then filter out the true values.
Troubleshooting
If List.IsEmpty returns an error, check the following in order:
- Verify the argument is a list. In the custom column dialog, the formula bar shows the type of each column. If the column is type any or type table, convert it to a list first. For a table column, use Table.ToList or Table.Column to extract a list.
- Handle nulls. If the column contains nulls, wrap the call as shown in Common Mistakes. You can also replace nulls with an empty list using Table.ReplaceValue before testing.
- Check for errors in the source column. If the list column itself contains errors, List.IsEmpty will propagate the error. Use try ... otherwise to catch it:
try List.IsEmpty([MyList]) otherwise false. - Confirm the function name and case. M is case-sensitive: List.IsEmpty, not list.isempty. Also ensure you are using the correct function; List.IsEmpty exists in Power Query M, but similar-sounding functions like List.NonNullCount are different.
- Refresh the query. If the result seems stale, right-click the query and select Refresh, or use Home > Refresh Preview. In Excel, also check that the query is loading to the intended destination.
If you are still stuck, simplify: create a blank query and test List.IsEmpty on a literal list. If that works, the issue is with your column's data type or content, not the function itself.
Frequently Asked Questions
What does List.IsEmpty return for an empty list?
It returns true. For any list with at least one item (including a single null), it returns false.
Can I use List.IsEmpty on a column that contains nulls?
No, directly it will error because null is not a list. Wrap it in an if expression to handle nulls first.
Is List.IsEmpty available in Excel Power Query?
Yes, it is part of the standard Power Query M library in Excel and Power BI. The exact editor labels may differ slightly by version.
How do I check if a list contains only nulls?
List.IsEmpty returns false for a list of nulls. Use List.NonNullCount(MyList) = 0 to test for no non-null items.
Does List.IsEmpty work on tables?
No, it expects a list. Convert a table to a list first with Table.ToList or Table.Column.
What is the difference between List.IsEmpty and List.Count?
List.Count returns the number of items; List.IsEmpty returns a logical value indicating whether the count is zero. List.IsEmpty is slightly more direct for empty checks.