The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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 ) )
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
21 | |
12 | |
10 | |
7 |