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
powerbiexpert22
Post Patron
Post Patron

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors