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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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 ) )
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 20 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 33 | |
| 31 | |
| 19 | |
| 12 | |
| 11 |