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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Deepak_
Helper I
Helper I

Crating a custom relationship between two tables

Hi Community Members,


I am looking to create a custom relationship between two tables. The tables I use are the pricing table and the sales table.
I have to perform some pricing calculations in the sales table based on the minimum and maximum range columns of the pricing table.

Initially, I manually created a pricing key in the pricing table based on the amount range and a custom column in the sales table as follows:

if [#"Amount"] >=0 and [#"Amount"] <= 24999 then "0-24999" else if [#"Amount"] >= 25000 and [#"Amount"] <= 249999 then "25000-249999" else if [#"Amount"] >= 250000 and [#"Amount"] <= 499999 then "250000-499999" else if [#"Amount"] >= 500000 and [#"Amount"] <= 749999 then "500000-749999" else if [#"Amount"] >= 750000 and [#"Amount"] <= 999999 then "750000-999999" else if [#"Amount"] >= 1000000 and [#"Amount"] <= 1249000 then "1000000-1249000" else if [#"Amount"] >= 1250000 and [#"Amount"] <= 100000000 then "1250000-10000000" else null

But the values I created key upon are going to change in the future. So I want to make sure the key I am using for the relationship dynamic. 


Is there a way in Power BI to make this custom key dynamic to adapt to future changes? I want to establish a flexible relationship between the two tables.

Thanks in advance

 

 



1 ACCEPTED SOLUTION

No. A foreign key is a deterministic relationship between records. 
You can derive key values from other columns as you are doing. So you could add year and month to your key, if you have the equivilent on your pricing table. But the one record will still only have one value at a time. 

View solution in original post

6 REPLIES 6
Data-estDog
Resolver II
Resolver II

I would need examples of the data sets (sanitized if not already). But I suspect I would not invent a releationship in this case (Again, I don't know what calculations you are doing). I imagine you would want your relationship to be based on product or service (what ever you are pricing and selling). Then you RELATED/RELATEDTABLE to perform your calculations based on the min/max range columns. 

Hi @Data-estDog,

This is the pricing table I am using. "Pricing_Key" is the custom column I created by merging the Volume minimum and maximum columns and using "-" as the delimiter.

Deepak__2-1699250672543.png

And this is the sales table I am using:

Account IDCompany NameYearMonthAmountAmount_Key
12254Company A2020151200-24999
12537Company B20209248780-24999
29954Company C2020710000024999-249999
52954Company D202011500000500000 - 749999


"Amount_Key" is the key I have created based on the amount range cuz I want to charge customers by the amount they belong to. However, the pricing table column's values will not remain the same. 
So, the relationship I have created will break in the future. Is there a way to solve this? 

 

This sound more like a transaction system problem (logic driving pricing decision). The logic for this should be in the source system database and/or associated app. 

 

I say this because if you want, for instance, company A to have a range key of "0-24999" now. But then 6 months from now they increase their volume, and their key would change to (for example) "500000 - 749999". Your probem is that all the old records were generated prices using the old range. 

 

I suppose you could be working in an environment where they want you to hand them a report of customers and last months volume so they know how to input sales into the system. In that case, just make the Year/Month (Period) part of the table unique key, and instead of just adding the range, show the multiplier too. The AmountKey and multiplier should never change cause it is hard wired to the company/account and period. 

 

Account IDCompany NamePeriodAmountAmount_Key

Pricing muliplier

12254Company A202001 51200-249991
12537Company B202009 248780-24999.95
29954Company C202007 10000024999-249999.93
52954Company D202011 500000500000 - 749999.91

 

Edit: I noticed after I posted you said that pricing table values will change with time. To me this really scream ETL/ELT logic into your data hub/warehouse/lake. Your pricing table should have effective dates. It is a slowly changing dimension at this point.

Yes, I was also thinking the same. For making custom relationships at least one column's value should be constant. Still, I was wondering If there is a way to make the key dynamic ?

No. A foreign key is a deterministic relationship between records. 
You can derive key values from other columns as you are doing. So you could add year and month to your key, if you have the equivilent on your pricing table. But the one record will still only have one value at a time. 

Ok, I understand. Thanks for your help @Data-estDog.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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