Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Time comparison in line chart

Hello, I've read many posts in this forum but did not find one answering my question.   I have a data model with a DimDate table (days from 01.2018 to today) and another table with Traffic (Google...
  • MFelix's avatar
    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