Forum Discussion
Rank based on datetime
Hi,
I need some help.
I want to add a Rank column to below table based on the AgentID and Datetime column.
So the most recent Datetime for the agent should be 0, then 1 so on
If for any agent (i.e AgentID 3) Datetime is same and has AgentStatis "on Call" then that should be ranked 0. Otherwise any can be ranked 0
| AgentID | AgentStatus | DateTime | Rank (New Column) |
| 1 | Log in | 10/02/21 15:05:50 | 0 |
| 1 | On Call | 10/02/21 12:10:10 | 1 |
| 1 | Break | 09/02/21 16:05:52 | 2 |
| 2 | Log in | 10/02/21 02:05:39 | 0 |
| 2 | Log in | 10/02/21 01:10:22 | 1 |
| 3 | On Call | 10/02/21 12:05:15 | 0 |
| 3 | Log Off | 10/02/21 12:05:15 | 1 |
Thanks
Daven
Anonymous try this measure
Rank = VAR __countFlag = CALCULATE ( COUNTROWS ( 'Rank' ), ALLEXCEPT ( 'Rank', 'Rank'[AgentID], 'Rank'[DateTime] ) ) VAR __rank = RANKX ( ALLEXCEPT ( 'Rank', 'Rank'[AgentID] ), CALCULATE ( MIN ( 'Rank'[DateTime] ) ), , DESC, DENSE ) RETURN IF ( __countFlag > 1 && MAX ( 'Rank'[AgentStatus] ) = "On Call", 0, __rank - IF ( __countFlag = 1, 1, 0 ) )Check my latest blog post Compare Budgeted Scenarios vs. Actuals 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.⚡
2 Replies
- parry2kSuper User
Anonymous try this measure
Rank = VAR __countFlag = CALCULATE ( COUNTROWS ( 'Rank' ), ALLEXCEPT ( 'Rank', 'Rank'[AgentID], 'Rank'[DateTime] ) ) VAR __rank = RANKX ( ALLEXCEPT ( 'Rank', 'Rank'[AgentID] ), CALCULATE ( MIN ( 'Rank'[DateTime] ) ), , DESC, DENSE ) RETURN IF ( __countFlag > 1 && MAX ( 'Rank'[AgentStatus] ) = "On Call", 0, __rank - IF ( __countFlag = 1, 1, 0 ) )Check my latest blog post Compare Budgeted Scenarios vs. Actuals 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.⚡
- AnonymousNot applicable
Thanks Parry
It worked!