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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors