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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
mihaita_baro
Helper II
Helper II

code from SQL transport into a measure

Hi guys,

 

RIght now i am using 3 CSV  files ( appointment, Person and Referral ) to calculate what i have called as KPI4, KPI5 and KPI6. 

 

I import them into an Access Database that run some SQL queries.  I want to automate this proces a bit and create a measure for these KPI's and just upload/update the 3 csv files and the POWER BI report just get updated.

 

For example for KPI4 I have the following SQL's queries

 

First and the main one but which reffers to z_KPI8_part1 : 

SELECT Person.LPTID, Person.ccgName, Person.Caseload, t1.FTDate, t1.SERVICEID, Person.LTCondition, Referral.Caseload, *
FROM Person INNER JOIN ((SELECT SERVICEID,FTDate

FROM z_KPI8_part1) AS t1 INNER JOIN Referral ON t1.SERVICEID = Referral.SERVICEID) ON Person.LPTID = Referral.LPTID;

 

z_KPI8_part1 which referrs to z_FirstTreatmentDate : 

SELECT z_FirstTreatmentDate.SERVICEID, Min(z_FirstTreatmentDate.FTDate) AS FTDate, Max(Appointment.ATTENDANCE) AS ATTENDANCE
FROM Appointment INNER JOIN z_FirstTreatmentDate ON (Appointment.SERVICEID = z_FirstTreatmentDate.SERVICEID) AND (Appointment.Appointment = z_FirstTreatmentDate.FTDate)
WHERE (((z_FirstTreatmentDate.FTDate) Between [forms]![frmMain]![txtFTDateFrom] And [forms]![frmMain]![txtFTDateTo]))
GROUP BY z_FirstTreatmentDate.SERVICEID;

 

 z_FirstTreatmentDate : 

 

SELECT Appointment.SERVICEID, Min(Appointment.APPOINTMENT) AS FTDate, Min(Appointment.APPTYPE) AS APPTYPE
FROM (SELECT *
FROM Appointment
WHERE (Appointment.APPTYPE=02 OR Appointment.APPTYPE=03 OR Appointment.APPTYPE=05)
AND (Appointment.ATTENDANCE='5' OR Appointment.ATTENDANCE='6')
) AS [%$##@_Alias]
GROUP BY Appointment.SERVICEID;

 

In theory KPI4 is First Appointment Date when client's  Session Type ( APPTYPE )is one of the following: 2,3,5 
And
- Attendance Status is one of the following: 5 and 6.

 

From my method i am not getting anywhere near the numbers i get from Access database.

 

Please help me or guide me

2 REPLIES 2
Anonymous
Not applicable

Hi @mihaita_baro ,


I'm not good at SQL. Can you share some sample data and the expected result to us? So that we may be able to use DAX formula to get the result you want.

 

Best Regards,

Jay

Hi

So In theory KPI4 is  the number of clients where at First Appointment Date the Session Type ( APPTYPE )is one of the following: 2,3,5 AndAttendance Status is one of the following: 5 and 6.,

 

how do i calculate that ? 

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors