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
DRing
Helper V
Helper V

Possible to create a Unique Key when using Direct Query?

I have a data model which has many to many relationships between several tables. I've provided one example below, where the relationship in the model is FACT_CALL_TABLE.Advertisement_ID to DIM_AD_TABLE.Advertisement_ID. This relationship is many-to-many, however the combinaton of Advertisement_ID & Store_Location makes the relationship many-to-one.

Is it possible for me to join Advertisement_ID and Store_Location to create a unique key between both tables?

Capture.PNG

2 ACCEPTED SOLUTIONS
Anand24
Super User
Super User

Hi @DRing ,
You definely can do this in Power BI.
You need to create a calculated column in both tables. This calculated column should concatenate Advertisement_ID and Store_Location. Now join FACT_CALL_TABLE and DIM_AD_TABLE using this new calculated column.

 

Below would be your DAX for Calculated column in FACT_CALL_TABLE:
Unique_Key_Fact_Table = CONCATENATE(FACT_CALL_TABLE[Advertisement_ID], FACT_CALL_TABLE[Store_Location])

 

Below would be your DAX for Calculated column in DIM_AD_TABLE:
Unique_Key_Dim_Table = CONCATENATE(DIM_AD_TABLE [Advertisement_ID], DIM_AD_TABLE [Store_Location])

Now go to model view and join both tables on FACT_CALL_TABLE.Unique_Key_Fact_Table = DIM_AD_TABLE.Unique_Key_Dim_Table

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

View solution in original post

@DRing ,
Yes.

In case you don't want to use CONCATENATE function, you can simply use FACT_CALL_TABLE[Advertisement_ID] & FACT_CALL_TABLE[Store_Location] for concatenating.

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

View solution in original post

4 REPLIES 4
DRing
Helper V
Helper V

Bravo @Anand24 !

Anand24
Super User
Super User

Hi @DRing ,
You definely can do this in Power BI.
You need to create a calculated column in both tables. This calculated column should concatenate Advertisement_ID and Store_Location. Now join FACT_CALL_TABLE and DIM_AD_TABLE using this new calculated column.

 

Below would be your DAX for Calculated column in FACT_CALL_TABLE:
Unique_Key_Fact_Table = CONCATENATE(FACT_CALL_TABLE[Advertisement_ID], FACT_CALL_TABLE[Store_Location])

 

Below would be your DAX for Calculated column in DIM_AD_TABLE:
Unique_Key_Dim_Table = CONCATENATE(DIM_AD_TABLE [Advertisement_ID], DIM_AD_TABLE [Store_Location])

Now go to model view and join both tables on FACT_CALL_TABLE.Unique_Key_Fact_Table = DIM_AD_TABLE.Unique_Key_Dim_Table

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

@Anand24  This can be done while using Direct Query?

@DRing ,
Yes.

In case you don't want to use CONCATENATE function, you can simply use FACT_CALL_TABLE[Advertisement_ID] & FACT_CALL_TABLE[Store_Location] for concatenating.

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

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.

Top Solution Authors
Top Kudoed Authors