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
lvallinoto
Frequent Visitor

Divide 2 columns from different tables in a Many to Many relationship

Hello,

 

I have a scenario where I have to divide 2 column, one in one table and the other in another table, which are linked by a Many-to-Many Relationship, and I was hopping to get some help from you Dax geniuses out there, please.

 

Quick explanation of the scenario : I have a transactions table, with sales, and these sales are in many different currencies. To convert them to a single currency, we have to divide the sales by the rate, which is in a second table rates.

There are 2 types of rates : an average rate per month, and an average rate per year. The link between the 2 tables is the period, and the currency. The relationship between the 2 tables is many to many ( Check model , please )

 

What I have tried so far: I could make it work, in 2 different ways, but none completely satisfying :

1 ) Dax expression with SumX :

Dividing the sum of sales by the sum of rates ( I must always have one selected rate type, so it's ok to sum the rates )

CalculatedValue = Sum( 'Transactions'[Sales] ) /Sum( 'Rates'[RateValue] )
Then applying a sumx on the Rate table :
SalesRateType = SUMX(VALUES('Transactions'[KeyColumn]), [CalculatedValue])

This works, but the performance is terrible. I have a transactions table with millions of records. Takes almost 1 minute to calculate YTD.

 

2 ) Forcing a many to 1 relationship :

If I apply some modeling to the tables, I can make it a 1 to Many relationship and create a calculated column, which will give a good performance. But that involves joining both tables, and it takes ages, even with Chris Webb's ideas, it will still take more than 1 hour to join the tables.

 

What I would like to know: Is there any other way of doing this? I'd really appreciate some ideas that I can test.

 

Simplified Model:


Sales:

PeriodCurrencySalesKeyColumn
202001USD55202001USD
202001EUR13202001EUR
202001GBP7202001GBP
201904USD65201904USD
201904EUR27201904EUR
201904GBP96201904GBP
202001GBP33202001GBP
202001EUR44202001EUR


Rates:

RateTypeKeyColumnRateValue
AvgMonthRate202001USD55
AvgMonthRate202001EUR13
AvgMonthRate202001GBP7
AvgMonthRate201904USD65
AvgMonthRate201904EUR27
AvgMonthRate201904GBP96
AvgAnnualRate201904USD55
AvgAnnualRate201904EUR13
AvgAnnualRate201904GBP7
AvgAnnualRate202001USD65
AvgAnnualRate202001EUR27
AvgAnnualRate202001GBP96

 

Expected Results:

PBI Scenario.gif

 

Thanks in advance!

 

2 REPLIES 2
lbendlin
Super User
Super User

What if you keep your annual rates and your monthly rates in different tables?

hi @BIBen 

 

I have tried that approach as well. But then you need a conditional measure and an extra table with a single column to calculate sales. Sometimes they add / remove rate types, so I'd like to keep it dynamic if possible.

 

I have good experience with data modeling, but I'm relatively new to power BI, so I'm just checking if there's some smart way of sorting this I'm not aware of.

 

If I'm doing the right things and it is what it is, I'll mark your answer as correct, thanks

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