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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
joshua1990
Post Prodigy
Post Prodigy

Exclude blank weeks from Rolling Average

hey experts!

I am using the Rolling AVG pattern from SQLBI and facing a minor issue now:

AVG R6M = 
VAR NumOfMonths = 6
VAR LastCurrentDate =
    MAX ( 'Calendar'[Date] )
VAR Period =
    DATESINPERIOD ( 'Calendar'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[MonthOffset] ),
            [Sales]
        ),
        Period
    )
VAR FirstDateInPeriod = MINX ( Period, 'Calendar'[Date] )
VAR LastDateWithSales = MAX ( 'Calendar'[Date] )
RETURN
   IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

I am using a bar chart per week that shows me the actual sales. Not every week has a value since not every week we have sales.

Now using the rolling average I get values for the blank weeks - what makes sense.

But I would like to exclude these weeks. How?

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@joshua1990 If you use Better Rolling Average this is quite simple:

Better Rolling Average = 
    VAR __EndDate = MAX('Table'[Date])
    VAR __MonthsAgo = EOMONTH(__EndDate, -6)
    VAR __StartDate = DATE(YEAR(__MonthsAgo), MONTH(__MonthsAgo), 1)
    VAR __Table = 
      FILTER(
        SUMMARIZE(
            FILTER(ALL('Table'),[Date]>=__StartDate && [Date]<=__EndDate),
            'Table'[Month],
            "__Value",[Sales])
        ),
        "__Value" <> BLANK()
      )
    VAR __Result = AVERAGEX(__Table,[__Value])
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@joshua1990 If you use Better Rolling Average this is quite simple:

Better Rolling Average = 
    VAR __EndDate = MAX('Table'[Date])
    VAR __MonthsAgo = EOMONTH(__EndDate, -6)
    VAR __StartDate = DATE(YEAR(__MonthsAgo), MONTH(__MonthsAgo), 1)
    VAR __Table = 
      FILTER(
        SUMMARIZE(
            FILTER(ALL('Table'),[Date]>=__StartDate && [Date]<=__EndDate),
            'Table'[Month],
            "__Value",[Sales])
        ),
        "__Value" <> BLANK()
      )
    VAR __Result = AVERAGEX(__Table,[__Value])
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @joshua1990 

Have you resolved the issue? If yes, kindly mark the helpful answer as a solution if you feel that makes sense. Welcome to share your own solution. More people will benefit from the thread.

Should you have any further questions, feel free to reach out.
Thank you for being a part of the Microsoft Fabric Community Forum!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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