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
Anonymous
Not applicable

Earliest Appt in the Future for each Patient

Good afternoon, I have 2 tables. Does anyone have suggestions for the following DAX query?

1. Patient - One row per unique pt identifier called PAT_ID

2. Encounters - One row for each patient's visit, foreign key is the pt unique identifier

In the patient column, I would like to add a field on the patient table that gives each patient's (see image)

        a. first appt in the future

        b. with an appt status name = 'Scheduled'

first appt in future.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

-- this DAX goes into a calculated column
-- in the Patient table

var __patientId = Patient[PAT_ID]
var __now = TODAY()
var __firstScheduledApptDate =
	CALCULATE(
		MIN( Encounters[APPT_DATE_TM] ),
		Encounters[APPT_STATUS] = "Scheduled",
		Encounters[PAT_ID] = __patientId,
		Encounters[APPT_DATE_TM] > __now
	)
return
	__firstScheduledApptDate

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

-- this DAX goes into a calculated column
-- in the Patient table

var __patientId = Patient[PAT_ID]
var __now = TODAY()
var __firstScheduledApptDate =
	CALCULATE(
		MIN( Encounters[APPT_DATE_TM] ),
		Encounters[APPT_STATUS] = "Scheduled",
		Encounters[PAT_ID] = __patientId,
		Encounters[APPT_DATE_TM] > __now
	)
return
	__firstScheduledApptDate
Anonymous
Not applicable

I appreciate your response. Do you have any suggestions for the error message below?dax errors 1.png

Anonymous
Not applicable

1. Are you creating this as a CALCULATED COLUMN? This is NOT A MEASURE.

2. Secondly, you have to give the column a name. As you can see in the error message, you're trying to name the column "var __patientId." Please name your column:

 

[Column Name] = <your formula here>

 

Best

Darek

Anonymous
Not applicable

You are absolutely correct

 

FirstSchApptDate = var __patientId = 'Patients'[PAT_ID]
var __now = TODAY()
var __firstScheduledApptDate =
CALCULATE(
MIN( 'Encounters'[APPT_DATE_TM] ),
'Encounters'[APPT_STATUS] = "Scheduled",
'Encounters'[PAT_ID] = __patientId,
'Encounters'[APPT_DATE_TM] > __now
)
return
__firstScheduledApptDate

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