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
Quiny_Harl
Resolver I
Resolver I

How to create a dynamic rolling average measure?

In fact, I have created the dynamic rolling average measure. Here how it works.
We have 2 slicers - one to select the measure we want to visualize and another one to select the 3 month, 6 month or 12 month rolling average for that measure. Both of those measures are visualized on a line chart.

Quiny_Harl_0-1661189425434.png

 

1. We have a switch measure that switches between the measures based on a slicer selection:

Selected Transport Measure =
SWITCH(SELECTEDVALUE(Parameters[Index]),
0, [Measure 1],
1, [Measure 2],
2, [Measure 3],
3, [Measure 4 Percent]
      )
2. We have a 3m, 6m and 12 rolling average measures which calculate the rolling average for the measure selected from the slicer:
3M Rolling Avg =
var LastSelectedDate = MAX(Calendar[Date])
var Period = DATESINPERIOD(Calendar[Date],LastSelectedDate,-3,MONTH)
var Rolling_Avg =
    CALCULATE(
              AVERAGEX(
                        VALUES(Calendar[Year Month]),
                        [Selected Transport Measure]
                      ),
               Period
             )
return Rolling_Avg

3. Then we have another switch measure that switches between 3m, 6m and 12m based on a selection from the other slicer. This is the measure used in the visual.
Selected Rolling Avg Measure =
IF(ISFILTERED('Parameters - Rolling Avg'[MRA Measures]),
                SWITCH(SELECTEDVALUE('Parameters - Rolling Avg'[Index]),
                                    3, [3M Rolling Avg],
                                    6, [6M Rolling Avg],
                                    12, [12M Rolling Avg],
                                    BLANK()
                     ),
    BLANK()
   )        

All works fine, except for Measure 4 Percent (see step 1) because unlike the other 3 measures it is a percent. Is there a way to make this thing work with a measure that's formatted as a percent?
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Quiny_Harl simply launch TE 

 

- create a calculation group

- add 4 calculation item, name those whatever you want

- assuming calculate items are called "Item1", "Item2", "Item3", Item4"

- for item1, it will return [Measure 1] and in the format string give the format string this suppose to have, do the same for each item in the calculation group. For item 4, the format string will be %

 

Apply and save the changes, To visualize

 

- put calculation item as a slicer so use can which measure they want to see

- in a matrix visual, put a column on rows, calculation item column on columns, any measure on value

 

and based on the slicer selection, the respective measures will show in the matrix visual with the respective format.

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@Quiny_Harl simply launch TE 

 

- create a calculation group

- add 4 calculation item, name those whatever you want

- assuming calculate items are called "Item1", "Item2", "Item3", Item4"

- for item1, it will return [Measure 1] and in the format string give the format string this suppose to have, do the same for each item in the calculation group. For item 4, the format string will be %

 

Apply and save the changes, To visualize

 

- put calculation item as a slicer so use can which measure they want to see

- in a matrix visual, put a column on rows, calculation item column on columns, any measure on value

 

and based on the slicer selection, the respective measures will show in the matrix visual with the respective format.

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Quiny_Harl instead of using the selected transport measure and switch function, you should use calculate groups instead, and there you can define the different formats for different measures and in measure 4, it will be the percent format. There are many blog posts on how to change format string in calculation group, just google it and you will find it. You can also check my playlist on the calculation group here. https://youtube.com/playlist?list=PLiYSIjh4cEx2s8-jXBhv5aCu5_6F9zQ3I

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k ,thanks for this suggestion! Would you mind explaining a bit more how the calculation groups can be used for this scenario? Or maybe if you have a mock up pbi file where this has been applied?

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.