Forum Discussion
Rank date in PowerBI
Hi,
I'm looking for a DAX formule to rank the date kolomn. No extra filters on Client ect, just rank the date.
Every month new data is loaded in the PowerBI model. Now i want to add a Kolomn so that 1 = newest month, 2 = month before, ect. Can someone help me on this?
Table:
| Month | Client | Amount |
| jan-20 | 1 | 100 |
| feb-20 | 1 | 122 |
| feb-20 | 1 | 1 |
| mar-20 | 1 | 140 |
Outcome:
| Month | Client | Amount | RANK |
| jan-20 | 1 | 100 | 3 |
| feb-20 | 1 | 122 | 2 |
| feb-20 | 1 | 1 | 2 |
| mar-20 | 1 | 140 | 1 |
- Anonymous6 years ago
Hello @tomwolswijk ,
You can test this calculated column.
Rank = RANKX ( 'Table', RANKX ( 'Table', YEAR ( 'Table'[Date] ),, DESC, DENSE ) * 100 + RANKX ( 'Table', MONTH ( 'Table'[Date] ),, DESC, DENSE ), , ASC, DENSE )More details can be found here.
Best regards
Stephen Tao
If this post helps,then consider Accepting it as the solution to help other members find it faster.
7 Replies
- amitchandakSuper User
you can use all except or sub-category for month
For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415- tomwolswijkHelper I
I tried;
Rank =RANKX( (ALLSELECTED ( Table[Month] ),CALCULATE ( SELECTEDVALUE ( Table[Month] ) ),,ASC))But did not work... Can you help?- amitchandakSuper User
tomwolswijk , I created a measure and then used Rank
Measure = CALCULATE(SUM('Table (2)'[Amount]) ,ALLEXCEPT('Table (2)','Table (2)'[Month])) Measure 2 = rankx(ALL('Table (2)'[Month]),[Measure])
- AnonymousNot applicable
Hello @tomwolswijk ,
You can test this calculated column.
Rank = RANKX ( 'Table', RANKX ( 'Table', YEAR ( 'Table'[Date] ),, DESC, DENSE ) * 100 + RANKX ( 'Table', MONTH ( 'Table'[Date] ),, DESC, DENSE ), , ASC, DENSE )More details can be found here.
Best regards
Stephen Tao
If this post helps,then consider Accepting it as the solution to help other members find it faster.
- tomwolswijkHelper I
Thanks a lot! It worked!
I used 'Table'[Month] instead of 'Table'[Date], because month is already a date data type. Thanks!
- MarlowNew Member
thanks