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.
I have a 30 day rolling average measure that works fine, against my [Amount] field:
My problem is that it is producing a 'tail' in the data.
The [Amount] data for the following contract only goes up to 31 March, but when I include the rolling average measure in the table, it produces blanks for the 30 days after 31 March.
Can anyone help remove this tail in the measure itself, without using slicers?
Solved! Go to Solution.
Here's your measure:
// 1st basic measure
[Total Amount] =
SUM ( 'Fact Daily Readings'[Amount] )
[30 Day Rolling Average] =
var __lastDayWithAmount =
lastnonblank(
ALL( 'Dimension Date'[Date] ),
[Total Amount]
)
VAR __lastDayVisible =
LASTDATE ( 'Dimension Date'[Date] )
var __shouldCalculate =
__lastDayVisible <= __lastDayWithAmount
var __startDay =
// YOU SHOULD BE CAREFUL WITH THIS
// SINCE THIS OPERATION MIGHT GET YOU
// OFF THE LEFT BOUNDARY OF THE CALENDAR.
// You need to check if this date is
// not BLANK. If it is, it means you're
// off the calendar... and can't calculate
// your measure.
DATEADD ( __lastDayVisible, -29, DAY )
var __periodToAverageOver =
DATESBETWEEN (
'Dimension Date'[Date],
__startDay,
__lastDayVisible
)
var __result =
AVERAGEX (
__periodToAverageOver,
[Total Amount]
)
return
If( __shouldCalculate, __result )
This should work. If it doesn't then some small modifications might be needed.
Best
D
Here's your measure:
// 1st basic measure
[Total Amount] =
SUM ( 'Fact Daily Readings'[Amount] )
[30 Day Rolling Average] =
var __lastDayWithAmount =
lastnonblank(
ALL( 'Dimension Date'[Date] ),
[Total Amount]
)
VAR __lastDayVisible =
LASTDATE ( 'Dimension Date'[Date] )
var __shouldCalculate =
__lastDayVisible <= __lastDayWithAmount
var __startDay =
// YOU SHOULD BE CAREFUL WITH THIS
// SINCE THIS OPERATION MIGHT GET YOU
// OFF THE LEFT BOUNDARY OF THE CALENDAR.
// You need to check if this date is
// not BLANK. If it is, it means you're
// off the calendar... and can't calculate
// your measure.
DATEADD ( __lastDayVisible, -29, DAY )
var __periodToAverageOver =
DATESBETWEEN (
'Dimension Date'[Date],
__startDay,
__lastDayVisible
)
var __result =
AVERAGEX (
__periodToAverageOver,
[Total Amount]
)
return
If( __shouldCalculate, __result )
This should work. If it doesn't then some small modifications might be needed.
Best
D
Hi @AltGr9
its unclear your desired output
[Amount] is your stored data from data model as I understand. So, if [Amount] is empty for april dates it is empty in visual
[30 Day Rolling Average] is a measure that calculates average for last 30 day. for example for 15th April it will sum up all the date from 16th March and 15 blank values from April and give you an average.
What ttail do you want to cut?
If you need only March average without April, you can try a measure like
30 Day Rolling Average =
VAR __LAST_DATE = IF(MONTH('Dimension Date'[Date])>3, DATE(2013,3,31), LASTDATE('Dimension Date'[Date]))
RETURN
AVERAGEX(
DATESBETWEEN(
'Dimension Date'[Date],
DATEADD(__LAST_DATE, -29, DAY),
__LAST_DATE )
, CALCULATE(SUM('Fact Daily Readings'[Amount]))
)
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 |
---|---|
47 | |
24 | |
20 | |
15 | |
12 |
User | Count |
---|---|
55 | |
48 | |
43 | |
19 | |
18 |