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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
helen_p
Frequent Visitor

Moving Range to be calculated at different hierachies

Dear Power BI user

 

I have set up a table in power BI which looks similar to the example table below:

 

Week Commencing     Count Of Additions      Care Group    Clinician  Moving Range

01/01/2020                                  3                          A                   1                 

07/01/2020                                  6                          A                   1               3

14/01/2020                                  4                          A                   1               2

01/01/2020                                  9                          B                    2              5

07/01/2020                                  8                          B                    2

14/01/2020                                  7                          B                    2

01/01/2020                                  9                          A                    3

07/01/2020                                  8                          A                    3

14/01/2020                                  7                          A                    3

 

I initially created 2 new index columns  called "Index" starting from 0 and and Index.1" starting from 1. 

 

The calculation below only works at the most granular level when looking at clinician.  I think it only works at clinician level as the index fields are always looking at the row above to calculate the difference in count of wl additions each row

 

I.e. 

 

Moving Range = ABS('Waiting List Extract'[Count Of WL Additions]-(CALCULATE(sum('Waiting List Extract'[Count Of WL Additions]),FILTER('Waiting List Extract','Waiting List Extract'[Index.1]=EARLIER('Waiting List Extract'[Index])))))

 

I was wondering if someone could help me understand how I can get my calculation to work with the index columns so that the moving range works at different levels of hiercahy in the table I.e. works out the moving range at  Care Group Level

 

Kind Regards

Helen

 

 

 

 

1 REPLY 1
MFelix
Super User
Super User

Hi @helen_p  no need to do the INDEX you just need to add the following measure:

 

Moving_Average = 
VAR temp_table =
    FILTER (
        ALL ( 'Waiting List Extract'[Week Commencing] );
        'Waiting List Extract'[Week Commencing]
            < SELECTEDVALUE ( 'Waiting List Extract'[Week Commencing] )
    )
VAR Previous_Date =
    MAXX ( temp_table; 'Waiting List Extract'[Week Commencing] )
RETURN
    ABS (
        SUM ( 'Waiting List Extract'[Count of Addtions] )
            - CALCULATE (
                SUM ( 'Waiting List Extract'[Count of Addtions] );
                FILTER (
                    ALL (
                        'Waiting List Extract'[Care Group];
                        'Waiting List Extract'[Clinician];
                        'Waiting List Extract'[Week Commencing];
                        'Waiting List Extract'[Count of Addtions]
                    );
                    'Waiting List Extract'[Week Commencing] = Previous_Date
                        && 'Waiting List Extract'[Care Group]
                            IN VALUES ( 'Waiting List Extract'[Care Group] )
                                && 'Waiting List Extract'[Clinician]
                                    IN VALUES ( 'Waiting List Extract'[Clinician] )
                )
            )
    )

This will pickup the previuos week date and then based on the aggregation make the calculation:

 

MFelix_0-1607684375850.png

Check PBIX file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.