Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi team,
i am trying to create the rolling average for 3 months but it was giving same values as base value, can you help me to fix for rolling average for 3 months.
Solved! Go to Solution.
You can try
Rolling Average =
VAR DatesToUse =
WINDOW (
-2,
REL,
0,
REL,
ALLSELECTED ( 'Date'[Year], 'Date'[Month number] ),
ORDERBY ( 'Date'[Year], ASC, 'Date'[Month number], ASC )
)
VAR Result =
AVERAGEX ( DatesToUse, CALCULATE ( DISTINCTCOUNT ( 'Table'[User ID] ) ) )
RETURN
Result
Hello @sreddy47652 ,
You can use below dax for your purpose , please replace table names and fileds:
Did I answer your query ? Mark this as solution if this helps, appreciate your Kudos.
Cheers
Hello @sreddy47652 ,
It is giving as expected , here is the illustration, please suggest if you have different logic
Cheers
Hi @sreddy47652 ,
Please try the following dax.
Rolling Average (3 Months) =
VAR difference = DATEDIFF(MINX(ALL('Table'),'Table'[Date]),MAX('Table'[Date]),MONTH) --The difference in months from the min date.
VAR _value = CALCULATE(DISTINCTCOUNT('Table'[Users]) ,DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-3,MONTH)) --Total value of 3 months.
RETURN
SWITCH(
TRUE(),
difference=0,_value,
difference=1,_value/2,
difference>1,_value/3
)
Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @sreddy47652 ,
Please try the following dax.
Rolling Average (3 Months) =
VAR difference = DATEDIFF(MINX(ALL('Table'),'Table'[Date]),MAX('Table'[Date]),MONTH) --The difference in months from the min date.
VAR _value = CALCULATE(DISTINCTCOUNT('Table'[Users]) ,DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-3,MONTH)) --Total value of 3 months.
RETURN
SWITCH(
TRUE(),
difference=0,_value,
difference=1,_value/2,
difference>1,_value/3
)
Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @sreddy47652 ,
You can use below dax for your purpose , please replace table names and fileds:
Did I answer your query ? Mark this as solution if this helps, appreciate your Kudos.
Cheers
@divyed it's working some what better than earlier formulas but need rolling average like this below image, can you help me to fix this.
Hello @sreddy47652 ,
It is giving as expected , here is the illustration, please suggest if you have different logic
Cheers
Hi @sreddy47652 ,
Here is a measure for calculating a 3-month rolling average at the month level:
Rolling Average (3 Months) =
VAR CurrentMonth = MAX('Calendar'[Date])
RETURN
AVERAGEX(
DATESINPERIOD('Calendar'[Date], CurrentMonth, -3, MONTH),
CALCULATE(SUM('FactTable'[Value]))
)
This measure calculates the rolling average by using the DATESINPERIOD function to define a 3-month window and then applies AVERAGEX to compute the average for the specified period. The calendar table ensures the calculation respects the relationship with the fact table.
Best regards,
You can try
Rolling Average =
VAR DatesToUse =
WINDOW (
-2,
REL,
0,
REL,
ALLSELECTED ( 'Date'[Year], 'Date'[Month number] ),
ORDERBY ( 'Date'[Year], ASC, 'Date'[Month number], ASC )
)
VAR Result =
AVERAGEX ( DatesToUse, CALCULATE ( DISTINCTCOUNT ( 'Table'[User ID] ) ) )
RETURN
Result
i tried above forumala but it always return as 1 only instead of rolling average
@johnt75 it seems better than earlier formula but its not giving accurate results, i need rolling average below like this but based on month number. can you help me how to fix it.
Its is showing the rolling 3 month average, including the month itself. So in March it is showing the average over Jan, Feb and March.
What formula are you using to calculate the average, and what about the numbers do you think is wrong ?
No ,Formula is correct but when you rolling over next month it's showing average for 4 months viceversa but ideally it should show as below image
I don't understand what you mean that its showing the average for 4 months viceversa? The window function is producing 3 months and then you take the average of that.
From the PBIX I posted earlier
Hi @sreddy47652
It is better to provide representative date to get the exact solution.
However, you could try this:
RollingAvg3Months =
CALCULATE(
AVERAGEX(
DATESINPERIOD(
'DateTable'[Date],
LASTDATE('DateTable'[Date]),
-3,
MONTH
),
AVERAGE('YourTable'[Value])
)
)
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz
i tried already above formula still returns same values for base value
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 64 | |
| 32 | |
| 31 | |
| 27 |