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

 

ThiagoDuarte_0-1666028505266.png

 

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):

ThiagoDuarte_1-1666029126345.png

ThiagoDuarte_2-1666029222333.png

 

(this was done in manually in excel)

 

Thanks in advance,

Thiago Duarte

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @ThiagoDuarte ,

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 )

In addition, you can refer the following links to get it.

Rolling 12 Months Average in DAX

Rolling Averages In Power BI

yingyinr_0-1666059296728.png

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.

View solution in original post

3 REPLIES 3
Sugat
New Member

Hello there ,

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

 

v-yiruan-msft
Community Support
Community Support

Hi @ThiagoDuarte ,

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 )

In addition, you can refer the following links to get it.

Rolling 12 Months Average in DAX

Rolling Averages In Power BI

yingyinr_0-1666059296728.png

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.

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

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.