Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
i am trying to connect power bi with moodle through sql query:
it is showing fatal error ODBC. please let me know if there is any other way to fetch all data or we can optimize this query or divide it into parts to get data
select ta.student_name,ta.idnumber,ta.email,cte.anonymouscode,ta.fullname,ta.shortname,ta.section,
t1.internaltotal,t1.internalmax,t1.internal_remarks,
t2.externaltotal,t2.externalmax,t2.external_remarks,
t3.coursetotal,t3.courssetotalmax,t3.coursetotal_remarks,(round(t3.coursetotal) + IFNULL(mm.marks,0)) as moderatedtotal,
mm.marks as moderatedmarks,
clg.grade,clg.specialgrades
from
( SELECT u.id as userid,c.id as courseid,c.fullname,c.shortname,concat(u.firstname," ",u.lastname) as student_name,u.email,u.idnumber,g.name as section
FROM mdl_user u
JOIN mdl_user_enrolments ue ON ue.userid = u.id
JOIN mdl_enrol e ON e.id = ue.enrolid
JOIN mdl_role_assignments ra ON ra.userid = u.id
JOIN mdl_context ct ON ct.id = ra.contextid
AND ct.contextlevel = 50
JOIN mdl_course c ON c.id = ct.instanceid
AND e.courseid = c.id
JOIN mdl_role r ON r.id = ra.roleid
JOIN mdl_groups g ON g.courseid = c.id
JOIN mdl_groups_members gm on g.id = gm.groupid and gm.userid = u.id
WHERE e.status =0
AND u.suspended =0
AND u.deleted =0
AND ue.status =0
AND r.shortname ="student"
) as ta
Left JOIN
(
select c.id as courseid,u.id as userid,
gg.finalgrade as internaltotal,gi.grademax as internalmax,gg.feedback as internal_remarks
from mdl_grade_categories gc
JOIN mdl_grade_items gi ON gc.id = gi.categoryid and gc.gradeitemtype =1
JOIN mdl_course c ON gi.courseid = c.id
JOIN mdl_grade_grades gg ON gi.id = gg.itemid
JOIN mdl_user as u ON gg.userid = u.id
) as t1 ON ta.userid = t1.userid and ta.courseid = t1.courseid
LEFT JOIN
(
select c.id as courseid,u.id as userid ,gc.fullname as external,gc.gradeitemtype ,gg.finalgrade as externaltotal,gi.grademax as externalmax,gg.feedback as external_remarks
from mdl_grade_categories gc
JOIN mdl_grade_items gi ON gc.id = gi.categoryid
JOIN mdl_course c ON gi.courseid = c.id
JOIN mdl_grade_grades gg ON gi.id = gg.itemid
JOIN mdl_user as u ON gg.userid = u.id
Where gc.gradeitemtype =2
) as t2
ON ta.courseid = t2.courseid and ta.userid = t2.userid
LEFT JOIN
(
select c.id as courseid,u.id as userid ,gg.finalgrade as coursetotal,gi.grademax as courssetotalmax,gg.feedback as coursetotal_remarks
from mdl_grade_categories gc
JOIN mdl_grade_items gi ON gc.id = gi.iteminstance and (gc.gradeitemtype is null)
JOIN mdl_course c ON gi.courseid = c.id
Left JOIN mdl_grade_grades gg ON gi.id = gg.itemid
JOIN mdl_user as u ON gg.userid = u.id
) as t3 on ta.courseid = t3.courseid and ta.userid = t3.userid
LEFT JOIN mdl_moderated_marks as mm on ta.courseid = mm.courseid and ta.userid = mm.userid
LEFT JOIN mdl_course_letter_grades as clg on ta.courseid = clg.courseid and ta.userid = clg.userid
LEFT JOIN mdl_course_term_enrol cte on cte.userid = ta.userid AND cte.courseid = ta.courseid
where t3.coursetotal is not null;
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
70 | |
68 | |
43 | |
34 | |
26 |
User | Count |
---|---|
86 | |
49 | |
45 | |
38 | |
37 |