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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.