cancel
Showing results 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.

Helper I

## Moving/rolling avarage (R12) of a cummulative measure

Hi,

I need help to build a measure to calculate a rolling avarage of a measure

These are the measures:

``WIP Month = [Poured]-SUM(Delivery[Peso])-SUM(Scrap[Peso])``
``````WIP cummulated =
CALCULATE(
[WIP month],
FILTER(ALL(Calendario),Calendario[Date]<=MAX(Calendario[Date])&&
Calendario[Date]>=DATE(2021,01,01)))``````

I need a measure for rolling 12 average "WIP cummulated"

Something like this (R12M):

(this was done in manually in excel)

Thiago Duarte

1 ACCEPTED SOLUTION
Community Support

You can create a measure as below and check if it can return the correct result...

``````WIP R12M =
VAR NumOfMonths = 12
VAR _selyear =
SELECTEDVALUE ( 'Calendario'[Ano] )
VAR _selmonth =
SELECTEDVALUE ( 'Calendario'[Monthno] )
VAR _selym =
VALUE ( _selyear & IF ( _selmonth >= 10, _selmonth, "0" & _selmonth ) )
VAR _date =
DATE ( 2021, 1, 1 ) + 365
VAR _date2 =
IF ( DAY ( _date ) > 1, _date + 1, _date )
VAR _ym =
VALUE ( YEAR ( _date2 ) & FORMAT ( _date2, "mm" ) )
VAR LastCurrentDate =
MAX ( 'Calendario'[Date] )
VAR Period =
DATESINPERIOD ( 'Calendario'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
AVERAGEX (
GROUPBY ( 'Calendario', 'Calendario'[Ano], 'Calendario'[Mes] ),
[WIP cummulated]
),
Period
)
RETURN
IF ( _selym >= _ym, Result )``````

Rolling 12 Months Average in DAX

Rolling Averages In Power BI

If the above one can't help you get the desired result, please provide some sample data in the table Delivery, Scrap and other fact table(exclude sensitive data) with Text format and your expected result with backend logic and special examples. And share the visual field settings as below screenshot. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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.
3 REPLIES 3
New Member

Hello there ,

The same moving or rolling avarage I wanted for Hourly basis, is this possible with above solution?

Community Support

You can create a measure as below and check if it can return the correct result...

``````WIP R12M =
VAR NumOfMonths = 12
VAR _selyear =
SELECTEDVALUE ( 'Calendario'[Ano] )
VAR _selmonth =
SELECTEDVALUE ( 'Calendario'[Monthno] )
VAR _selym =
VALUE ( _selyear & IF ( _selmonth >= 10, _selmonth, "0" & _selmonth ) )
VAR _date =
DATE ( 2021, 1, 1 ) + 365
VAR _date2 =
IF ( DAY ( _date ) > 1, _date + 1, _date )
VAR _ym =
VALUE ( YEAR ( _date2 ) & FORMAT ( _date2, "mm" ) )
VAR LastCurrentDate =
MAX ( 'Calendario'[Date] )
VAR Period =
DATESINPERIOD ( 'Calendario'[Date], LastCurrentDate, - NumOfMonths, MONTH )
VAR Result =
CALCULATE (
AVERAGEX (
GROUPBY ( 'Calendario', 'Calendario'[Ano], 'Calendario'[Mes] ),
[WIP cummulated]
),
Period
)
RETURN
IF ( _selym >= _ym, Result )``````

Rolling 12 Months Average in DAX

Rolling Averages In Power BI

If the above one can't help you get the desired result, please provide some sample data in the table Delivery, Scrap and other fact table(exclude sensitive data) with Text format and your expected result with backend logic and special examples. And share the visual field settings as below screenshot. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

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.
Helper I

Thank you @v-yiruan-msft!

That worked beautifully. I just had to make a few adjustments in how de dates are declared

``````VAR _selyear =
SELECTEDVALUE ( 'Calendario'[Ano] )

Became

VAR _selyear =
SELECTEDVALUE ( Calendario[Date].[Ano] )``````

and so on

Now i'll try and understand your code so i can learn from it

Thanks again!

Best Regards,

Thiago Duarte

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors