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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Fred1983
New Member

Find the most recent reinfection date

Good evening!

Some pateints can get the same disease multiple times and I am trying to find the most recent reinfection date. For each infection, I have the patient ID and episode date. How can I calcuate the last infection date, which is the most recent episode date before the current infection? 

 

Screenshot 2023-01-24 223954.png

I added an index by using patient ID (ascending) and episode date (oldest to newest) so cases are in the order I need.

 

I am think of finding the FIRSTNONBLANK of the episode date with a filter of patient ID=the current Patient ID and index < the current index, but I couldn't make it work

DtLastinfection = 
CALCULATE(FIRSTNONBLANK(table[DtEpisode]FILTER(table,table[PatientID]=current table[PatientID] && table[Index] < current table[Index])))
 
Please help, thank you in advance! 
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Fred1983 

try to add the calculated column like:

DtLastInfection=
MAXX(
    FILTER(
         TableName,          TableName[PatientID]=EARLIER(TableName[PatientID])&&TableName[DtEpisode]<EARLIER(TableName[DtEpisode])
    ),
    TableName[DtEpisode]
)

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @Fred1983 

try to add the calculated column like:

DtLastInfection=
MAXX(
    FILTER(
         TableName,          TableName[PatientID]=EARLIER(TableName[PatientID])&&TableName[DtEpisode]<EARLIER(TableName[DtEpisode])
    ),
    TableName[DtEpisode]
)

@FreemanZ Thank you so much!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.