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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Ranking

Hi all,

 

I'm trying to rank each customer's purchases chronologically based on their purchase date starting with "1" for each customer's first purchase and then sequencing numercially with each additional purchase (i.e. their 2nd purchase would populate rank as "2", etc.) 

I want the rank to start over from "1" with each individual client. As you can see for below for client, C100456 the formula is working correctly, but for client C100217 it isn't. 

 

Power BI Rank Issue.PNG

 

This is my current formula: 

Rank = RANKX(ALLEXCEPT(ep_Sales_Invoice_Line, ep_Sales_Invoice_Line[Customer_Name]), CALCULATE(MAX(ep_Sales_Invoice_Line[INVOICENUMBER])),,ASC, DENSE)-1

 

Thank you for all your help! 🙂 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Rank invoicenumber base measure: = 
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    CALCULATE ( MAX ( ep_Sales_Invoice_Line[INVOICENUMBER] ) ),
    ,
    ASC
)

 

Rank invoicedate base measure: = 
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    CALCULATE ( MAX ( ep_Sales_Invoice_Line[Invoice_Date] ) ),
    ,
    ASC
)

 

Rank measure: =
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    [Rank invoicedate base measure:] + [Rank invoicenumber base measure:] / 100,
    ,
    ASC
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Rank invoicenumber base measure: = 
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    CALCULATE ( MAX ( ep_Sales_Invoice_Line[INVOICENUMBER] ) ),
    ,
    ASC
)

 

Rank invoicedate base measure: = 
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    CALCULATE ( MAX ( ep_Sales_Invoice_Line[Invoice_Date] ) ),
    ,
    ASC
)

 

Rank measure: =
RANKX (
    FILTER (
        ALL ( ep_Sales_Invoice_Line ),
        ep_Sales_Invoice_Line[Customer_Account_Number]
            = MAX ( ep_Sales_Invoice_Line[Customer_Account_Number] )
    ),
    [Rank invoicedate base measure:] + [Rank invoicenumber base measure:] / 100,
    ,
    ASC
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Anonymous
Not applicable

Thank you so much, this fixed our problem 🙂 

rodrigosan
Responsive Resident
Responsive Resident

Hello, @Anonymous how are you?
I don't know if my solution can help you.
What I did was create a key in the fSales table with the date in numeric format (yyyymmdd) and with the CustomerKey.
After I duplicated this table, I left only the Data / CustomerKey / Key columns.
I created a group and inserted an index inside the group.
Then I expanded and merged with fSales table based on Key.
Then I disabled the copy load.
I have my example file here at this link: https://easyupload.io/mjew8f

 

Did I solve your problem?
Please mark as solution so others can find this solution.
https://www.linkedin.com/in/rodrigosanpbi/

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.