Forum Discussion

AtomFiske's avatar
AtomFiske
New Member
3 years ago
Solved

Matrix + percentage difference issue

I have monthly recurring tasks and I would like to calculate and visualize these figures. the base data is quite simple (see below), but I can't seem to get this right. I want to calculate the percentage difference between tasks and I would like power bi to show me the percentage difference between two months based on the filtered months that I select.

for example, I want to compare the month 202110 with the month 202210 and see the percentage difference of tasks. And when I change the filter values, I want to compare the months 202209 and 202210 in the same way.

 

i have huge problems with this. Can anyone help me? 

 

 

YYYYMMTaskValue
202110task 1380
202110task 2550
202110task 3120
202209task 1350
202209task 2520
202209task 3150
202210task 1400
202210task 2500
202210task 3100
  • MFelix's avatar
    MFelix
    3 years ago

    Hi AtomFiske ,

     

    In this case you just need to change the second argument of the division use the following metric:

    Variation = 
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
            - CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) ),
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) )
    )

     

    If you want to present the values based on the YYYYMM also then you need to make some changes, this can be an option:

    Variation = 
    IF(ISINSCOPE('Table'[YYYYMM]), SUM('Table'[Value]),
    FORMAT(DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
            - CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) ),
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) )
    ), "#.00%"))

     

     

4 Replies

  • Hi AtomFiske ,

     

    Try the following code:

    Variation = 
    DIVIDE (
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
            - CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) ),
        CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
    )

    Be aware that this code only works if you do not have the yyyymm on your table, if you need to have it this needs to be revised.

     

  • Hi! Thank you MFelix ! This is pretty close, but not quite what I was trying to describe. I probably didn't describe my problem well enough. I will try again with a picture.

    I want to compare the task-specific percentage difference (see the red numbers on the picture) of the two months I selected with the filter, but I don't understand how to make this work. 

     

    • MFelix's avatar
      MFelix
      Super User

      Hi AtomFiske ,

       

      In this case you just need to change the second argument of the division use the following metric:

      Variation = 
      DIVIDE (
          CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
              - CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) ),
          CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) )
      )

       

      If you want to present the values based on the YYYYMM also then you need to make some changes, this can be an option:

      Variation = 
      IF(ISINSCOPE('Table'[YYYYMM]), SUM('Table'[Value]),
      FORMAT(DIVIDE (
          CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MAX ( 'Table'[YYYYMM] ) )
              - CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) ),
          CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[YYYYMM] = MIN ( 'Table'[YYYYMM] ) )
      ), "#.00%"))