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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JoSwinnen1
Frequent Visitor

Retrieve the maximum date in a column where a value is appearing for the first time in another colum

Hi all,

 

I have a table with for each year a student start at the university a row appears. I want to find out how long it takes before the student is graduating. But there are some difficulities. A lot of them are already tackled, but there are still some exceptions which are not covered yet. For instance a student can have a second diploma in the same education, but I want to calculate the duration based on the first diploma. 

 

This is part of my table: 

Studentnumber   Education      StartDate       Enddate              Diploma

00001                       X            15/09/2016        15/06/2017

00001                       X            15/09/2017        15/06/2018

00001                       X            15/09/2018        15/06/2019           Yes

00001                       X            15/09/2019        15/06/2020           Yes

 

Duration =
if(
vw_PowerBI[Diploma]="Yes",
Value(
calculate(
datediff(min(vw_powerBI[startdate]),max(vw_powerBI[enddate]),DAY)/365,
filter(vw_powerBI,vw_powerBI[studentnumber]=earlier(vw_powerBI[studentnumber])
),
filter(vw_powerBI,vw_powerBI[education]=earlier(vw_powerBI[education])
)
)
),
0)
 
But I will get 4 instead of 3 as a result, how can I make sure that the maximum of enddate is calculated based on the first yes? 
 
I hope it is clear...
 
Kind regards,
 
Jo 
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @JoSwinnen1 ,

Here are the steps you can follow:

1. Create measure.

Measure =
var _start=
MINX(FILTER(ALL('Table'),
'Table'[Studentumnber]=MAX('Table'[Studentumnber])),[StartDate])
var _end=
MINX(FILTER(ALL('Table'),
'Table'[Studentumnber]=MAX('Table'[Studentumnber])&&'Table'[Diploma]="Yes"),[EndDate])
return
DATEDIFF(_start,_end,DAY)

2. Result:

vyangliumsft_0-1662354985444.png

 

If you need pbix, please click here.

Retrieve the maximum date in a column where a value is appearing for the first time in another colum...

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @JoSwinnen1 ,

Here are the steps you can follow:

1. Create measure.

Measure =
var _start=
MINX(FILTER(ALL('Table'),
'Table'[Studentumnber]=MAX('Table'[Studentumnber])),[StartDate])
var _end=
MINX(FILTER(ALL('Table'),
'Table'[Studentumnber]=MAX('Table'[Studentumnber])&&'Table'[Diploma]="Yes"),[EndDate])
return
DATEDIFF(_start,_end,DAY)

2. Result:

vyangliumsft_0-1662354985444.png

 

If you need pbix, please click here.

Retrieve the maximum date in a column where a value is appearing for the first time in another colum...

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@JoSwinnen1 , Create measure like

 

Sumx(Summarize(Filter( vw_PowerBI, vw_PowerBI[Diploma]="Yes"), vw_powerBI,vw_powerBI[studentnumber], vw_powerBI[education] , "_1", datediff(min(vw_powerBI[startdate]),max(vw_powerBI[enddate]),DAY)/365 ), [_1])

Thank you for your reply. I don't understand the formula. Can you explain? Because it seems that it is not giving the appropriate result. 

Maybe another difficulty: I want to create classes also (<2 years, 2-4 years, ...), is it not better to create a calculated column then? 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors