Forum Discussion

daniel_krantz_4's avatar
2 years ago
Solved

Transitioning from Tableau - calculated Measure

I'm having alot of trouble with this one. In Tableau, I have a measure called "% Difference" - calculated as "ZN([%Pos Response]) - LOOKUP(ZN([%Pos Response]), -1)". This allows me, when I put Years ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi daniel_krantz_4 

     

    Maybe you can try this:

    Here I create a measure:

    % Difference =
    VAR _currentYear =
        YEAR ( MAX ( 'Table'[Date] ) )
    VAR _previousYear =
        CALCULATE (
            MAX ( 'Table'[Date] ),
            FILTER ( ALLSELECTED ( 'TABLE' ), YEAR ( 'TABLE'[Date] ) < _currentYear )
        )
    VAR CurrentYearValue =
        CALCULATE (
            [%Pos Response],
            FILTER ( ALLSELECTED ( 'Date' ), YEAR ( 'Table'[Date] ) = _currentYear )
        )
    VAR PreviousYearValue =
        CALCULATE (
            [%Pos Response],
            FILTER ( ALLSELECTED ( 'Date' ), YEAR ( 'Table'[Date] ) = _previousYear )
        )
    RETURN
        IF (
            NOT ISBLANK ( CurrentYearValue ),
            ( CurrentYearValue - PreviousYearValue ) / PreviousYearValue,
            BLANK ()
        )

     You can change the 'Table'[Date] into your own table's Date column.

     

    Best Regards

    Zhengdong Xu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.