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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Harry_Tran
Helper III
Helper III

Rolling average missing values

Hello everyone, I need help to calculate 7 Days Rolling Average for missing data.

I have MAIN table with Date, Users, Points, Categories, Subcategories, and Products columns. I also hace Calendar table.

My Measures:

Avg_Point_per_User_per_Day = SUM(MAIN[Points])

                                                           /

                                                           DISTINCTCOUNT(MAIN[User])

                                                           /

                                                           DISTINCTCOUNT(MAIN[Date])

7_Days_Rolling_Avarage =

                                          VAR Last_Date = LASTDATE(Calendar[Date].[Date])

                                          VAR RollingAvg =

                                                        AVERAGEX (

                                                                      DATEBETWEEN (Calendar[Date].[Date],

                                                                      DATEADD (Last_Date, -7,DAY),

                                                                      Last_Date), [Avg_Point_per_User_per_Day]

RETURN IF (Last_Date > TODAY() , BLANK(), RollingAvg)

Harry_Tran_0-1607616059219.png

 

The issue that I have is

When I apply Categories to the table, I have some data that do not have data. So, The [7_Days_Rolling_Avarage] returns (47+ 68 + 43 + 49 + 65)/5 ; (68 + 43 + 49 + 65 + 59)/5

What I expect is it would skip the missing date and return (47+ 68 + 43 + 49 + 65 + 59 + 62)/7

I came with another measure

Rolling_7_Days =

              VAR Sevendays = CALCULATETABLE ( TOPN (7,

                                                        SUMMARIZE (MAIN, MAIN [Date],

“point”, SUM (MAIN [POINTS]) / DISTINCTCOUNT (MAIN [Users])),

MAIN[Date] , DESC),

FILTER (ALL (MAIN[Date]) , MAIN[Date] <= SELECTEDVALUE (MAIN[Date])))

              RETURN

                      SUMX( Sevendays, [points]) / COUTROWS (Sevendays)

This one worked but it took almost 10 minutes to pull out the data.

Please help,

Thank you

 

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Harry_Tran ,

 

Try this:

TopN_Rolling_7days 2 =
VAR t =
    CALCULATETABLE (
        TOPN (
            7,
            SUMMARIZE (
                MAIN,
                MAIN[Category],
                MAIN[Date],
                "Avg_", [Avg_Point_per_User_per_Day]
            ),
            [Date], DESC
        ),
        FILTER ( ALLSELECTED ( MAIN[Date] ), MAIN[Date] <= MAX ( MAIN[Date] ) )
    )
RETURN
    SUMX ( t, [Avg_] ) / COUNTROWS ( t )

rolling.JPG

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

View solution in original post

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Harry_Tran ,

 

Try this:

TopN_Rolling_7days 2 =
VAR t =
    CALCULATETABLE (
        TOPN (
            7,
            SUMMARIZE (
                MAIN,
                MAIN[Category],
                MAIN[Date],
                "Avg_", [Avg_Point_per_User_per_Day]
            ),
            [Date], DESC
        ),
        FILTER ( ALLSELECTED ( MAIN[Date] ), MAIN[Date] <= MAX ( MAIN[Date] ) )
    )
RETURN
    SUMX ( t, [Avg_] ) / COUNTROWS ( t )

rolling.JPG

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

MFelix
Super User
Super User

Believe this is duplicated with:

 

https://community.powerbi.com/t5/Desktop/7-days-rolling-average-for-missing-values/td-p/1539228/page...


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





DataInsights
Super User
Super User

This appears to be a duplicate of the post below:

 

https://community.powerbi.com/t5/Desktop/7-days-rolling-average-for-missing-values/m-p/1549438#M6337... 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors