Forum Discussion
GMkk
Helper I
2 years agoconvert 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_in...
- Anonymous2 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 XuIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
GMkk
Helper I
2 years ago| ID_FROM_SOURCE ( Table-A) |
| 164987 |
| 164988 |
| 164989 |
| 164990 |
| 164992 |
| 164993 |
| 164994 |
| 164995 |
| 164996 |
| 164997 |
| 164998 |
| 164999 |
| 165000 |
| 165002 |
| 165003 |
| 165001 |
Table A- Table-B ( one to Many)
Table-B
| dinv_fk_dypr | dinv_value | dinv_fk_dyei |
| 191 | 164962 | 260592 |
| 327 | 1 | 260573 |
| 327 | 1 | 260590 |
| 191 | 164963 | 260601 |
| 327 | 2 | 260587 |
| 327 | 1 | 260589 |
| 327 | 1 | 260592 |
| 327 | 2 | 260591 |
| 191 | 164964 | 260615 |
| 191 | 164965 | 260616 |
| 191 | 164966 | 260618 |
| 191 | 164967 | 260624 |
| 191 | 164968 | 260625 |
| 327 | 2 | 260089 |
| 327 | 2 | 260615 |
| 191 | 164969 | 260637 |
| 327 | 2 | 260625 |
| 191 | 164970 | 260640 |
| 191 | 164971 | 260650 |
| 191 | 164972 | 260651 |
| 327 | 1 | 260640 |
| 191 | 164973 | 260654 |
| 191 | 164974 | 260658 |
| 191 | 164975 | 260659 |
| 327 | 1 | 260651 |
| 191 | 164976 | 260662 |
| 327 | 2 | 260616 |
| 327 | 2 | 260658 |
| 327 | 2 | 260654 |
| 327 | 2 | 260662 |
| 327 | 2 | 260561 |
| 327 | 2 | 260650 |
| 191 | 164977 | 260696 |
| 191 | 164978 | 260697 |
| 327 | 2 | 260563 |
| 191 | 164979 | 260701 |
| 191 | 164980 | 260702 |
| 191 | 164981 | 260703 |
| 191 | 164982 | 260704 |
| 191 | 164983 | 260705 |
| 191 | 164984 | 260713 |
| 191 | 164985 | 260714 |
| 327 | 2 | 260702 |
| 327 | 1 | 260705 |
| 191 | 164986 | 260721 |
| 191 | 164987 | 260722 |
| 191 | 164988 | 260723 |
| 191 | 164989 | 260724 |
| 191 | 164990 | 260725 |
| 191 | 164991 | 260726 |
| 191 | 164992 | 260727 |
| 327 | 1 | 260722 |
| 327 | 1 | 260725 |
| 327 | 1 | 260723 |
| 327 | 1 | 260727 |
| 327 | 2 | 260697 |
| 191 | 164993 | 260751 |
| 191 | 164994 | 260752 |
| 327 | 2 | 260752 |
| 191 | 164995 | 260757 |
| 327 | 2 | 260703 |
| 327 | 2 | 260751 |
| 191 | 164996 | 260770 |
| 327 | 1 | 260757 |
| 327 | 1 | 260696 |
| 327 | 2 | 260770 |
| 327 | 2 | 260601 |
| 327 | 1 | 260618 |
| 327 | 2 | 260637 |
| 327 | 2 | 260659 |
| 327 | 2 | 260713 |
| 191 | 164997 | 260799 |
| 327 | 2 | 260726 |
| 327 | 1 | 260701 |
| 327 | 2 | 260724 |
| 327 | 2 | 260799 |
| 191 | 164998 | 260808 |
| 191 | 164999 | 260809 |
| 191 | 165000 | 260812 |
| 191 | 165001 | 260813 |
| 327 | 1 | 260588 |
| 327 | 2 | 260704 |
| 327 | 1 | 260714 |
| 327 | 1 | 260813 |
| 191 | 165002 | 260826 |
| 327 | 1 | 260826 |
| 191 | 165003 | 260831 |