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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How To Get A Sliceable Rolling 14-day Average Sales Count By Day?

I am attempting to create a measure that shows the 14-day average sales count over time by day. Given the sensitivity of the data I am handling, I cannot post that data here, but here is an analogous example of the sales of a generic product that models what I am trying to do:

 

Sale DateBrandColorSize
01/01/2001ARedSmall
01/05/2001ABlueMedium
01/05/2001ABlueLarge
01/14/2001BBlueMedium
01/16/2001BRedSmall
01/17/2001AYellowLarge
01/19/2001ABlueLarge
01/22/2001BBlueMedium
01/24/2001ABlueLarge
01/24/2001ABlueLarge
01/27/2001BBlueSmall
01/28/2001BRedLarge
01/31/2001BYellowSmall

 

I want to be able to count the average number of units sold per brand the last 14 days for every day in the date range. Further, there can be and often will be more than one sale on any given day in the dataset. My end goal is I want to be able to filter with slicers on different details. I may want to see a stacked line graph of the 14-day rolling average with brand sales broken down by brand in the legend and a slicer for color and size, and the average count must adjust according to the slicer selection. For example, if I set the slicer to blue only, it should show a rolling average count of sales for brand A of 0.21 and brand B of 0.07 units sold per day (given 3 and 1 sold respectively over 14 days, from 01/01/2001 through 01/14/2001).

When I attempt this in DAX like so:

 

 

14-Day Rolling Average Sales Count= 
COUNTROWS (
    FILTER (
        'Product Sales',
        'Product Sales'[Sale Date] <= 'Product Sales'[Sale Date]
            && 'Product Sales'[Sale Date] > DATEADD ( 'Product Sales'[Sale Date], -14, DAY )
    )
) / 14

 

 

Expectedly, I get only the current day's sales count divided by 14. How can I indicate in DAX that I want to look to previous dates up to 14 days back on any given date and get the average daily sales count? Again, I want to be able to maintain live filterability of the average with slicers. That is why I try to let the outer filters apply in the next example.

 

I attempt this, but the count fails and the graph shows up as blank.

 

 

14-Day Rolling Average Sales Count =
CALCULATE (
    COUNTROWS ( 'Product Sales' ),
    KEEPFILTERS (
        FILTER (
            ALL ( 'Product Sales' ),
            COUNTX (
                KEEPFILTERS (
                    FILTER (
                        'Product Sales',
                        EARLIER ( 'Product Sales'[Sale Date] ) < 'Product Sales'[Sale Date]
                            && EARLIER ( 'Product Sales'[Sale Date] ) >= 'Product Sales'[Sale Date] - 13
                    )
                ),
                'Product Sales'[Brand]
            )
        )
    )
) / 14

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Using a Date table

 

14-Day Rolling Average Sales Count = CALCULATE(AverageX(Values('Date'[Date]),calculate(Countrows('Product Sales')))
,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-14,DAY))

 

Rolling Days Formula: https://youtu.be/cJVj5nhkKBw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Using a Date table

 

14-Day Rolling Average Sales Count = CALCULATE(AverageX(Values('Date'[Date]),calculate(Countrows('Product Sales')))
,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-14,DAY))

 

Rolling Days Formula: https://youtu.be/cJVj5nhkKBw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks! Perfect. Another problem I was also having was my date dimension had a date range extending outside of the supported range of Power BI. Once I added a filter to pare it down to size, it worked.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.