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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Performance issue to find Rolling52WeekAverage from the Measure value using by (SUMX & AVERAGEX)

Hi,

 

I am using the following two DAX formulas to find an average of Rolling52Weeks from the Measure value, the results are getting correctly but performance is very slow.  I just filtering the prior 52 weeks from the calendar and applying into SUMX/ AVERAGEX in order to get a result. 

 

Can anyone please help me if there is any way to replace the SUMX/ AVERAGEX for the below scenarios or can please confirm if I made any logical mistaken on the below DAX.

 

Appreciate if you join with me to get resolved.

 

Rolling52WeekAverage:=

var Filtervalue =
FILTER(ALL(CalendarWeekly),AND(CalendarWeekly[CalendarWeeklySkey] <=max(CalendarWeekly[CalendarWeeklySkey]),CalendarWeekly[FiscalWeekCloseDt] > max(CalendarWeekly[FiscalWeekCloseDt]) - 364 && Fact[Average_FlagNew] <> 3))

var Tempcnt =
COUNTROWS ( Filtervalue )

var rd = SUMX(Filtervalue ,Fact[Measure Value])

return DIVIDE(rd, Tempcnt )

 

Rolling52WeekAverage:=

var Filtervalue =
FILTER(ALL(CalendarWeekly),AND(CalendarWeekly[CalendarWeeklySkey] <=max(CalendarWeekly[CalendarWeeklySkey]),CalendarWeekly[FiscalWeekCloseDt] > max(CalendarWeekly[FiscalWeekCloseDt]) - 364 && Fact[Average_FlagNew] <> 3))

return AVERAGEX(FILTER(Filtervalue,IF(Fact[Average_FlagNew] <> 3 ,1)),Fact[Measure Value])

 

Regards,

 

Raj

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

I am not sure if the SUMX or AVERAGEX causes the issue, check your data model with best practices https://powerbi.microsoft.com/en-us/blog/best-practice-rules-to-improve-your-models-performance/

 

Check the following modified measure.

Rolling52WeekAverage = 
var _skey = _CalendarWeekly[CalendarWeeklySkey]
var _close = _CalendarWeekly[FiscalWeekCloseDt]- 364
var Filtervalue =
    FILTER(
        ALL(CalendarWeekly[CalendarWeeklySkey],CalendarWeekly[FiscalWeekCloseDt]),
        CalendarWeekly[CalendarWeeklySkey] <=_skey &&
        CalendarWeekly[FiscalWeekCloseDt] > _close  && 
        [Average_FlagNew] <> 3
    )

var Tempcnt = COUNTROWS ( Filtervalue )
var rd = SUMX(Filtervalue ,[Measure Value])
    return 
    DIVIDE(rd, Tempcnt )



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@Anonymous 

I am not sure if the SUMX or AVERAGEX causes the issue, check your data model with best practices https://powerbi.microsoft.com/en-us/blog/best-practice-rules-to-improve-your-models-performance/

 

Check the following modified measure.

Rolling52WeekAverage = 
var _skey = _CalendarWeekly[CalendarWeeklySkey]
var _close = _CalendarWeekly[FiscalWeekCloseDt]- 364
var Filtervalue =
    FILTER(
        ALL(CalendarWeekly[CalendarWeeklySkey],CalendarWeekly[FiscalWeekCloseDt]),
        CalendarWeekly[CalendarWeeklySkey] <=_skey &&
        CalendarWeekly[FiscalWeekCloseDt] > _close  && 
        [Average_FlagNew] <> 3
    )

var Tempcnt = COUNTROWS ( Filtervalue )
var rd = SUMX(Filtervalue ,[Measure Value])
    return 
    DIVIDE(rd, Tempcnt )



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Your DAX logic works fine and it  is faster than earlier logic. 

 

Thank you so much Fowmy!!

 

Regards,

 

Rajkumar

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.