Forum Discussion
Subtracting two rows based on conditions
- 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.
Hi v-zhangti
The date field is applied across all of the fields, meaning that you have date in a column where it is present - I am working with a very large data set, so everything is from the same source and everything have a date.
The first time I presented data I just showed some test data, as I cannot post the real data. But what I am working with is Portfolios in which there are some InstrumentSecurityID's then on a monthly basis I receive an output file which contains new information as the market has developed during the month. I am creating this report to quickly do a performance report, so yes there is a relation to Holding Value and the relation is like:
| AsOfDate | Aktivklasse | AltPortfolioName | PortfolioNbr | InstrumentSecurityId | Holding Value |
| 31-01-2022 | Repo | Repo | 150 | US000x0000 | 100 |
| 31-01-2022 | Bonds | Bonds US | 110 | US000x0000 | 50 |
| 28-02-2022 | Repo | Repo | 150 | US000x0000 | 200 |
| 28-02-2022 | Bonds | Bonds US | 110 | US000x0000 | 300 |
An Example only involving Portfolio 110 with AsOfDate = 31-01-2022, but it is the same for 120 as it should be summed with 150 as well on a InstrumentSecurityID level.
So what I want is to have a slicer selecting the data and then the following table which sums depending on the date selected by the slicer:
| AsOfDate | Aktivklasse | AltPortfolioName | PortfolioNbr | InstrumentSecurityId | Holding Value |
| Selected by Slicer (in this example 31-01-2022) | Bonds | Bonds US | 110 | US000x0000 | 100 + 50 = 150 |
Please let me know if you need some furhter explanation and please be aware that the same InstrumentSecurityID can be present in other portfolios and the holding values from these shouldn't be included in the above.
Best Regards
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.