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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

How to write this SQL query in DAX?

Hi,

Please can someone provide the DAX equivalent for the below SQL query?  Thanks in advance.

SELECT sv.packet_id
            , sv.syllabus
            , sv.session_id
            , COUNT(candidate_number) AS CountOfCandidates
            , SUM(
                      CASE sv.status
                               WHEN 'validated' THEN 1
                               WHEN 'validated_rejected' THEN 1
                               ELSE 0
                      END
                      ) AS Completed
            , SUM(
                      CASE sv.status
                               WHEN 'validated' THEN 0
                               WHEN 'validated_rejected' THEN 0
                               ELSE 1
                      END
                      ) AS ToBeCompleted
FROM SCRIPT_VALIDATION AS sv
GROUP BY sv.packet_id, sv.syllabus, sv.session_id

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Thanks. That put me in the right direction.
In case anyone is interested to know how what the DAX equivalent for the SQL was, see below. I had slightly altered my requirement so the SQL and DAX won't be 100% matching but close enough for you to follow.

 

tblPacketsWithCandidatesBySession = SUMMARIZE(
                                                                                         refSCRIPT_VALIDATION,
                                                                                         refSCRIPT_VALIDATION[session_id],
                                                                                         refSCRIPT_VALIDATION[syllabus],
                                                                                         refSCRIPT_VALIDATION[component],
                                                                                         refSCRIPT_VALIDATION[packet_id],
                                                                                         "CountOfCandidates", COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                         "CompletedCandidates", CALCULATE(
                                                                                                                                    COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                                                                    FILTER( refSCRIPT_VALIDATION,
                                                                                                                                    refSCRIPT_VALIDATION[status] = "validated"
                                                                                                                                   || refSCRIPT_VALIDATION[status] =                                                                                                                                                                                                                           "validated_rejected")
                                                                                                                                                        ),
                                                                                          "ToBeCompletedCandidates", CALCULATE(
                                                                                                                                             COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                                                                             FILTER( refSCRIPT_VALIDATION,
                                                                                                                                             refSCRIPT_VALIDATION[status] <> "validated"
                                                                                                                      && refSCRIPT_VALIDATION[status] <> "validated_rejected")
                                                                                                                                                        )
                                                                                         )

View solution in original post

Hardik
Continued Contributor
Continued Contributor

hey !! please accept the solution provided,if it helped you !

Thanks  

View solution in original post

3 REPLIES 3
Hardik
Continued Contributor
Continued Contributor

Anonymous
Not applicable

Thanks. That put me in the right direction.
In case anyone is interested to know how what the DAX equivalent for the SQL was, see below. I had slightly altered my requirement so the SQL and DAX won't be 100% matching but close enough for you to follow.

 

tblPacketsWithCandidatesBySession = SUMMARIZE(
                                                                                         refSCRIPT_VALIDATION,
                                                                                         refSCRIPT_VALIDATION[session_id],
                                                                                         refSCRIPT_VALIDATION[syllabus],
                                                                                         refSCRIPT_VALIDATION[component],
                                                                                         refSCRIPT_VALIDATION[packet_id],
                                                                                         "CountOfCandidates", COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                         "CompletedCandidates", CALCULATE(
                                                                                                                                    COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                                                                    FILTER( refSCRIPT_VALIDATION,
                                                                                                                                    refSCRIPT_VALIDATION[status] = "validated"
                                                                                                                                   || refSCRIPT_VALIDATION[status] =                                                                                                                                                                                                                           "validated_rejected")
                                                                                                                                                        ),
                                                                                          "ToBeCompletedCandidates", CALCULATE(
                                                                                                                                             COUNT( refSCRIPT_VALIDATION[id] ),
                                                                                                                                             FILTER( refSCRIPT_VALIDATION,
                                                                                                                                             refSCRIPT_VALIDATION[status] <> "validated"
                                                                                                                      && refSCRIPT_VALIDATION[status] <> "validated_rejected")
                                                                                                                                                        )
                                                                                         )

Hardik
Continued Contributor
Continued Contributor

hey !! please accept the solution provided,if it helped you !

Thanks  

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.