Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SMaz
Regular 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)

- Year : 2021, 2022, 2023

- Week : 1 to 52

 

The result should give something like :

YearWeekAgent
20211Bob
20211Cathy
20211Bernie
20212Bob
20212Cathy
20212Bernie
20213Bob
20213Cathy
20213Bernie

 

and so on, until 2023; 52; Bernie.

 

Any tips?

Thanks a lot !

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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

View solution in original post

3 REPLIES 3
ThxAlot
Super User
Super 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"

ThxAlot_0-1695243962044.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



AlexisOlson
Super User
Super User

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

So easy 🙂

Thanks a lot !

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors