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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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