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
SabineOussi
Skilled Sharer
Skilled Sharer

Dates Raking with Selection

Hello,

 

I have a set of orders made by different departments and I am trying to rank them according to the sequence of orders (1st, 2nd, 3rd, ...) and the dates.

 

Here's a sample of the data

SAMPLE.PNG

 

If I want to choose only departments A and B, I should get this

AB.PNG

B, D, and E

BDE.PNG

 

etc.

 

I saw this post http://community.powerbi.com/t5/Desktop/DAX-Ranking-or-Indexing-Dates/m-p/41239#M15579 but couldn't get to the solution I want.

 

Any help is appreciated.
Thank you.

 

 

5 REPLIES 5
AlexChen
Microsoft Employee
Microsoft Employee

Hi,

 

You can create a numeric calculate column for Date.

 

Column = VALUE(YEAR(Department[Date]) & if(MONTH(Department[Date]) < 10, "0" & MONTH(Department[Date]), MONTH(Department[Date])) & if(DAY(Department[Date]) < 10, "0" & DAY(Department[Date]), DAY(Department[Date])))

 

Then create a Rank measure within each Department group.

 

Measure = RANKX(ALLEXCEPT(Department,Department[Department]),CALCULATE(sum(Department[Column])),,ASC, Dense) - 1

 

This is the result:

 

1.png

 

2.png

 

3.png

 

Best Regards

Alex

 

Thank you Alex.

 

Your solution functions perfeclty when I have distinct dates.

But when I have the same date for the same department, measure does not work as it should.

Multiple Dates.PNG

Multiple Dates Data.PNG

 

Any suggestions on how to fix this?

Thanks again.

Hi,

 

If you have only 2 columns in Department table, I suggest you using following code to remove duplicated records in a new table.

 

Department2 = DISTINCT(Department)

 

Then create the same “Column” and “Measure” just as I wrote in my reply above for Department2.

 

Best Regards

Alex

 

Thank you Alex for your help.

 

The thing is they are not duplicated records. Only the department and the date are the same while other columns like quantity and description differ. So a department can make many orders during the same day, that's why I cannot remove any record.

 

I'm not sure if this is feasible...

 

Thanks.

SabineOussi
Skilled Sharer
Skilled Sharer

Hello, 

 

I have a set of orders made by different departments and I am trying to rank them according to the sequence of orders (1st, 2nd, 3rd, ...) and the dates.

 

Here's a sample of the data

SAMPLE.PNG

 

If I want to choose only departments A and B, I should get this

AB.PNG

 

B, D, and E

BDE.PNG

etc.

 

I saw this post http://community.powerbi.com/t5/Desktop/DAX-Ranking-or-Indexing-Dates/m-p/41239#M15579 but couldn't get to the solution I want.

 

Any help is appreciated.

Thank you.

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.