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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Create a Measure based on logic of SQL Query

Hi,

I have a SQL Query as below :

select s.TERM_START_DATE
, s.TERM_END_DATE
, S.MONTH_END_DATE
, S.COLLEGE_CODE
, s.LEVEL_CODE
, Round (SUM(S.TERM_OTP)/COUNT(S.TERM_OTP),4) *100 OTP_PCT
from wgubi.vw_rst_student s
where s.month_begin_Date >= '01-dec-2018'
and s.term_start_date >= '01-dec-2018'
AND S.TERM_END_DATE < SYSDATE
AND S.TERM_OTP IS NOT NULL
AND S.STUDENT_PIDM NOT IN (select student_pidm from WGUBI.INF_STUDENT_GRADS where DEGREE_status_CODE = 'AW')
AND TRUNC(S.TERM_END_DATE) = S.MONTH_END_dATE
GROUP BY s.TERM_START_DATE
, s.TERM_END_DATE
, S.MONTH_END_DATE
, S.COLLEGE_CODE
,s.LEVEL_CODE
ORDER by 1;
 
Using "Import Mode", I connected all the requried tables to PowerBI and joined them.
Now, Using DAX, I created a Measure for "OTP_PCT" as :
OTP_PCT  = CALCULATE(
Round(SUM(VW_RST_STUDENT[TERM_OTP])/count(VW_RST_STUDENT[TERM_OTP]),4),
filter (INF_STUDENT_GRADS,INF_STUDENT_GRADS[DEGREE_STATUS_CODE]<> "AW"),
filter(VW_RST_STUDENT, VW_RST_STUDENT[TERM_OTP] in {0,1}))
 
 
It's giving wrong results.
Kindly help me.
 
Also please suggest how to use Blank Query for the same.
2 REPLIES 2
ananeto
New Member

What exactly are you trying to calculate? An average?

And why do you say the results are wrong?

v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you please share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.