Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
Solved! Go to Solution.
@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.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@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.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Thanks Parry
It worked!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!