Forum Discussion

MT54's avatar
MT54
New Member
3 years ago
Solved

Percentage Difference Formula Help

Hi,    I have searched the forums but didn't find anything that was what I'm trying to do and my attempts to change other formulae and use the quick measures haven't worked. I'm trying to create th...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi MT54 ,

     

    I suggest you to try code as below to create calculated columns.

    Difference = 
    VAR _1 = 0
    VAR _2to5 =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Category] ),
                'Table'[Step]
                    = EARLIER ( 'Table'[Step] ) - 1
            )
        )
    VAR _6 =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[Category] ), 'Table'[Step] = 1 )
        )
    RETURN
        IF (
            'Table'[Step] = 1,
            _1,
            IF ( 'Table'[Step] = 6, 'Table'[Value] - _6, 'Table'[Value] - _2to5 )
        )
    % difference = 
    VAR _1 = 0
    VAR _2to5 =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Category] ),
                'Table'[Step]
                    = EARLIER ( 'Table'[Step] ) - 1
            )
        )
    VAR _6 =
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[Category] ), 'Table'[Step] = 1 )
        )
    RETURN
        IF (
            'Table'[Step] = 1,
            _1,
            DIVIDE ( 'Table'[Difference], IF ( 'Table'[Step] = 6, _6, _2to5 ) )
        )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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