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
chrishnrh57
Regular Visitor

Rolling Average Excluding Zero

Hello,

 

I have looked through this forum quite a bit and i'm seeing solutions very similar to what i'm trying to figure out, but not exactly what I need.

 

I'm looking for a Rolling Average that EXCLUDES zero. My initial Equation Looks like this:

 
(5-2)Output 5 Day Average =
CALCULATE(
Sum('(5-2) Shift Turnover Data'[(5.2) 8 Hr. Output]),
DATESINPERIOD('(5-1) Shift Turnover Data'[Date],LASTDATE('(5-1) Shift Turnover Data'[Date]),5,DAY)
)
/
CALCULATE(
DISTINCTCOUNT('(5-1) Shift Turnover Data'[Date]),
DATESINPERIOD('(5-1) Shift Turnover Data'[Date],LASTDATE('(5-1) Shift Turnover Data'[Date]),5,DAY)
)
 
And it looks like this:
 
 

Capture.JPG

Capture2.JPG

 

It looks like it's taking the blank days and including them in the average.

 

 

 

I also tried using the "New Quick Measure" feature but every time I did it would look like this:

 

(5.1) 8 H.r Output rolling average =
IF(
    ISFILTERED('(5-1) Shift Turnover Data'[Date]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __LAST_DATE = LASTDATE('(5-1) Shift Turnover Data'[Date].[Date])
    RETURN
        AVERAGEX(
            DATESBETWEEN(
                '(5-1) Shift Turnover Data'[Date].[Date],
                DATEADD(__LAST_DATE, -1, DAY),
                DATEADD(__LAST_DATE, 5, DAY)
            ),
            CALCULATE(SUM('(5-1) Shift Turnover Data'[(5.1) 8 H.r Output]))
        )
)
 
 
 
And I'm assuming the "ERROR" message is preventing it from working because every time i place it in a chart it errors out.
 
 
I also saw this website as a solution in a previous post:
 
But this was only for monthly averages and i wanted rolling 5 day averages.
 
I'm still very new at this so any information on this would be GREATLY appreciated. Thank you.
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @chrishnrh57,

It is hard to find out your table structure and test from your snapshot. Can you please share some dummy data with the same table structure? 

How to Get Your Question Answered Quickly 

In addition, I'd like to suggest you use date function to manually define filter range instead of using time intelligence functions. (they do not support custom)

Time Intelligence "The Hard Way" (TITHW) 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @chrishnrh57,

It is hard to find out your table structure and test from your snapshot. Can you please share some dummy data with the same table structure? 

How to Get Your Question Answered Quickly 

In addition, I'd like to suggest you use date function to manually define filter range instead of using time intelligence functions. (they do not support custom)

Time Intelligence "The Hard Way" (TITHW) 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

I don't think any software will force a value in a blank cell to compute an average.  Simplify your request by sharing a simple Excel file and show the expected result there.  Share the link from where i can download your PBI file.


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

Make it blank and try

  VAR __LAST_DATE = LASTDATE('(5-1) Shift Turnover Data'[Date])
    RETURN
        AVERAGEX(
            DATESBETWEEN(
                '(5-1) Shift Turnover Data'[Date],
                DATEADD(__LAST_DATE, -1, DAY),
                DATEADD(__LAST_DATE, 5, DAY)
            ),
            if(CALCULATE(SUM('(5-1) Shift Turnover Data'[(5.1) 8 H.r Output]))=0, blank(),CALCULATE(SUM('(5-1) Shift Turnover Data'[(5.1) 8 H.r Output])))
        )
)	

 

In case date do not include time do not use ,date -> Shift Turnover Data'[Date].[Date] only use Shift Turnover Data'[Date]

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.