Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

difference of rows from same table

Hi,

I have a single table as shown below. the user can select upto two run ids from a slicer. so if the user selected 2,3 i would like to show a table which does Sum(amount; run id = 2) - Sum(amount; run id = 3) grouped by treaty and cal_year. i know it can be done from two different table but is there a way to do this within the same table. 

 

 

Input data:

 

run idtreatycal yearamount
1A2022100
1A2023110
1B2022120
1B2023130
1C2022140
1C2023150
2A2022160
2A2023170
2B2022180
2B2023190
2C2022200
2C2023210
3A2022220
3A2023230
3B2022240
3B2023250
3C2022260
3C2023270
  • Anonymous 

     

    you can try this

     

    Measure =
    var _id=sumx(FILTER(all('Table'),'Table'[treaty]=max('Table'[treaty])&&'Table'[cal year]=max('Table'[cal year])&&'Table'[run id]=min('Table'[run id])),'Table'[amount])
    var _id2=sumx(FILTER(all('Table'),'Table'[treaty]=max('Table'[treaty])&&'Table'[cal year]=max('Table'[cal year])&&'Table'[run id]=max('Table'[run id])),'Table'[amount])
    return _id-_id2
     
     
    pls see the attachment below
     
     

3 Replies

  • Anonymous 

     

    you can try this

     

    Measure =
    var _id=sumx(FILTER(all('Table'),'Table'[treaty]=max('Table'[treaty])&&'Table'[cal year]=max('Table'[cal year])&&'Table'[run id]=min('Table'[run id])),'Table'[amount])
    var _id2=sumx(FILTER(all('Table'),'Table'[treaty]=max('Table'[treaty])&&'Table'[cal year]=max('Table'[cal year])&&'Table'[run id]=max('Table'[run id])),'Table'[amount])
    return _id-_id2
     
     
    pls see the attachment below
     
     
  • Anonymous 

    Create a Measure

    AmountDifference = 
    VAR SelectedRuns = VALUES('Table'[run id])
    VAR Run1 = CALCULATE(SUM('Table'[amount]), 'Table'[run id] = MIN(SelectedRuns))
    VAR Run2 = CALCULATE(SUM('Table'[amount]), 'Table'[run id] = MAX(SelectedRuns))
    RETURN
    IF(COUNTROWS(SelectedRuns) = 2, Run1 - Run2, BLANK())

    Use Treaty and Cal Year as row fields, and place AmountDifference as the value.

     

    💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
    Cheers,
    Kedar
    Connect on LinkedIn

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks for this but i get an erorr saying