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
akshaydz
Frequent Visitor

start_date end_date from a table

Hi,

 

I have scenerai where I need to pull the patients first_join date and patients_last join date, My data looks somethings like this

 

PatientTreatmentstart_dateEnd_dateStatus
P1T119/05/201622/12/20160
P1T202/02/201704/08/20170
P1T310/10/201701/01/20180
P2T422/02/201722/06/20170
P2T513/05/201722/12/20170
P2T622/08/2017Null1
P3T724/12/201723/06/20180
P4T826/12/2017Null1

For each Patient:

    --Start_date = First(start_date) of corresponding patients start_date
    --End_date = If Status is 1 then Today else Last(end_date) of corresponding patients end_date

 

The output would look like this

 

Patient_idStart_dateEnd_date
P119/05/201601/01/2018
P222/02/2017Today()
P324/12/201723/06/2018
P426/12/2017Today()

Can anybody help me with this please?

1 ACCEPTED SOLUTION
Thejeswar
Resident Rockstar
Resident Rockstar

Hi @akshaydz,

For this purpose, I converted your date column into mm/dd/yyyy format from your format of dd/mm/yyyy. Hopw that would not aaffect you in any way

 

Then create 2 columns using the following 2 DAX Statements

 

First Date = CALCULATE(MIN(Table1[start_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient]))) 
Last Date = IF(ISBLANK(CALCULATE(MAX(Table1[End_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient])))), TODAY(), CALCULATE(MAX(Table1[End_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient])))) 

The Final Table Looks as the one belowdate.PNG

 

 

 

 

View solution in original post

1 REPLY 1
Thejeswar
Resident Rockstar
Resident Rockstar

Hi @akshaydz,

For this purpose, I converted your date column into mm/dd/yyyy format from your format of dd/mm/yyyy. Hopw that would not aaffect you in any way

 

Then create 2 columns using the following 2 DAX Statements

 

First Date = CALCULATE(MIN(Table1[start_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient]))) 
Last Date = IF(ISBLANK(CALCULATE(MAX(Table1[End_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient])))), TODAY(), CALCULATE(MAX(Table1[End_date]), FILTER(Table1, Table1[Patient] = EARLIER(Table1[Patient])))) 

The Final Table Looks as the one belowdate.PNG

 

 

 

 

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.