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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Rolling Average With Drilldown

I followed this post to create a chart that has a rolling average: 

https://community.powerbi.com/t5/Desktop/12-Month-Rolling-average/m-p/323299#M144109

 

As far as I can tell, the solution works as intended (though I didn't need to change AVERAGEX to SUMX), but I need to be able to expand my date hierarchy to either year+quarter or year+month. Every time I expand the hierarchy the table breaks, though.

 

Before expanding:

Before ExpandingBefore Expanding

After Expanding:

After ExpandingAfter Expanding

 

Is there a way to do this or am I asking the impossible?

1 ACCEPTED SOLUTION

Hey @Anonymous ,

 

I'm not 100% shure if I understand correctly what you mean by "breaks" the visual.

My assumption is this: Due to the "outlier" with an established date way back in the past, there are a lot of quarter / month with an rolling average, if you drill down from year to ...

And the goal: Avoid the "unnecessary" level.

 

To achieve this I created this measure:

 

Rolling Average = 
var _NullValue = CALCULATE(SUM('Table'[Setup Time]))
return
IF(NOT(ISBLANK(_NullValue))
    , CALCULATE(
        AVERAGEX(
            'Table'
            , CALCULATE(AVERAGE('Table'[Setup Time]))
        )
        , FILTER(
            ALL('Calendar')
            , 'Calendar'[Date] <= MAX('Calendar'[Date])
        )
    )
    , BLANK()
)

 

The essential part is not the calculation of the rolling average using CALCULATE(AVERAGEX(... , ...) , ...), the essntial part is the calculation of the "_NullValue", whenever there is no "Setup Time", the rolling average will not be calculated, using IF(NOT(ISBLANK(_NullValue)) , <the calculation of the rolling average> , BLANK()) prevents the calculation of the rolling average even if there is no "Setup time".

 

Hopefully this is what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

According to your description, I do not quite understand your question.

Could you please share your PBIX/some sample data and expected result to me if you don't have any Confidential Information?

You can upload your pbix file to OneDrive and share it with me if it is convenient..

Remember that you should remove security and sensitive data within the report.

 

Best Regards,
Community Support Team _ Eason

Anonymous
Not applicable

I can't share the PBIX since I believe it's mostly confidential but here's a mock-up of what the data looks like as well as the desired output:

 

Customers

NameEstablished DateSetup Time

Company A

11/2/198030
Company B7/8/201750
Company C3/6/201842
Company D5/9/201867
Company E8/6/201843

 

Those are essentially all of the relevant fields in this visual of the report. From this data I want to create a column chart of Established Date month + year on the X-axis vs the average Setup Time of all companies established on or before the given month (rolling average that covers all time beforehand).

 

I followed the linked tutorial in my first post, and it creates a rolling average just fine, but there are two problems with it.

1. The chart begins including months between an outlying company that was established long before all others and the next earliest established company, which is several decades of useless months

2. As the Established Date field is a date hierarchy, I want to be able to expand downward to display either the quarter + month, or the year + month but when I expand downward the chart breaks as depicted.

Anonymous
Not applicable

@v-easonf-msft is this possible or should I look at an alternate solution?

Hey @Anonymous ,

 

I'm not 100% shure if I understand correctly what you mean by "breaks" the visual.

My assumption is this: Due to the "outlier" with an established date way back in the past, there are a lot of quarter / month with an rolling average, if you drill down from year to ...

And the goal: Avoid the "unnecessary" level.

 

To achieve this I created this measure:

 

Rolling Average = 
var _NullValue = CALCULATE(SUM('Table'[Setup Time]))
return
IF(NOT(ISBLANK(_NullValue))
    , CALCULATE(
        AVERAGEX(
            'Table'
            , CALCULATE(AVERAGE('Table'[Setup Time]))
        )
        , FILTER(
            ALL('Calendar')
            , 'Calendar'[Date] <= MAX('Calendar'[Date])
        )
    )
    , BLANK()
)

 

The essential part is not the calculation of the rolling average using CALCULATE(AVERAGEX(... , ...) , ...), the essntial part is the calculation of the "_NullValue", whenever there is no "Setup Time", the rolling average will not be calculated, using IF(NOT(ISBLANK(_NullValue)) , <the calculation of the rolling average> , BLANK()) prevents the calculation of the rolling average even if there is no "Setup time".

 

Hopefully this is what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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