List.Union
Several lists put together so that a value they share isn't doubled, in the order the values first appear.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.Union(lists as list, optional equationCriteria as any) as list
| Parameter | Type | Description |
|---|---|---|
lists | list | A list of lists. |
equationCriteria | any optional | How two values count as equal: a comparer or a key function. |
Returns
list. The values of the first list, then those of each next list that are not there yet.
Remarks
- The lists are counted like bags: a value appears in the answer as often as in the list where it is most frequent. Two Oslos in one list and one in another give two;
List.Distinctafterwards leaves one.
Examples
Every city with a shop or a warehouse
List.Union({{"Oslo", "Bergen"}, {"Bergen", "Tromsø"}})
{"Oslo", "Bergen", "Tromsø"}
A value twice in one list
List.Union({{"Oslo", "Oslo", "Bergen"}, {"Bergen"}})
{"Oslo", "Oslo", "Bergen"}
Related functions
List.Intersect, List.Difference, List.Combine, List.Distinct.