Forum Discussion
Need help reset count
Hi All,
I've tried to calculate the total infected and recovered users every month, the total recovered doesn't matter but the total infected when the same users are infected again after recovery the calculation doesn't work.
My table:
This is my DAX for it:
I'd recommend looking at whatever the last status was.
Try something like this:
CountInfected = VAR LastStatusDates = ADDCOLUMNS ( VALUES ( Summary[User] ), "@LastStatusDate", CALCULATE ( MAX ( Summary[Date] ) ) ) RETURN SUMX ( LastStatusDates, LOOKUPVALUE ( Summary[Infected], Summary[User], Summary[User], Summary[Date], [@LastStatusDate] ) )
6 Replies
- parry2kSuper User
Anonymous based on the data seems like everyone is recovered, how you expected answer to be 1
✨ Follow us on LinkedIn
Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- AlexisOlsonSuper User
A is reinfected in the last row.
- AlexisOlsonSuper User
I'd recommend looking at whatever the last status was.
Try something like this:
CountInfected = VAR LastStatusDates = ADDCOLUMNS ( VALUES ( Summary[User] ), "@LastStatusDate", CALCULATE ( MAX ( Summary[Date] ) ) ) RETURN SUMX ( LastStatusDates, LOOKUPVALUE ( Summary[Infected], Summary[User], Summary[User], Summary[Date], [@LastStatusDate] ) )- AnonymousNot applicable
Perfect, It works as required too in different ways. Great Support. Thanks AlexisOlson
- parry2kSuper User
AlexisOlson got it. I missed that. Thanks for pointing that out.
Anonymous Here is a measure.
Total Infected = VAR __table = TOPN ( 1, ALLSELECTED ( 'Table' ), CALCULATE ( MAX ( 'Table'[Date] ), VALUES ( 'Table'[User] ) ), DESC ) VAR __totalInfected = CALCULATE ( SUM ( 'Table'[Infected] ), KEEPFILTERS ( __table ) ) - CALCULATE ( SUM ( 'Table'[Recovered] ), KEEPFILTERS ( __table ) ) RETURN IF ( __totalInfected > 0, __totalInfected )- AnonymousNot applicable
It works as required. Great Support. Thanks, parry2k