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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
siva_powerbi
Helper IV
Helper IV

Cross join 2 columns and add resultant to same table as new column

Hello Experts

 

I am beginner in Power BI.

 

I have a requirement to create a cross join between 2 columns of a table and add the resultant cross join as another column in same table. I have generated the cross join but this  can be created as a new table but unable to create the cross join in the same table:

 

Data source:

 

Test1Test2Test3test4
11Jobs1
11Jobs11
12Jobs21
13Jobs32
13Jobs41
14Jobs51

 

I want to create the cross join for columns Test2 and Test3 and add the result as column5.

 

Code I have used

 

Table 4 = ADDCOLUMNS('Sheet2 (2)',"C1",CROSSJOIN(SELECTCOLUMNS(Sheet2,"col1",Sheet2[Test1]), SELECTCOLUMNS(Sheet2,"col2",Sheet2[Test2])))
 
Getting Error:
 
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
 
Any help would be saving my day, trying for couple of days now
5 REPLIES 5
amitjzaveri
Resolver II
Resolver II

@siva_powerbi  I guess CROSSJOIN is not the right solution if you're looking for some output in a new column. CROSSJOIN multiples values which result in more rows e.g. 5 rows x 5 rows will result in 25 rows. You can check the official documentation for understanding: https://docs.microsoft.com/en-us/dax/crossjoin-function-dax

 

If you can let know what output is expected in the last/new column then probably I can suggest further.

 

Cheers!

Thanks for the reply.

My original requirement is to create a cross join between all columns.

First Cross join: col1,col2

Second Cross Join: col2,col3

Third Cross Join: col3,Col4

Need these result sets either in the same table or different table but I need these cross join result set as columns in a table.

Can you please suggest me a approach.

@siva_powerbi  In case you want to do a cross join for each column then I would store each column in a separate table

Col1 in Table1

Col2 in Table2

Col3 in Table3

Col4 in Table4

(Hint: You can import table in Power Query and create 3 more copies. Then only keep 1 column in each table)

 

Note ideally CROSSJOIN is done after keeping distinct values in each column. I could see duplicate values in your data which might not be desired.

 

Then write the following query in DAX. Here I have written UNION to keep output in a single table; you can keep separate if required.

 

UNION(

CROSSJOIN('Table1','Table2'),
CROSSJOIN('Table2','Table3'),
CROSSJOIN('Table3','Table4')
)

 

 

Thanks Amit for solution...

Sorry for the later reply.

Your code actually appends the rows of all 3 tables instead I need the columns to be added side by side in a single table.

May I know if the solution I am looking is practically possible?

Thanks

Siva

One more point - CROSSJOIN can also be done at model level using Power Query. Please check below link

 

https://blog.crossjoin.co.uk/2014/06/02/join-conditions-in-power-query-part-1/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.