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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AlexPayette
Frequent Visitor

Rankx function showing all 1 in a calculated column

Hi,

 

I am trying to use the Rankx function to order my different shifts starting with 1 desc. I have a fact table which showcases my shifts everyday. There's two shifts, day shift (from 6h AM to 5:59:59 PM) and night shift (from 6h PM to 5:59:59).

 

When using the Rankx function, I am only obtaining all 1 or 1 and big numbers (passing from 1 to 512, etc.)

 

I would like to use this function to rank my different shifts, starting from the most recent shift (as 1). I have a fact table containing multiple rows for each shifts, and I woud like to be able to rank the shift based on the shift (start and end dates).

 

This is what I am trying to use as a function : 

 

=RANKX(
FILTER(
FactTable,
[Shift Start Date] = EARLIER('Table'[Shift Start Date)
&&
[Shift End Date] = EARLIER('Table'[Shift End Date)
),
[FactTable].[Date Dump],
,
DESC,
Dense)

 

This is what I would like my fact table to look like :

 

RefDateLoadRefDateDumpDate DumpDate Time DumpShift Start DateShift End DateRankLast 2 shiftsQuantity
20220928202209282022-09-282022-09-28 6:02:092022-09-28 06:00:002022-09-28 18:00:001TRUE1000
20220928202209282022-09-282022-09-28 11:10:112022-09-28 06:00:002022-09-28 18:00:001TRUE2000
20220927202209272022-09-272022-09-27 18:30:472022-09-27 18:00:002022-09-28 06:00:002TRUE3000
20220927202209272022-09-272022-09-27 21:45:582022-09-27 18:00:002022-09-28 06:00:002TRUE4000
20220927202209272022-09-272022-09-27 12:22:222022-09-27 06:00:002022-09-27 18:00:003FALSE

5000

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Rank = 
var ReferenceDate = 'Table'[Shift End Date]
return
CALCULATE(
    RANKX( ALL('Table'), 'Table'[Shift End Date], ReferenceDate , DESC, Dense ),
    ALLEXCEPT('Table', 'Table'[Shift Start Date], 'Table'[Shift End Date] )
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

Rank = 
var ReferenceDate = 'Table'[Shift End Date]
return
CALCULATE(
    RANKX( ALL('Table'), 'Table'[Shift End Date], ReferenceDate , DESC, Dense ),
    ALLEXCEPT('Table', 'Table'[Shift Start Date], 'Table'[Shift End Date] )
)

It worked, thanks !

amitchandak
Super User
Super User

@AlexPayette , You have use date time dump column

Column = RANKX(FILTER(Data, Data[Shift End Date] =EARLIER([Shift End Date]) && Data[Shift Start Date] = EARLIER([Shift Start Date])), [Date Time Dump],,DESC,Dense)

 

 

amitchandak_0-1666364522260.png

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

It's not working, it's giving me all 1 again.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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