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

Calculate 5th date from max date

Hello All,

 

I am trying to get the last fifth date from the max date in my table.

 

EmpIDDateDaytype

A21/10/2018WO
A22/10/2018AB
A23/10/2018AB
B24/10/2018AB
A25/10/2018AB
A26/10/2018AB
A27/10/2018WO
A28/10/2018WO
A29/10/2018AB
A30/10/2018AB
B21/10/2018WO
B22/10/2018AB
B23/10/2018AB
B24/10/2018AB
B25/10/2018AB
B26/10/2018AB
B27/10/2018WO
B28/10/2018WO
B29/10/2018AB
B31/10/2018AB

 

This is the data that iam working on.

 

And my query looks like this.

 

Last5thDate = CALCULATE(MAX(Table[Date]),
    FILTER(ALLEXCEPT(Table,Table[EmpID]),
        NOT(Table[Daytype]="WO" )))-4

But it gives me wrong output as 26/10/2018 for A and 27 for B

 

Can any one please help me out.

 

MohanV

 

 

1 ACCEPTED SOLUTION
petrovnikitamai
Resolver V
Resolver V

new column = 
var rankk = RANKX(FILTER('Table';EARLIER('Table'[EmpID])='Table'[EmpID]&&EARLIER('Table'[Daytype])='Table'[Daytype]);'Table'[Date];;DESC)
var last5thDate = IF(rankk=5&&[Daytype]<>"WO";[Date];BLANK())
return last5thDate

try this

image.png

View solution in original post

7 REPLIES 7
petrovnikitamai
Resolver V
Resolver V

new column = 
var rankk = RANKX(FILTER('Table';EARLIER('Table'[EmpID])='Table'[EmpID]&&EARLIER('Table'[Daytype])='Table'[Daytype]);'Table'[Date];;DESC)
var last5thDate = IF(rankk=5&&[Daytype]<>"WO";[Date];BLANK())
return last5thDate

try this

image.png

Greg_Deckler
Community Champion
Community Champion

If I am reading your formula correctly, it looks like you want to find the 5th date from the MAX date that doesn't involve WO's, only AB's, is that correct?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler Yes..you got it right...

Any help

@Anonymous - See if this works for you. Page 3 of the attached file (Table6). 

 

Measure 3 = 
VAR __emplID = MAX('Table6'[EmplID])
VAR __table = FILTER('Table6',[EmplID]=__emplID && [Daytype]="AB")
VAR __table1 = ADDCOLUMNS(__table,"__rank",RANKX(__table,[Date]))
RETURN MAXX(FILTER(__table1,[__rank]=5),[Date])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler @petrovnikitamai thanks for your help.

 

Both the solutions works perfectly..

 

But I am looking for the calculated column as i have some calculations needs to be done based on that, afterthat.

 

thanks.

 

 

Anonymous
Not applicable

@Greg_Deckler @petrovnikitamai

What if my data model is looks like this and whenever i get the "NT" value then my rank count should get start from 1 again.

 

EmpIDDateDaytype

A21-10-2018WO
A22-10-2018AB
A23-10-2018AB
A24-10-2018AB
A25-10-2018NT
A26-10-2018AB
A27-10-2018WO
A28-10-2018WO
A29-10-2018AB
A30-10-2018AB
B21-10-2018WO
B22-10-2018AB
B23-10-2018NT
B24-10-2018AB
B25-10-2018AB
B26-10-2018NT
B27-10-2018WO
B28-10-2018WO
B29-10-2018AB
B31-10-2018AB

 

Here For B, On 26/10/2018 it is NT, so when ever i get NT in middle of my DayTpe column then it should count from 1 again.

 

Any Suggestions

Hmm, I solved a count issue that needed to restart periodically, see if my Cthulhu measure in the Quick Measure Gallery provides a way to do this:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.