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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
gp10
Advocate III
Advocate III

Rank of Days with an Occurance

Hi community,

Lets say my data are sales, employees and dates.
I would like to create a column where I will have a count of dates whith transactions, that will be irrelevant from the amount of the transactions, but specific for employees.

Every employee has a different working schedule, and they do not work the same amount of days each week, month etc.
I want to able to see how each employee performed based on their working days. So, I would like to create a slicer with options like "First 30 Days", "First 100 Days" etc. In order to do so I need this ranking column.

So this is what I would like to achieve: 

Date TimeSales ID Employee Name Sales Working Date Count
1.1.22 12:00PM   1

  John

  1
1.1.22 13:00PM   2  Jack  1
1.1.22 13:00PM  3  John  1
1.1.22 14:00PM  4  Mary  1
2.1.22 13:00PM  5  John  2
2.1.22 14:00PM  6  Mary  2
2.1.22 15:00PM  7  Mary  2
3.1.22 11:00AM  8  Jack  2
3.1.22 12:00PM  9  Mary  3
3.1.22 16:00PM  10  Mary  3
4.1.22 11:00AM  11  Mary  4
4.1.22 12:00PM  12  Jack3
4.1.22 16:00PM  13  Jack3


I would prefer the best solution for this performance wise either in Power Query or as a calculated column.
In MySQL it could be even better...

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Adding a date column as a helper column make it much easier; but that's no fun at all. I avoid it on purpose for fun only.

 

PQ solution,

CNENFRNL_0-1654167004110.png

 

Caculated Column solution,

CNENFRNL_1-1654167181612.png

 

Stay tuned for SQL solution after my lunch break ...

=========================================

The most concise solution (T-sql),

CNENFRNL_0-1654172346301.png

 

Bonus solution by powerful Excel formula,

CNENFRNL_1-1654173324762.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

Adding a date column as a helper column make it much easier; but that's no fun at all. I avoid it on purpose for fun only.

 

PQ solution,

CNENFRNL_0-1654167004110.png

 

Caculated Column solution,

CNENFRNL_1-1654167181612.png

 

Stay tuned for SQL solution after my lunch break ...

=========================================

The most concise solution (T-sql),

CNENFRNL_0-1654172346301.png

 

Bonus solution by powerful Excel formula,

CNENFRNL_1-1654173324762.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL,
one more question. If we want to add one more column in the grouping.
For example we rank the days by Employee and Sales, what if we wanted a Store column as well. Meaning different rank for each store.
I have managed to do it in DAX, but having some difficulties in M and SQL.

Legendary stuff @CNENFRNL , thanks a lot, what a reply!
Will test all of them.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.