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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.