Forum Discussion
How to Optimize my Complex dax query
Just looking at the end of your expression, I see two issues.
VAR _AbsoluteDiff = SUMX(VALUES(ARTICLE[Article]),Calculate(ABS(ForecastQty-ActualQty)
))
// the SUMX is likely not doing what you expect. you are referencing variables ForecastQty and ActualQty. those are being evaluated once and then reused for however many distinct Articles you have (not calculated for each).
VAR
_Accuracy = IF(ActualQty,ABS(
1- DIVIDE(_AbsoluteDiff,ActualQty,0)))
// ActualQty is a variable that returns a number. the first argument of the IF should be a true/false
Hard to tell w/o seeing your data but I suspect you could create a table variable with ADDCOLUMNS(SUMMARIZE(... where you add columns for forecast and actual qty, and then apply your logic in the SUMX over that table variable.
Pat