Forum Discussion

j3n5k1's avatar
j3n5k1
New Member
3 years ago
Solved

Difference between 2 columns

I have a matrix like the below where I have swapped the values to rows. What I would like is to create another column showing the difference between Current and Prior Year for all metrics. If I creat...
  • v-jianboli-msft's avatar
    3 years ago

    Hi j3n5k1 ,

     

    Please try:

    First add a new column to the table:

    Then creaet a new table:

    Manage relationship:

     

    Apply the measure:

    Sum of Cancles = 
    var _a = FORMAT( CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'[Year])),"General Number")
    var _b = CALCULATE(SUM('Dummy Data'[Cancels]),FILTER('Table',[Year]=_a))
    var _c = CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'))
    var _d = CALCULATE(SUM('Dummy Data'[Cancels]),FILTER(ALL('Table'),[Year]=FORMAT(_c,"General Number")))
    var _e = CALCULATE(SUM('Dummy Data'[Cancels]),FILTER(ALL('Table'),[Year]=FORMAT(_c-1,"General Number")))
    return IF(MAX('Table'[Year])="Difference",_d-_e,_b)
    
    Sum of Growth = 
    var _a = FORMAT( CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'[Year])),"General Number")
    var _b = CALCULATE(SUM('Dummy Data'[Growth]),FILTER('Table',[Year]=_a))
    var _c = CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'))
    var _d = CALCULATE(SUM('Dummy Data'[Growth]),FILTER(ALL('Table'),[Year]=FORMAT(_c,"General Number")))
    var _e = CALCULATE(SUM('Dummy Data'[Growth]),FILTER(ALL('Table'),[Year]=FORMAT(_c-1,"General Number")))
    return IF(MAX('Table'[Year])="Difference",_d-_e,_b)
    
    Sum of Transacted = 
    var _a = FORMAT( CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'[Year])),"General Number")
    var _b = CALCULATE(SUM('Dummy Data'[Transacted $]),FILTER('Table',[Year]=_a))
    var _c = CALCULATE(MAX('Dummy Data'[Year]),ALL('Dummy Data'))
    var _d = CALCULATE(SUM('Dummy Data'[Transacted $]),FILTER(ALL('Table'),[Year]=FORMAT(_c,"General Number")))
    var _e = CALCULATE(SUM('Dummy Data'[Transacted $]),FILTER(ALL('Table'),[Year]=FORMAT(_c-1,"General Number")))
    return IF(MAX('Table'[Year])="Difference",_d-_e,_b)
    
    Retention % = 
    DIVIDE([Sum of Cancles], [Sum of Transacted])
    
    NCVI = [Sum of Growth]-[Sum of Cancles]

    Final output:

    Best Regards,

    Jianbo Li

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