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
v_mark
Helper V
Helper V

How to Exclude Blanks in Rolling Average

I was working on a rolling average for 30 days, everything works fine but I need to exclude those blanks

 

Rolling Average Changes per Day = 
VAR NumDays = 30
VAR RollingSum = CALCULATE([Ticket Total], 
DATESINPERIOD('Date'[Date], LASTDATE('Date'[Date]), -NumDays, DAY))

RETURN
DIVIDE( RollingSum, NumDays, BLANK())

 

My concern is it goes through each date on my date table(see right table) 
regardless if there is an input (see left). 
Is there a way to control that behavior and just leave those blanks as blanks as part of the moving average? 

v_mark_0-1638545867039.png

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @v_mark ,

Please try to update your measure [Rolling Average Changes per Day ] as below and check whether it can get your expected result.

Rolling Average Changes per Day =
VAR NumDays = 30
VAR RollingSum =
    CALCULATE (
        [Ticket Total],
        DATESINPERIOD ( 'Date'[Date], LASTDATE ( 'Date'[Date] ), - NumDaysDAY )
    )
RETURN
    IF (
        ISBLANK ( [Ticket Total] ),
        BLANK (),
        DIVIDE ( RollingSumNumDaysBLANK () )
    )

If the above one can't help you get the correct result, please provide some sample data(exclude sensitive data) and your expected result with calculation logic and special examples. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @v_mark ,

Please try to update your measure [Rolling Average Changes per Day ] as below and check whether it can get your expected result.

Rolling Average Changes per Day =
VAR NumDays = 30
VAR RollingSum =
    CALCULATE (
        [Ticket Total],
        DATESINPERIOD ( 'Date'[Date], LASTDATE ( 'Date'[Date] ), - NumDaysDAY )
    )
RETURN
    IF (
        ISBLANK ( [Ticket Total] ),
        BLANK (),
        DIVIDE ( RollingSumNumDaysBLANK () )
    )

If the above one can't help you get the correct result, please provide some sample data(exclude sensitive data) and your expected result with calculation logic and special examples. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@v_mark , Try like

 


Rolling Average Changes per Day =
VAR NumDays = 30
VAR RollingSum = CALCULATE([Ticket Total],
DATESINPERIOD('Date'[Date], LASTDATE('Date'[Date]), -NumDays, DAY))

RETURN
if(isblank([Ticket Total]), blank(), DIVIDE( RollingSum, NumDays, BLANK()))

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.