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
Anonymous
Not applicable

Find middle date in between first and last date, and put in column

I have a table like this:

idtimestamptemperaturefirst date - idlast date - idmiddle date - idfirst, last, middle
11/1/20 1:00 AM14TRUEFALSE First
11/1/20 2:00 PM12.4FALSEFALSE na
11/1/20 8:00 AM16.3FALSEFALSE na
11/2/20 1:00 AM14.2FALSEFALSE na
11/2/20 2:00 PM15.9FALSEFALSE na
11/2/20 8:00 AM14.5FALSEFALSE na
11/3/20 1:00 AM13.2FALSEFALSE na
11/3/20 2:00 PM19.3FALSETRUE Last
11/3/20 8:00 AM16.9FALSEFALSE na
21/1/20 1:00 AM14.3TRUEFALSE First
21/1/20 2:00 PM12.4FALSEFALSE na
21/1/20 8:00 AM16.3FALSEFALSE na
21/2/20 1:00 AM14.2FALSEFALSE na
21/2/20 1:00 PM15.9FALSEFALSE na
21/2/20 8:00 AM14.5FALSEFALSE na
21/3/20 2:00 AM13.2FALSEFALSE na
21/3/20 1:00 PM13.5FALSETRUE Last
21/3/20 8:00 AM16.9FALSEFALSE na

 

I have calculated the first and laste date using this formula: IF(tabledb[timestamp]=CALCULATE(MIN(tabledb[timestamp]),ALLEXCEPT('tabledb', 'tabledb'[id])),True)

 

How can I get the middle date in a format like last and first, and then create a new column to show first, middle and last date for every id, like shown in table above for first and last date.

 

Thanks a lot.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous 

I recommend you first ranked the timestamp for each id. Then use MEDIAN to get the middle rank for each id.

Rank= RANKX(FILTER(Tabledb,[id]=EARLIER(Tabledb[id])),Tabledb[timestamp],,ASC,Dense)

firstmidlast = 
IF(Tabledb[Rank]=MIN(Tabledb[Rank]),"first",IF(Tabledb[Rank]=MAX(Tabledb[Rank]),"last",IF(Tabledb[Rank]=MEDIAN(Tabledb[Rank]),"mid")))

midfirstlast.JPG


Best,
Paul

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@Anonymous 

I recommend you first ranked the timestamp for each id. Then use MEDIAN to get the middle rank for each id.

Rank= RANKX(FILTER(Tabledb,[id]=EARLIER(Tabledb[id])),Tabledb[timestamp],,ASC,Dense)

firstmidlast = 
IF(Tabledb[Rank]=MIN(Tabledb[Rank]),"first",IF(Tabledb[Rank]=MAX(Tabledb[Rank]),"last",IF(Tabledb[Rank]=MEDIAN(Tabledb[Rank]),"mid")))

midfirstlast.JPG


Best,
Paul

amitchandak
Super User
Super User

create rank inside each id.  crease dense rank

refer -https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

create rank as column.

 

Now using that you can use min and max of rank try to find middle rank and use that.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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