List.Difference
The items of one list that a second list does not take away, one for one.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.Difference(list1 as list, list2 as list, optional equationCriteria as any) as list
| Parameter | Type | Description |
|---|---|---|
list1 | list | The list to take from. |
list2 | list | The values to take away. |
equationCriteria | any optional | How two values count as equal: a comparer or a key function. |
Returns
list. What is left of list1, in its order.
Remarks
- Each value of list2 takes away one matching item: a value that list1 holds twice and list2 once is left once.
List.RemoveItemsremoves every occurrence.
Examples
Products not yet shipped
List.Difference({"Coffee", "Tea", "Milk", "Juice"}, {"Tea", "Juice"})
{"Coffee", "Milk"}
One of two teas shipped
List.Difference({"Tea", "Tea", "Milk"}, {"Tea"})
{"Tea", "Milk"}