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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Prats_Kul
Frequent Visitor

Calculate average of last n weekdays

I am trying to create a measure which gives the average of last 2 weekdays(Last 2 Mondays/ Tuesdays and so on). Sample data are given below.

 

I am trying to modiy this measure but dont know how CALCULATE([Sessions],DATESINPERIOD('Calendar'[Date],MAX('Calendar'[Date]),-2,DAY))

 

 

 

DateWeekday|Device Category|Sessions|Average of Last 2 Weekdays

17 October 2017Tuedesktop298 
17 October 2017Tuemobile3,798 
18 October 2017Weddesktop586 
18 October 2017Wedmobile7,942 
19 October 2017Thudesktop472 
19 October 2017Thumobile5,432 
20 October 2017Fridesktop394 
20 October 2017Frimobile5,491 
21 October 2017Satdesktop431 
21 October 2017Satmobile6,207 
22 October 2017Sundesktop441 
22 October 2017Sunmobile6,164 
23 October 2017Mondesktop754 
23 October 2017Monmobile5,503 
24 October 2017Tuedesktop777538
24 October 2017Tuemobile5,2534526
25 October 2017Weddesktop645615.5
25 October 2017Wedmobile4,9066424
2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

Hi @Prats_Kul

 

Try this MEASURE

 

Measure =
AVERAGEX (
    TOPN (
        2,
        ALLEXCEPT ( TableName, TableName[Device Category], TableName[Weekday] ),
        CALCULATE ( VALUES ( TableName[Date] ) ), DESC
    ),
    CALCULATE ( SUM ( TableName[Sessions] ) )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

Hi @Prats_Kul

 

Try this MEASURE

 

Measure =
AVERAGEX (
    TOPN (
        2,
        ALLEXCEPT ( TableName, TableName[Device Category], TableName[Weekday] ),
        CALCULATE ( VALUES ( TableName[Date] ) ), DESC
    ),
    CALCULATE ( SUM ( TableName[Sessions] ) )
)

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.