Forum Discussion
Using RANKX to rank dates across various combinations of unique categories
So I have an interesting use-case for something like this.
Let's say we have the following table that summarizes meetings with customers, that lists:
- The Name of our Sales Rep
- The customer they met
- Whether the meeting was in-person or over the phone,
- The date the meeting happened
What I'm trying to do is run a RANKX based on the date column, so it sorts from earliest to latest. However, I want this RANKX to work across unique combinations of the first 3 columns. So the expected output for instance should be:
Essentially, each unique combination of the first 3 categories is treated as a unique category for the purposes of rankx, and then it's sorted by the date.
As an example, Sarah (column 1) met with Customer 3 (column 2) via in-person meetings (column 3) 3 separate times, so the rank goes up to 3 for that scenario.
I'm unclear how to go about starting to create this rankx calculated column.
What I probably want is some variation of the following that actually works:
Rank = RANKX(
I just can't seem to structure the DAX quite right to achieve the intended effect!
Hi rainynights ,
Try this DAX:Column 3 = RANKX( FILTER( 'Table', [Sales Rep] = EARLIER('Table'[Sales Rep]) && [Customer] = EARLIER('Table'[Customer]) && [Meeting Type] = EARLIER('Table'[Meeting Type]) ), [Date].[Date], , ASC, Dense)Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- v-lionel-msft
Community Support
Hi rainynights ,
Try this DAX:Column 3 = RANKX( FILTER( 'Table', [Sales Rep] = EARLIER('Table'[Sales Rep]) && [Customer] = EARLIER('Table'[Customer]) && [Meeting Type] = EARLIER('Table'[Meeting Type]) ), [Date].[Date], , ASC, Dense)Best regards,
Lionel ChenIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- rainynights
Helper II
That worked beautifully, thank you so much v-lionel-msft!
- amitchandak
Super User
Refer if this can help.If not. If possible please share a sample pbix file after removing sensitive information.
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p/881739
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601- rainynights
Helper II
Hi amitchandak , here's a link to a sample PBIX file:
I came across the link you shared too, but it doesn't seem to apply to my kind of specific scenario of constructing unique categories based on unique combinations across many columns.