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.
Hi,
I have a sales table with the last 5years data and the table look like below.
I would like to calculate the rolling average of last 12 months based on the selected date from date table in the slicer and PeriodTypeId = 2.
For Example: If I select 2020-05 in the slicer, I should get the rolling average of last 12 months (2020-04 to 2019-05)
The rolling average should be calculated only for the PeriodTypeId=2
Thanks in advance!
Solved! Go to Solution.
Hi, @Krish89
According to your description, I think you need to create a single list and use the date column as slicer. Then create a measure to display the results.
Like this:
Table = CALCULATETABLE(DISTINCT(Table1[Date]),Table1[PeriodTypeld]=2)
Rolling Average =
VAR last =
DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, MONTH ( SELECTEDVALUE ( 'Table'[Date] ) ), DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) )
VAR s =
SUMX (
FILTER (
ALL ( Table1 ),
[PeriodTypeld] = 2
&& [Date] < SELECTEDVALUE ( 'Table'[Date] )
&& [Date] >= last
),
[Amount]
)
RETURN
DIVIDE ( s, 12 )
My sample file is below. Hope it helps.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Krish89
According to your description, I think you need to create a single list and use the date column as slicer. Then create a measure to display the results.
Like this:
Table = CALCULATETABLE(DISTINCT(Table1[Date]),Table1[PeriodTypeld]=2)
Rolling Average =
VAR last =
DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, MONTH ( SELECTEDVALUE ( 'Table'[Date] ) ), DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) )
VAR s =
SUMX (
FILTER (
ALL ( Table1 ),
[PeriodTypeld] = 2
&& [Date] < SELECTEDVALUE ( 'Table'[Date] )
&& [Date] >= last
),
[Amount]
)
RETURN
DIVIDE ( s, 12 )
My sample file is below. Hope it helps.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hey @Krish89 ,
try the following measure:
Rolling Average =
CALCULATE(
AVERAGE( myTable[Amount] ),
myTable[PeriodTypeId] = 2,
DATESINPERIOD(
dateTable[Date],
MAX( dateTable[Date] ),
-1,
YEAR
)
)
Be aware that you need a proper date table in order for the time intelligence functions to work.
Take a look on how to create a date table:
https://softcrylic.com/blogs/power-bi-for-beginners-how-to-create-a-date-table-in-power-bi/
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
100 | |
88 | |
68 | |
61 |
User | Count |
---|---|
152 | |
120 | |
102 | |
87 | |
68 |