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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
V-pazhen-msft
Community Support
Community Support

@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
V-pazhen-msft
Community Support
Community Support

@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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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