Forum Discussion
SMaz
2 years agoFrequent Visitor
Create a custom table from 3 dimensions
Hi all, I would like to create a 3 columns table in Power Query giving the complete combinations from 3 dimensions. E.g.: - Agent : Bob, Cathy, Bernie (actually this list could contain 100 names) ...
- 2 years ago
This is called a Cartesian product or a cross-join.
You can use this method twice for 3 dimensions:
Cross join - Power Query | Microsoft Learn
ThxAlot
2 years agoSuper User
Enjoy elegance of Power Query!
let
Agents = {"Bob","Cathy","Bernie"},
Years = {2021 .. 2023},
Weeks = {1 .. 52},
#"Cartesian Product" =
List.Accumulate(
{Agents,Weeks,Years},
{{}},
(s,c) => List.TransformMany(c, each s, (x,y) => {x} & (if Value.Is(y, type list) then y else {y}))
),
#"To Table" = Table.FromRows(#"Cartesian Product",{"Yr","Wk","Agt"})
in
#"To Table"