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

Rolling 5 Days Average

Hi, I want to show the rolling 5 days Average like below, it should reset after every 5 days

powerbiexpert22_0-1704787890207.png

 

1 ACCEPTED SOLUTION

@powerbiexpert22

 Rolling 5 Days Average =
IF (
HASONEVALUE ( 'Date'[Date] ),
VAR FirstSelectedDate =
CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED () )
VAR CurrentDate =
VALUES ( 'Date'[Date] )
VAR DaysDifference =
INT ( CurrentDate - FirstSelectedDate )
VAR DayIndex =
MOD ( DaysDifference, 5 )
VAR Dates =
DATESINPERIOD ( 'Date'[Date], CurrentDate, - DayIndex, DAY )
RETURN
COALESCE ( AVERAGEX ( Dates, [Sales Amont] ), [Sales Amont] )
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @powerbiexpert22 
Please try

Rolling 5 Days Average =
IF (
    HASONEVALUE ( 'Date'[Date] ),
    VAR FirstSelectedDate =
        CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED () )
    VAR CurrentDate =
        VALUES ( 'Date'[Date] )
    VAR DaysDifference =
        INT ( CurrentDate - FirstSelectedDate )
    VAR DayIndex =
        MOD ( DaysDifference, 5 )
    VAR Dates =
        DATESINPERIOD ( 'Date'[Date], CurrentDate, - DayIndex, DAY )
    RETURN
        AVERAGEX ( Dates, [Sales Amont] )
)

Hi @tamerj1 , I am getting correct results except for first rows which are showing blank like below

powerbiexpert22_0-1704804881498.png

 

@powerbiexpert22

 Rolling 5 Days Average =
IF (
HASONEVALUE ( 'Date'[Date] ),
VAR FirstSelectedDate =
CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED () )
VAR CurrentDate =
VALUES ( 'Date'[Date] )
VAR DaysDifference =
INT ( CurrentDate - FirstSelectedDate )
VAR DayIndex =
MOD ( DaysDifference, 5 )
VAR Dates =
DATESINPERIOD ( 'Date'[Date], CurrentDate, - DayIndex, DAY )
RETURN
COALESCE ( AVERAGEX ( Dates, [Sales Amont] ), [Sales Amont] )
)

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.

Top Solution Authors