Forum Discussion

Gustavo_Rdz's avatar
Gustavo_Rdz
New Member
5 years ago
Solved

Subtract rows in a Table based on a id

Hi,   I have the followig data and I trying to subtract te row with  index 1 from the row with index 2.   TXN_START_DATE   PRODUCT   AMOUNT   INDEX   RESULT 14/03/2021   A   15 ...
  • Jihwan_Kim's avatar
    5 years ago

    Hi, Gustavo_Rdz 

    Please check the below, which is for creating a new measure.

     

     

    Result =
    VAR currentdate =
    MAX ( 'Table'[TXN_START_DATE] )
    VAR amountindextwo =
    CALCULATE (
    SUM ( 'Table'[AMOUNT] ),
    FILTER (
    ALL ( 'Table' ),
    'Table'[TXN_START_DATE] = currentdate
    && 'Table'[INDEX] = 2
    )
    )
    VAR amountindexone =
    CALCULATE (
    SUM ( 'Table'[AMOUNT] ),
    FILTER (
    ALL ( 'Table' ),
    'Table'[TXN_START_DATE] = currentdate
    && 'Table'[INDEX] = 1
    )
    )
    RETURN
    IF ( SELECTEDVALUE ( 'Table'[INDEX] ) = 2, amountindextwo - amountindexone, "" )

     

     

     

    Hi, My name is Jihwan Kim.

     

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

     

    Linkedin: linkedin.com/in/jihwankim1975/

    Twitter: twitter.com/Jihwan_JHKIM