Forum Discussion
Price - Volume Variance Analysis | DAX optimization | Resources Exceeded
Hello, I'm seeking advice on any ways to optimize the following DAX measures to enable the engine to perform the calculation without any visual / report level filter or slicer. On both desktop and publishing to the online service, I receive a resources exceeded error message when it tries to iterate through all 14M order line items YoY, in arriving at the card total without any filter. I believe it's necessary for this calculation to be peformed as a DAX measure, since the stakeholder wants to slice by varying dimensions & granularities impacting whether or not a given product is recurring YoY within the given context and then arrive at its variance allocation to price vs volume, accordingly. Below, I've put in bold font where I may not be following best practice. Appreciate any help!
- Anonymous4 years ago
I may have at least improved the measure with the following update below. The report card & table visuals run quicker without the error message on desktop with this revision, at least. Perhaps, still not ideal, not sure.
Sales Price (Staging) =var PYTDSalesRebate =CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Rebate",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1)var CYTDSalesRebate =CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Rebate",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0)var PYTDSales =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1),0)var CYTDSales =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0),0)var PYTDUnits =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Quantity Shipped]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1),0)var CYTDUnits =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Quantity Shipped]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0),0)var PYTDASP =DIVIDE(PYTDSales, PYTDUnits, 0)var CYTDASP =DIVIDE(CYTDSales, CYTDUnits, 0)return((CYTDASP - PYTDASP) * CYTDUnits) + (CYTDSalesRebate - PYTDSalesRebate)
5 Replies
- AnonymousNot applicable
- v-yanjiang-msft
Community Support
Hi Anonymous ,
According to the formula, you havn't used too complicated function, but there're too many variables in the formula, it spends too much CPU in the calculation. I think this led to the error.
To prevent too heavy calculation in a measure, I suggest you try to break it down into several measures or calculated columns.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Appreciate your response! I'm not sure I agree though that a measure branching approach would be more performant than the variables approach I've taken.
https://www.sqlbi.com/articles/variables-in-dax/
- AnonymousNot applicable
I may have at least improved the measure with the following update below. The report card & table visuals run quicker without the error message on desktop with this revision, at least. Perhaps, still not ideal, not sure.
Sales Price (Staging) =var PYTDSalesRebate =CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Rebate",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1)var CYTDSalesRebate =CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Rebate",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0)var PYTDSales =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1),0)var CYTDSales =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Net Sales]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0),0)var PYTDUnits =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Quantity Shipped]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = -1),0)var CYTDUnits =IF([YTD Period Classification] = "Recurring",CALCULATE(SUM(Orders[Quantity Shipped]),Orders[Volume Rebate Flag] = "Other",DimDate[YTD] = True,DimDate[NbrYearsFromToday] = 0),0)var PYTDASP =DIVIDE(PYTDSales, PYTDUnits, 0)var CYTDASP =DIVIDE(CYTDSales, CYTDUnits, 0)return((CYTDASP - PYTDASP) * CYTDUnits) + (CYTDSalesRebate - PYTDSalesRebate)- v-yanjiang-msft
Community Support
Hi Anonymous ,
Glad you figure it out by yourself. Would you mind accept your reply as solutions? Then we are able to close the thread. More people who have the same requirment will find the solution quickly and benefit here, thank you!
Best Regards,
Community Support Team _ kalyj