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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
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.