March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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)
Thanks in advance,
Thiago Duarte
Solved! Go to Solution.
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
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
Hello there ,
The same moving or rolling avarage I wanted for Hourly basis, is this possible with above solution?
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
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
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
132 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
203 | |
141 | |
107 | |
73 | |
70 |