Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
Good afternoon, I need to convert a short SQL query to PowerBI DAX.
As a reference, here is the SQL query:
WITH ae_per_infant AS (
SELECT
Infants,
COUNT(*) AS Count
FROM
ae
GROUP BY
Infants
)
SELECT
dm.UCRFID AS UCRFID,
ae_per_infant.Count AS Count,
COALESCE(ae_per_infant.Count / dm.duration, 0) AS IR
FROM
dm
LEFT JOIN
ae_per_infant ON dm.UCRFID = ae_per_infant.Infants
Any help would be greatly appreciated.
Solved! Go to Solution.
Hi @---Andrea---
Thank you for being part of the Microsoft Fabric Community.
Please find below DAX code as per your requirement.
***********************************************
left join =
VAR A=
SELECTEDCOLUMNS(ae,"Infants",ae[Infants])
VAR B=
SELECTEDCOLUMNS(dm,"UCRFID",dm[UCRFID])
return
NATURALLEFTOUTERJOIN(B,A)
VAR IR =
IF(
ISBLANK(DIVIDE ( COUNTROWS ( RELATEDTABLE ( AE ) ), DM[Duration])),0
)
return IR
Infants count= COUNTROWS( AE )
***********************************************
Hope this helps!
If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth.
Hi @---Andrea---
Thank you for being part of the Microsoft Fabric Community.
Please find below DAX code as per your requirement.
***********************************************
left join =
VAR A=
SELECTEDCOLUMNS(ae,"Infants",ae[Infants])
VAR B=
SELECTEDCOLUMNS(dm,"UCRFID",dm[UCRFID])
return
NATURALLEFTOUTERJOIN(B,A)
VAR IR =
IF(
ISBLANK(DIVIDE ( COUNTROWS ( RELATEDTABLE ( AE ) ), DM[Duration])),0
)
return IR
Infants count= COUNTROWS( AE )
***********************************************
Hope this helps!
If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth.
Change the relationship so that it is single direction - bi-directional relationships are almost never a good idea.
You can create a couple of measures like
Infant count = COUNTROWS( AE )
IR =
SUMX ( DM, DIVIDE ( COUNTROWS ( RELATEDTABLE ( AE ) ), DM[Duration], 0 ) )
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 23 | |
| 12 | |
| 11 | |
| 9 | |
| 8 |