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
mrbajana
Helper III
Helper III

Rolling Average considering Blank Dates

I have a model with the Fact table and the date dimension. How can I rolling average by n days considering the dates that do not have sales included within a 7-day moving average, for example?

 

2023-12-08_15h27_17.png

 

I used this formula but it only consider days with sales 

Media Movil 7 D =
VAR LastTransactionDate = MAX(Fecha[Fecha])
VAR AverageDay = 7
VAR PeriodInVisual =
FILTER(
    ALL(
        Fecha[Fecha]
    ),
    AND(
        Fecha[Fecha]> LastTransactionDate - AverageDay,
        Fecha[Fecha] <= LastTransactionDate
    )
)
VAR OutPut =
CALCULATE(
    AVERAGEX(
        Fecha,
        [Ventas]
    ),
    PeriodInVisual
)
RETURN
OutPut
2 ACCEPTED SOLUTIONS
CoreyP
Solution Sage
Solution Sage

Try replacing blanks with 0.

 

Ventas = IF( ISBLANK(SUM([value])), 0, SUM([Value]) )

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This pattern should work

Measure = divide(calculate([Amount],datesbetween(calendar[date],min(calendar[date])-6,max(calendar[date]))),7)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This pattern should work

Measure = divide(calculate([Amount],datesbetween(calendar[date],min(calendar[date])-6,max(calendar[date]))),7)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CoreyP
Solution Sage
Solution Sage

Try replacing blanks with 0.

 

Ventas = IF( ISBLANK(SUM([value])), 0, SUM([Value]) )

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.