Forum Discussion

GMkk's avatar
GMkk
Helper I
2 years ago
Solved

convert sql joins to dax

hi everyone, this is my sql 
SELECT
COUNT(inc_incident_DW.inc_incident_ref) AS Inc_No
--,luynt_description
--,FeedbackYN.dinv_value
FROM inc_incident_DW
LEFT OUTER JOIN sta_station_DW ON inc_incident_DW.SK_sta_pk = sta_station_DW.SK_sta_pk
LEFT OUTER JOIN dinv_dynamic_int_value_DW AS customIncident ON customIncident.dinv_fk_dypr = 191 and customIncident.dinv_value = inc_incident_DW.ID_FROM_SOURCE
LEFT OUTER JOIN dinv_dynamic_int_value_DW AS FeedbackYN on FeedbackYN.dinv_fk_dypr = 327 and FeedbackYN.dinv_fk_dyei = customIncident.dinv_fk_dyei
LEFT OUTER JOIN luynt_yes_no_type_DW AS luynt ON luynt.ID_FROM_SOURCE = FeedbackYN.dinv_value

trying to replicate it into dax but this sql query has got self joins and i coudn't understand/get how to replicate in dax.

this is how it looks in sql design query editor, please feel free to ask any other info required.

this is in my analysis service , let me know if i need to edit relationships to achive what i need.

I appreciate  everyone, for taking time and reading 



  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi GMkk 

     

    lbendlin , thanks for your concern about this case.

     

    The following formula is for your reference:

     

    Measure = 
    VAR _tab1 = CALCULATETABLE(VALUES('Table-B'[dinv_fk_dyei]), FILTER(ALLSELECTED('Table-B'), 'Table-B'[dinv_fk_dypr] = 191 && 'Table-B'[dinv_value] in VALUES('Table-A'[ID_FROM_SOURCE])))
    var _tab2 = CALCULATETABLE(VALUES('Table-B'[dinv_fk_dyei]), FILTER(ALLSELECTED('Table-B'), 'Table-B'[dinv_fk_dypr] = 327 && 'Table-B'[dinv_value] = 1 && 'Table-B'[dinv_fk_dyei] in _tab1))
    return COUNTROWS(_tab2)

     

     

    But I have a small doubt to confirm with you, I tested it in the database with the SQL statement you provided and the count is 7. If I have misunderstood you, could you please explain further? Thank you in advance for your time.

     

    Result:

     

    Best Regards,
    Yulia Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

16 Replies