Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I am trying to create a rankx measure that will create a row number by date but also partitioned by category. This will also dynamically update when the user changes the date filter. For example:
| Category | Date | rn |
| a | 01/01/2022 | 1 |
| a | 02/01/2022 | 2 |
| a | 03/01/2022 | 3 |
| b | 01/01/2022 | 1 |
| c | 02/01/2022 | 1 |
| d | 03/01/2022 | 1 |
If the user then change the date slicer to 02/01/2022 - 03/01/2022 the result would be:
| Category | Date | rn |
| a | 02/01/2022 | 1 |
| a | 03/01/2022 | 2 |
| c | 02/01/2022 | 1 |
| d | 03/01/2022 | 1 |
Any help would be most welcome!
Solved! Go to Solution.
Hi @Anonymous
Something like this (replace Table references as necessary):
rn =
VAR CurrentDate =
SELECTEDVALUE ( YourTable[Date] )
VAR RankingTable =
CALCULATETABLE (
SUMMARIZE ( YourTable, YourTable[Date] ),
ALLSELECTED (), -- filter context of visual
VALUES ( YourTable[Category] ) -- retain current Category filter
)
RETURN
RANKX (
RankingTable,
YourTable[Date],
CurrentDate,
ASC
)
Regards,
Owen
For fun only, the logical is replicated in Excel,
| Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Thanks CNENFRNL, this worked also.
Hi @Anonymous
Something like this (replace Table references as necessary):
rn =
VAR CurrentDate =
SELECTEDVALUE ( YourTable[Date] )
VAR RankingTable =
CALCULATETABLE (
SUMMARIZE ( YourTable, YourTable[Date] ),
ALLSELECTED (), -- filter context of visual
VALUES ( YourTable[Category] ) -- retain current Category filter
)
RETURN
RANKX (
RankingTable,
YourTable[Date],
CurrentDate,
ASC
)
Regards,
Owen
Hi OwenAuger, after getting the row number I am trying to count the categories where the row number = 1 which I thought would be a simple calculate function:
I'm thinking something like this, if you want to count the number of times [_rn]=1 in that particular visual, assuming you're placing this as a standalone measure outside the original visual.
Count RN =
SUMX (
SUMMARIZE (
Table,
Table[Category],
Table[Date]
),
IF ( [_rn] = 1, 1 )
)
Thanks OwenAuger, this 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!
| User | Count |
|---|---|
| 21 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 35 | |
| 31 | |
| 20 | |
| 13 | |
| 10 |