Forum Discussion

dopingcontrol's avatar
dopingcontrol
New Member
4 years ago
Solved

power bi difference between two columns in a matrix

Hello community,

I would like to calculate a difference absolute and percent between two columns in my visualisation.

 

My data looks like this:

 

 

LEVELDATEREVENUE
ActualJanuary 100
BudgetJanuary 110
Actual February 90
BudgetFebruary 95
ActualMarch115
BudgetMarch105
ActualApril130
BudgetApril120
   

 

I want to have the following matrix with the difference column Actual vs Budget.

 

DATEACTUALBUDGETDiff 
January100110-10 
February9095-5 
March115105+10 
April130120+10 
     
     
     
     

 

 

 

Is this possible?

I would be very grateful for your help.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi dopingcontrol ,

     

    Arul use PIVOT function in Power Query to achieve your goal. This way will transform your data model. If you don't want to transform your table, you can try to create a measure to show difference in Total and rename "Total" by "Diff".

     

    Measure = 
    VAR _REVENUE = SUM('Table'[REVENUE])
    VAR _ACTUAL = CALCULATE( SUM('Table'[REVENUE]),'Table'[LEVEL] = "Actual")
    VAR _Budget = CALCULATE( SUM('Table'[REVENUE]),'Table'[LEVEL] = "Budget")
    RETURN
    IF(HASONEVALUE('Table'[LEVEL]),_REVENUE,_ACTUAL - _Budget)

     

    Then create a matrix visual.

    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.

     

2 Replies

  • Arul's avatar
    Arul
    Icon for Super User rankSuper User

    dopingcontrol ,

    Yes it is possible!!

    You need to pivot your table in power query editor based on date column,

    Then,

    write the below measure and use actual,budget and measure in the matrix visual.

     

    Thanks,

    Arul

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi dopingcontrol ,

     

    Arul use PIVOT function in Power Query to achieve your goal. This way will transform your data model. If you don't want to transform your table, you can try to create a measure to show difference in Total and rename "Total" by "Diff".

     

    Measure = 
    VAR _REVENUE = SUM('Table'[REVENUE])
    VAR _ACTUAL = CALCULATE( SUM('Table'[REVENUE]),'Table'[LEVEL] = "Actual")
    VAR _Budget = CALCULATE( SUM('Table'[REVENUE]),'Table'[LEVEL] = "Budget")
    RETURN
    IF(HASONEVALUE('Table'[LEVEL]),_REVENUE,_ACTUAL - _Budget)

     

    Then create a matrix visual.

    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.