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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to calculate a measure with values from two fact tables on the lowest level of granularity?

Tabular model has 2 fact tables:

Sales (fact table)
CustomerId
TimePeriodId
ProductId
<Several another dimensions Ids>
Amount

and

Discount (fact table)
CustomerId
TimePeriodId
ProductId
Discount

Sales table has [ComplexMeasure] measure that uses another measures chain for calculations, in the lowest level it has SUM(Amount).

 

I need to add a new measure with formula = ComplexMeasure x Discount, but I can't use here something like average discount, instead of that I shoud multiply every Amount from the Sales table by corresponding Discount from the Discount table. I can't change ComplexMeasure or measures that used in this measure calculation. And I don't want to re-create all these measures, but with SUM(Sales[Amount] x Discount[Discount]) on the lowest level.

 

Do you have any idea how I could implement that using a DAX expression?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

sumx(summarize(Sales, customer[CustomerId],date[TimePeriodId],Product[ProductId], "_1", sum(Sales[Amount]) , "_2", max(Discount[Discount])),[_1]*[_2])

 

Changes the measure and aggregation as per need

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Try like

sumx(summarize(Sales, customer[CustomerId],date[TimePeriodId],Product[ProductId], "_1", sum(Sales[Amount]) , "_2", max(Discount[Discount])),[_1]*[_2])

 

Changes the measure and aggregation as per need

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Yes, it works. Thank you!

It seems that you query groups all data from Sales and then if the coresponding Discount exists adds value to the result.

I would like to increase the performance of the query by filtering Sales items before grouping operation. Is it possible to have grouped sales only that have link to discount table? Probably I should use RELATEDTABLE in this query, but I can't figure out how to use it. 

saraMissBI
Resolver I
Resolver I

Hi @Anonymous 

 

You can add a calculated column to table Sales to get the corresponding discount for each customer. Then create the following measure:

NewMeasure = CALCULATE(Sales, SUMX([ComplexMeasure] * [CalculatedColumnDiscount])

 

This should do the trick.

 

If my answer solves your problem, please give Kudos and mark as solution 🙂

 

Thank you!

Anonymous
Not applicable

Hi @saraMissBI

It's a very, very, very bad idea to have a measure that would iterate a big fact table and execute CALCULATE against each and every row. The measure will be AGONIZINGLY SLOW and will lead to memory overflow. One should never do it. Apart from that, the measure is syntactically incorrect.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.