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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

RANKING ORDERS BY CUSTOMER

Hi everyone,

 

I have a classical customers and sales table.

 

I would like to know in my sales tables (in a calculated column) for each customers which order is the first, which order is the second, the third ect...

 

This means I want to rank my orders/customers from the oldest to the most recent.

 

order_idcustomer_idorder_rank
32211001
32211001
45521002
44781003
15522511
15522511
62212512
75513501
75513501
85503502
85513503
91203504
91203504

It's a little bit hard for me to explain in english what i need but i hope its okay this way.

 

Thanks a lot for your help,

Regards

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Picture1.png

 

order-rank CC =
VAR currentcustomer = 'Table'[customer_id]
RETURN
RANKX (
FILTER ( 'Table', 'Table'[customer_id] = currentcustomer ),
'Table'[order_id],
,
ASC,
DENSE
)

 

 

https://www.dropbox.com/s/6uv76w7q1p91ypg/paulmight.pbix?dl=0 

 

 


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

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

PaulOlding
Solution Sage
Solution Sage

Hi.  I'm not clear how you know what the most recent order is.  Is it based on the order_id as a number, or is there an order table with a date on it?

 

This just uses the order_id

calc_order_rank =
RANKX(
CALCULATETABLE('Table', ALLEXCEPT('Table', 'Table'[customer_id])),
'Table'[order_id],
, ASC, Dense
)
 
If you have an order date in a Orders table you'd swap 'Table'[order_id] for RELATED(Orders[order_date])

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,

 

Thank you for your replys, both solutions works perfectly.

 

What if i want to rank my orders only for the year 2021 ? first order of 2021 ect..

 

Regards,

Paul

PaulOlding
Solution Sage
Solution Sage

Hi.  I'm not clear how you know what the most recent order is.  Is it based on the order_id as a number, or is there an order table with a date on it?

 

This just uses the order_id

calc_order_rank =
RANKX(
CALCULATETABLE('Table', ALLEXCEPT('Table', 'Table'[customer_id])),
'Table'[order_id],
, ASC, Dense
)
 
If you have an order date in a Orders table you'd swap 'Table'[order_id] for RELATED(Orders[order_date])
Jihwan_Kim
Super User
Super User

Picture1.png

 

order-rank CC =
VAR currentcustomer = 'Table'[customer_id]
RETURN
RANKX (
FILTER ( 'Table', 'Table'[customer_id] = currentcustomer ),
'Table'[order_id],
,
ASC,
DENSE
)

 

 

https://www.dropbox.com/s/6uv76w7q1p91ypg/paulmight.pbix?dl=0 

 

 


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

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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