List.IsEmpty
ListReturns true if the list contains no elements.
Syntax
List.IsEmpty(list as list) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list to check. |
Return Value
logical — True if the list has zero elements; false otherwise.
Remarks
List.IsEmpty returns true if the list has zero items. It is equivalent to List.Count(list) = 0 but expresses intent more clearly. The primary use case is defensive branching: before calling List.First, List.Single, or any aggregation function on a filtered list, check List.IsEmpty to avoid errors when no results exist.
A list containing only null values is not empty — it has elements, they are simply null. An empty list is one with no elements at all: {}.
Compared to List.Count, List.IsEmpty does not need to count all elements — it only needs to check for the existence of any element, which can be more efficient on large lazy lists. For the inverse check, use not List.IsEmpty(list) rather than comparing count to a number.
Examples
Example 1: Empty list
List.IsEmpty({})Result | |
|---|---|
| 1 | TRUE |
Example 2: Non-empty list
List.IsEmpty({1, 2, 3})Result | |
|---|---|
| 1 | FALSE |
Example 3: Check if a filter returned results before accessing
let
Values = {10, 20, 30},
Filtered = List.Select(Values, each _ > 50),
Result = if List.IsEmpty(Filtered) then null else List.First(Filtered)
in
ResultResult | |
|---|---|
| 1 | null |