Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
memoalkatib1
Frequent Visitor

RANKX measure for each group

I have a live connection to a "locked" dataset that sits on top of a SSAS model. so I can only create measures. I have a table that has a bunch of columns including CustomerID , ProductID and Date Purchased along with 20 other columns. I would like to rank by customerID, Product ID based on Date Purchased Descending. This would repeat for each customer & productID . I need this done by a calculated measure that must be compatible with Direct Query/ Live Connection. 

here how I am picturing the ranking to apply (I'm not displaying this data like this on a visual/dashboard)

Ex : 

 

CustomerID    ProductID      Date Purchased    Rank
1234                       1                 1-1-2023           1
1234                        1                 1-1-2022          2
1234                        2                 1-1-2019          1
3456                        1                 1-1-2020          1
3456                        1                 1-1-2018          2
3456                        6                 1-1-2020          1

1 ACCEPTED SOLUTION
DAXDigger
Regular Visitor

@memoalkatib1 please try below measure

Rankx = RANKX(FILTER(ALL('Table'),'Table'[CustomerID] = MAX('Table'[CustomerID]) && 'Table'[ProductID] = MAX('Table'[ProductID])),CALCULATE(MAX('Table'[Date Purchased])),,DESC)

 

DAXDigger_0-1678424737225.png

 

View solution in original post

2 REPLIES 2
memoalkatib1
Frequent Visitor

Thanks @DAXDigger . but the syntax for the code has multiple errors. I also think based off reading the code it'sef that the rating does not repeat for each customer+Product ID. also are you able why you're using max function ? 

DAXDigger
Regular Visitor

@memoalkatib1 please try below measure

Rankx = RANKX(FILTER(ALL('Table'),'Table'[CustomerID] = MAX('Table'[CustomerID]) && 'Table'[ProductID] = MAX('Table'[ProductID])),CALCULATE(MAX('Table'[Date Purchased])),,DESC)

 

DAXDigger_0-1678424737225.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors