Forum Discussion

apelleti's avatar
apelleti
Helper I
3 years ago
Solved

Year over year change in type string calculation

I would like to create a measure that compares data from two different years (in a single column) and returns one of four types of change then plot the proportions of change type in a pie chart (i.e ...
  • Barthel's avatar
    3 years ago

    Hey apelleti,

    Add an table visual and put the 'ID' in it.

    Then create a measure that assigns the label to the 'ID'.

     

     

    Measure = 
    VAR _2022 =
        CALCULATE ( 
            SELECTEDVALUE ( 'Table'[Result] ),
            'Table'[Year] = "2022"
        )
    VAR _2021 =
        CALCULATE ( 
            SELECTEDVALUE ( 'Table'[Result] ),
            'Table'[Year] = "2021"
        )
    VAR _result =
        SWITCH ( 
            TRUE,
            _2022 = "1" && _2021 = "1", "No change – result 1",
            _2022 = "2" && _2021 = "2", "No change – result 2",
            _2022 = "2" && _2021 = "1", "Change – increase",
            _2022 = "1" && _2021 = "2", "Change – decrease"
        )
    RETURN
        _result

     

     

    Place the measure in the table visual for the desired result.

    For your second request, we need to add a new table. I named this one 'Table (2)'.

    YoY

    No change – result 1
    No change – result 2
    Change – increase
    Change – decrease

    Place this new table in a table visual.

    Create a second measure to calculate the number.

     

     

    Measure 2 =
    SUMX (
        'Table (2)',
        COUNTROWS (
            FILTER ( DISTINCT ( 'Table'[ID] ), [Measure] = EARLIER ( 'Table (2)'[YoY] ) )
        )
    )

     

     

    Finally, place the measure in the visual.