Forum Discussion
Display only dates with existing data when calculating measure
I have a data set with values pulled from a timeseries table via a measure called [Avg]. I am trying to calculate the annual average by date from a data set that has a data result once per quarter. See example:
| Date | Data[Avg] |
| 2/12/2019 | 21 |
| 5/14/2019 | 50 |
| 8/13/2019 | 55 |
| 11/12/2019 | 32 |
| 2/15/2020 | 20 |
I have a code that correctly calculates the annual running average here:
I want it to have one point for the avarage only where there is a date with data. I have played around with the filters but can't get it working while still calulating the annual average. Any tips?
1 Reply
- amitchandak
Super User
ApplePie , Assuming , You table is having a date column
VAR Duration = 4
VAR LastSelectDate = MAX(Dates[Date])
VAR Period = DATESINPERIOD( Dates[Date], LastSelectDate, -Duration, QUARTER)
VAR LRAA =
IF(COUNTROWS(Period)>364,
CALCULATE (
AVERAGEX ( FILTER(ALLSELECTED(Dates), Dates[Date] <= LastSelectDate),
[Avg]),
Period, not(ISBLANK(Table[Date])) ),
BLANK())
RETURN
LRAAOr use this with date from your Table on axis
VAR Duration = 4
VAR LastSelectDate = MAX(Table[Date])
VAR Period = Date(Year(LastSelectDate)-1, month(LastSelectDate), day(LastSelectDate))
VAR LRAA =
CALCULATE (
AVERAGEX ( FILTER(ALLSELECTED(Dates), Dates[Date] <= LastSelectDate),
[Avg]),
Period, not(ISBLANK(Table[Date])) )
RETURN
LRAA