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.
Hello, I'm trying to get 30 day moving avg measure to work without having to first create a summarized table (count, group by date) of source data.
Measure that works with summarized table
30 Day Moving Avg =
CALCULATE(
AVERAGEX ('Summary Table (Case Count)', 'Summary Table (Case Count)'[CountofCasesperday]),
DATESINPERIOD (
'Summary Table (Case Count)'[EOWeekMonSun],
LASTDATE ('Summary Table (Case Count)'[EOWeekMonSun]),
-30,
DAY
)
)
Outcome - good
The data points on the line show the average of the last 30 day count of cases. On Apr 9, moving avg is same as count, Apr 16 it is 4+37 / 2, Apr 23 4 + 37 + 56 / 3, etc.
But essentially the same measure on unsummarized data table does not give needed outcome
MovingAvg =
CALCULATE(
AVERAGEX ('Ticket-Details', 'Ticket-Details'[CasesPerDay]),
DATESINPERIOD (
'Ticket-Details'[EOWeek],
LASTDATE ('Ticket-Details'[EOWeek]),
-30,
DAY
)
)
Outcome - not good
Why is measure not working on unsummarized data. Is summarized table only way to go?
Solved! Go to Solution.
@hxkresl wrote:
The data points on the line show the average of the last 30 day count of cases. On Apr 9, moving avg is same as count, Apr 16 it is 4+37 / 2, Apr 23 4 + 37 + 56 / 3, etc.
Not clear about the underlying data in your table, however according to the description on what "average" is expected in your case, the measure below shall work.
MovingAvg = DIVIDE ( CALCULATE ( SUM ( 'Ticket-Details'[CasesPerDay] ), FILTER ( ALLSELECTED ( 'Ticket-Details' ), 'Ticket-Details'[EOWeek] <= MAX ( 'Ticket-Details'[EOWeek] ) ) ), CALCULATE ( DISTINCTCOUNT ( 'Ticket-Details'[EOWeek] ), FILTER ( ALLSELECTED ( 'Ticket-Details' ), 'Ticket-Details'[EOWeek] <= MAX ( 'Ticket-Details'[EOWeek] ) ) ) )
@hxkresl wrote:
The data points on the line show the average of the last 30 day count of cases. On Apr 9, moving avg is same as count, Apr 16 it is 4+37 / 2, Apr 23 4 + 37 + 56 / 3, etc.
Not clear about the underlying data in your table, however according to the description on what "average" is expected in your case, the measure below shall work.
MovingAvg = DIVIDE ( CALCULATE ( SUM ( 'Ticket-Details'[CasesPerDay] ), FILTER ( ALLSELECTED ( 'Ticket-Details' ), 'Ticket-Details'[EOWeek] <= MAX ( 'Ticket-Details'[EOWeek] ) ) ), CALCULATE ( DISTINCTCOUNT ( 'Ticket-Details'[EOWeek] ), FILTER ( ALLSELECTED ( 'Ticket-Details' ), 'Ticket-Details'[EOWeek] <= MAX ( 'Ticket-Details'[EOWeek] ) ) ) )
Thank you @Eric_Zhang
I understand you are dividing the total count of cases by the total number of week periods, which is giving me the desired average at the intersection of date and count. Thank you for showing me.
I added range to make so only 30 day avg and now it's working perfectly against source data.
30DayMovingAvg_CaseCount =
DIVIDE (
CALCULATE (
COUNTA( 'Ticket-Details'[Case #] ),
FILTER (
ALLSELECTED ( 'Ticket-Details' ),
'Ticket-Details'[WeekEnd] <= MAX ( 'Ticket-Details'[WeekEnd] ) && 'Ticket-Details'[WeekEnd] >= MAX ( 'Ticket-Details'[WeekEnd] )-30
)
),
CALCULATE (
DISTINCTCOUNT ( 'Ticket-Details'[WeekEnd] ),
FILTER (
ALLSELECTED ( 'Ticket-Details' ),
'Ticket-Details'[WeekEnd] <= MAX ( 'Ticket-Details'[WeekEnd] ) && 'Ticket-Details'[WeekEnd] >= MAX ( 'Ticket-Details'[WeekEnd] )-30
)
)
)
Ta daah!!!
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 |
---|---|
106 | |
94 | |
75 | |
62 | |
50 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |