Forum Discussion
How to get the difference between 2 rows in a column for category
I want to get the difference between the successive rows in a column(Confirmed_cases). I have indexed the columns by category but can't go further. Please help.
Newbie992 try this
Diff = VAR __index = SELECTEDVALUE ( 'Table'[Index] ) VAR __prevIndex = __index - 1 VAR __prevValue = CALCULATE ( SUM ( 'Table'[Confirmed_cases] ), ALLEXCEPT ( 'Table', 'Table'[Location_Key] ), 'Table'[Index] = __prevIndex ) RETURN SUM ( 'Table'[Confirmed_cases] ) - __prevValueI would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
6 Replies
- parry2k
Super User
Newbie992 try this measure
Diff = VAR __index = SELECTEDVALUE ( Table[Index ) VAR __prevIndex = __index - 1 VAR __country = SELECTEDVALUE Table[Country] ) VAR __prevValue = CALULATE ( SUM ( Table[Cases] ), Table[Index] = __prevIndex, Table[Country] = __country ) RETURN SUM ( Table[Cases] ) - __prevValueI would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
- Newbie992Regular Visitor
Hi,
Thanks for your reply!
It's not working for me. In the result, I get the same values that are in Confirmed_cases column. I checked and in the variable _prevValue I am not getting any values.
Thanks!