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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Optimize Dax measure

I have a complex model and the measures created from this model uses USERELATIONSHIP when calculate measure. Hence, I would like to optimize the dax expression.

 

 

[Margin (Current)] = 

Var MaxDate = calculate (max ( FACTProduct[Date]) , ALL(FACTProduct) , CROSSFILTER(DIMProductHierarchy[Scan Product], FACTProduct[Scan_Product], NONE))

RETURN

calculate ( 
sum (FACTSales[Sales]) - sum (FACTProductWaste[Marks]) + ( sum (FACTProduct[Amt]) - sum (FACTProduct[CancelSales]) ) - sum (FACTSales[Cost]) 
, USERELATIONSHIP( Date[Date] , 'DateProduct'[Date] )
, USERELATIONSHIP(DateProduct[Concat],FACTSales[Concat] )
, USERELATIONSHIP(Product[Concat],FACTProductWaste[Concat] )
, USERELATIONSHIP(DateProduct[Concat],FACTProduct[Concat] )
, USERELATIONSHIP(DIMPromo[ID],DateProduct[ID])
, 'DatePromo'[Date] <= MaxDate ) 

 

 

I using DAX studio to time to run the above Dax, it took 2427ms as shown below: Capture2.PNG

How can I optimize the dax

1 REPLY 1
v-janeyg-msft
Community Support
Community Support

Hello, @Anonymous 

 

The code basically has nothing to optimize. Since measure will automatically change in the visual according to the context, it's not sure whether some conditions in your code are not necessary and can be deleted.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.