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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
akfir
Helper V
Helper V

Ranking Orders by date and customer for product X

Hi masters,
I wish to a add a calculated column of ranking orders by date and customer for a specific Product. Demo data below:

akfir_0-1696752397967.png

please assist with the correct DAX

thanks!

1 ACCEPTED SOLUTION

Assuming you have a table named Orders with columns OrderID and OrderDate, you can add a calculated column to calculate the day of the year and then use it for sorting:

 

 

 

DayOfYear = YEAR(Orders[OrderDate]) * 1000 + DAYOFYEAR(Orders[OrderDate])

 

 

 

This expression combines the year and the day of the year to create a unique numeric value like 2023001 for January 1st, 2023, and so on
1. Now, you can sort the OrderID based on this calculated column. Go to the "Modeling" tab and select the Orders table.

2. In the "Sort by Column" option, choose the DayOfYear column
3.Finally, make sure to use the DayOfYear column as the sorting column in your visuals where you want to sort by this rank.

 

OR

OrderSequence =
RANKX(
    FILTER(
        Orders,
        Orders[CustomerID] = EARLIER(Orders[CustomerID]) &&
        Orders[ProductID] = EARLIER(Orders[ProductID])
    ),
    Orders[OrderDate]
)

 

View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

ThxAlot_0-1696791000373.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



_elbpower
Resolver III
Resolver III

What if you just take the day of year?

didnt understand your suggestion.
i need to figure out what is the customer X product 1st order, 2nd order, 3rd and so on... day of year has nothing to do with that.

Assuming you have a table named Orders with columns OrderID and OrderDate, you can add a calculated column to calculate the day of the year and then use it for sorting:

 

 

 

DayOfYear = YEAR(Orders[OrderDate]) * 1000 + DAYOFYEAR(Orders[OrderDate])

 

 

 

This expression combines the year and the day of the year to create a unique numeric value like 2023001 for January 1st, 2023, and so on
1. Now, you can sort the OrderID based on this calculated column. Go to the "Modeling" tab and select the Orders table.

2. In the "Sort by Column" option, choose the DayOfYear column
3.Finally, make sure to use the DayOfYear column as the sorting column in your visuals where you want to sort by this rank.

 

OR

OrderSequence =
RANKX(
    FILTER(
        Orders,
        Orders[CustomerID] = EARLIER(Orders[CustomerID]) &&
        Orders[ProductID] = EARLIER(Orders[ProductID])
    ),
    Orders[OrderDate]
)

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.