Forum Discussion
Anonymous
3 years agoNot applicable
Optimize DAX Code
Hello everyone, This fourmula count unique number of stores in time window of 42 days backward from the selected date in slicer. However formula runs pretty slow when i change the name of product. ...
ppm1
3 years agoSolution Sage
I looked at this for a bit and ran out of time for tonight. Not sure I fully understand the logic of your existing measure. The measure below is much more performant (76 ms vs 3600 ms) and does what I think you are looking for but does not match all of your current values. If you know your current values are correct, perhaps this approach will give you some ideas to tweak it.
ND daily 2 =
VAR selDateEnd =
SELECTEDVALUE ( tSelectedDates[WorkingDate] )
VAR selDateStart = selDateEnd - 42
VAR Summarized =
CALCULATETABLE (
SUMMARIZE ( FactND, FactND[StoreID], "cMaxDate", MAX ( FactND[VisitTime] ) ),
FactND[VisitTime] <= selDateEnd
&& FactND[VisitTime] >= selDateStart
)
RETURN
CALCULATE (
[BaseModelCount],
TREATAS ( Summarized, FactND[StoreID], FactND[VisitTime] )
)Pat
Anonymous
3 years agoNot applicable
ppm1 ,
I modified your formula to return the desired result, the trick is in using returning all rows before grouping by the maximum date.
ND daily 2 =
VAR selDateEnd =
SELECTEDVALUE ( tSelectedDates[WorkingDate] )
VAR selDateStart = selDateEnd - 42
VAR Summarized =
GROUPBY(
FILTER(ALLEXCEPT(FactND,FactND[ProductID]),FactND[VisitTime]<=selDateEnd&&FactND[VisitTime]>=selDateStart),
FactND[StoreID],"MaxVisitDate",MAXX(CURRENTGROUP(),FactND[VisitTime]))
RETURN
CALCULATE (
[BaseModelCount],
TREATAS ( Summarized, FactND[StoreID], FactND[VisitTime] )
)