Forum Discussion

Doorian's avatar
Doorian
New Member
1 year ago
Solved

DAX Measure

Hello everyone, I am looking for help regarding a DAX measure in a matrix visual. I want to calculate the change of my initial measure (number of trips per day) compared to the previous month. In my ...
  • johnt75's avatar
    1 year ago

    You can try

    Month on Month change =
    IF (
        ISINSCOPE ( 'Date'[Year month] ),
        VAR CurrentValue = [Num trips]
        VAR PrevValue =
            CALCULATE ( [Num trips], DATEADD ( 'Date'[Date], -1, MONTH ) )
        VAR Result = CurrentValue - PrevValue
        RETURN
            Result,
        VAR MinDate =
            MINX (
                ALLSELECTED ( 'Date'[Year month sort column] ),
                'Date'[Year month sort column]
            )
        VAR MaxDate =
            MAXX (
                ALLSELECTED ( 'Date'[Year month sort column] ),
                'Date'[Year month sort column]
            )
        VAR CurrentValue =
            CALCULATE ( [Num trips], 'Date'[Year month sort column] = MaxDate )
        VAR PrevValue =
            CALCULATE ( [Num trips], 'Date'[Year month sort column] = MinDate )
        VAR Result = CurrentValue - PrevValue
        RETURN
            Result
    )
    

    Its important to use the column which year month is sorted by, rather than the year month column itself, as MIN / MAX won't work properly with alphanumeric columns. If your year month column is actually date which is just formatted in year month format then you can use that column.