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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
yve214
Helper III
Helper III

Urgent Help with Creating a Flag column

Problem:

Please, I am trying to check if my recent admission location is the same as my recent discharge location and create a flag to help me with my other measures. How to approach this.

 

check...

1. The patient's most recent admission location

2. The patient's most recent discharge location

3. Create a flag to see if they have the same location then 1, else 0

 

Table:

patient_namepatient_Idadmission_datedischarge_daterecord_IdLocation
Mark11/1/20183/15/20191001A
John26/1/20196/3/20201002B
Tom31/1/20208/7/20201003A
Tom38/7/20209/7/20201004C
Tom39/7/202010/3/20201005A
Sarah47/2/20152/1/20181006C
Kim53/1/20167/6/20171007E
Mark13/16/20194/7/20191008A
Tom32/1/2021 1009C
Steve63/2/2019 1010 
John23/4/20225/10/20221011A

 

Expected Results:

patient_namepatient_Idlocation_flag//Explanation
Mark11most recent discharge location and new admission location is the same so flag is 1
John21recent discharge location is same as recent admission
Tom30different locations for  their recent admission and discharge record
Sarah40has only one record
Kim50has only one record
Steve60has only one record, no discharge record

 

Thank you very much in advance.

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @yve214 

please try

Flag =
VAR CurrentIDTable =
    CALCULATETABLE ( Table1, ALLEXCEPT ( Table1, Table1[patient_Id] ) )
VAR LastAdmissionLocation =
    MAXX ( TOPN ( 1, CurrentIDTable, Table1[admission_date] ), Table1[Location] )
VAR LastDischargeLocation =
    MAXX ( TOPN ( 1, CurrentIDTable, Table1[discharge_date] ), Table1[Location] )
RETURN
    IF ( LastAdmissionLocation = LastDischargeLocation, 1 )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @yve214 

please try

Flag =
VAR CurrentIDTable =
    CALCULATETABLE ( Table1, ALLEXCEPT ( Table1, Table1[patient_Id] ) )
VAR LastAdmissionLocation =
    MAXX ( TOPN ( 1, CurrentIDTable, Table1[admission_date] ), Table1[Location] )
VAR LastDischargeLocation =
    MAXX ( TOPN ( 1, CurrentIDTable, Table1[discharge_date] ), Table1[Location] )
RETURN
    IF ( LastAdmissionLocation = LastDischargeLocation, 1 )

@tamerj1 ,

 

you are a life safer. YES worked PERFECTLY. Immense thanks for your quick and effective response.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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