Forum Discussion
Calculate difference between current and previous row with a condition
- 3 years ago
Hi Sultanista ,
You can try this method:
New column:
Diff = VAR _curr = CALCULATE ( SUM ( 'Table'[Applicants] ), 'Table'[Agregation Type] = "All Branches - YTD" ) RETURN IF ( [Fiscal Month] = 1 || 'Table'[Agregation Type] <> "All Branches - YTD" || ISBLANK ( 'Table'[Applicants] ), BLANK (), _curr - CALCULATE ( SUM ( 'Table'[Applicants] ), FILTER ( 'Table', [Agregation Type] = "All Branches - YTD" && [Fiscal Year] = EARLIER ( 'Table'[Fiscal Year] ) && [Fiscal Month] = EARLIER ( 'Table'[Fiscal Month] ) - 1 ) ) )The result is:
Hope this helps you. Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Sultanista ,
You can try this method:
New column:
Diff =
VAR _curr =
CALCULATE (
SUM ( 'Table'[Applicants] ),
'Table'[Agregation Type] = "All Branches - YTD"
)
RETURN
IF (
[Fiscal Month] = 1
|| 'Table'[Agregation Type] <> "All Branches - YTD"
|| ISBLANK ( 'Table'[Applicants] ),
BLANK (),
_curr
- CALCULATE (
SUM ( 'Table'[Applicants] ),
FILTER (
'Table',
[Agregation Type] = "All Branches - YTD"
&& [Fiscal Year] = EARLIER ( 'Table'[Fiscal Year] )
&& [Fiscal Month]
= EARLIER ( 'Table'[Fiscal Month] ) - 1
)
)
)
The result is:
Hope this helps you. Here is my PBIX file.
Best Regards,
Community Support Team _Yinliw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
It works great! Is it possible to move those results from current place to the corresponding fiscal year and month but aggregation type = All Branches - MTD ?
And having the 1st value of the year (month =1) same as in YTD?