Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Power Query Cross Join

I have the following two tables in Power Query (Product and Region)

 

Product
a

b

 

CountryAreaTownHouse
EnglandTyne and WearSunderlandA1
EnglandTyne and WearSunderlandA1
ScotlandAyrshireAyrW1
ScotlandAyrshireAyrW2

 

I want to be able to cross join - show me all product for each area  - can anyone help e.g.

 

CountryAreaTownHouseProduct
EnglandTyne and WearSunderlandA1a
England

Tyne and Wear

SunderlandA1a
ScotlandAyrshireAyrW1a
ScotlandAyrshireAyrW2a
EnglandTyne and WearSunderlandA1b
EnglandTyne and WearSunderlandA1b
ScotlandAyrshireAyrW1b
ScotlandAyrshireAyrW2b
  • Hi Anonymous

    you need to add a new column to the Region table, this column would contain the Product table, and then you'd expand this new column

     

     

8 Replies

  • Hi,

     

    There's also other several ways to do this. 

     

    Method 1: The easiest way to do a crossjoin is to put the table you want to crossjoin, in a custom column. Just write

     

    = TableName

     

    You can then expand the column to get your result. The downside is that this method is slow. 

     

    Method 2: The faster method, is to add a join column to both tables. You can add a dummy value in this column. For example the number 1. Then join the tables together based on this join column. Delete the join column after cross joining the table. 

     

    More details on both method you can find on my blog at: Understanding Join Types in Power Query - BI Gorilla

     

    Enjoy!

     

     

    --------------------------------------------------

    @ me in replies or I'll lose your thread

     

    Master Power Query M? -> https://powerquery.how

    Read in-depth articles? -> BI Gorilla

    Youtube Channel: BI Gorilla

     

    If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

  • To create a crossjoin you can either use: 

     

    - Add a helper column in the two tables you want to cross join, and input the same value. Then perform a merge on these columns. It creates a crossjoin

    - Reference the table name directly in a custom column -> this also creates a crossjoin. More details you can find here; 

     

    Create All Unique Combinations From Multiple Columns (gorilla.bi)

     

    --------------------------------------------------

    @ me in replies or I'll lose your thread

     

    Master Power Query M? -> https://powerquery.how

    Read in-depth articles? -> BI Gorilla

    Youtube Channel: BI Gorilla

     

    If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

  • Hi Anonymous

    you need to add a new column to the Region table, this column would contain the Product table, and then you'd expand this new column

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      I have tried to create a join in Power Query but there is no field to join on.

       

      How can I add a new column with the product table data?

      • Stachu's avatar
        Stachu
        Community Champion

        add a new column and type 

        = Product

        (where Product is the name of your product table), then expand the columns