Forum Discussion

Solle's avatar
Solle
Icon for Helper III rankHelper III
4 years ago
Solved

Subtracting two rows based on conditions

Hi,  As I have started to use PowerBI I have stumbled upon a problem, in which I haven't been able to find any posts or useful answers to.  I have the following columns which is used as rows in...
  • v-zhangti's avatar
    v-zhangti
    4 years ago

    Hi, Solle 

     

    It is simple to add date specific filtering to the original formula.

    New Holding Value = 
    IF (
        SELECTEDVALUE ( 'Table'[PortfolioNbr] ) = 110,
        CALCULATE (
            SUM ( 'Table'[Holding Value] ),
            FILTER (
                ALL ( 'Table' ),
                [InstrumentSecurityID] = MAX ( 'Table'[InstrumentSecurityID] )&&[AsOfDate]=SELECTEDVALUE('Table'[AsOfDate])
            )
        ),
        IF (
            SELECTEDVALUE ( 'Table'[PortfolioNbr] ) = 120,
            CALCULATE (
                SUM ( 'Table'[Holding Value] ),
                FILTER (
                    ALL ( 'Table' ),
                    [InstrumentSecurityID] = MAX ( 'Table'[InstrumentSecurityID] )&&[AsOfDate]=SELECTEDVALUE('Table'[AsOfDate])
                )
            ),
            SELECTEDVALUE ( 'Table'[Holding Value] )
        )
    )

    Did this result meet your expectations?

     

    Best Regards,

    Community Support Team _Charlotte

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