Forum Discussion
Time comparison in line chart
- 6 years ago
Hi Anonymous ,
This has to do with the context you have for your measure. When you are makking the daily chart and make the COUNTA(DimDate) you are only picking the current date on the visualization so your value is 1 then on your formula you do -1 +1 this is 0 so your result will be exactly the same as the current day.
For this to work you need to pickup the MAX and MIN date of the selected dates to get the number of days to be consider on your calcultions
Try the following measure:
Var_Users = VAR Max_date = MAXX ( ALLSELECTED ( dimDate[Date] ), dimDate[Date] ) VAR Min_date = MINX ( ALLSELECTED ( dimDate[Date] ), dimDate[Date] ) VAR date_range = DATEDIFF ( Min_date, Max_date, DAY ) VAR sum_prevperiod = CALCULATE ( SUM ( 'RawData'[Users] ), DATEADD ( DimDate[Date], - date_range + 1, DAY ) ) RETURN sum_prevperiod
Hi Anonymous ,
This has to do with the context you have for your measure. When you are makking the daily chart and make the COUNTA(DimDate) you are only picking the current date on the visualization so your value is 1 then on your formula you do -1 +1 this is 0 so your result will be exactly the same as the current day.
For this to work you need to pickup the MAX and MIN date of the selected dates to get the number of days to be consider on your calcultions
Try the following measure:
Var_Users =
VAR Max_date =
MAXX ( ALLSELECTED ( dimDate[Date] ), dimDate[Date] )
VAR Min_date =
MINX ( ALLSELECTED ( dimDate[Date] ), dimDate[Date] )
VAR date_range =
DATEDIFF ( Min_date, Max_date, DAY )
VAR sum_prevperiod =
CALCULATE (
SUM ( 'RawData'[Users] ),
DATEADD ( DimDate[Date], - date_range + 1, DAY )
)
RETURN
sum_prevperiod
Thank you!! This worked very well!!