Forum Discussion
Convert SQL To DAX
- Anonymous2 years ago
Hi, bpdax
Based on your description, you want to implement DAX statements that have similar functionality to SQL statements, and the following are possible DAX statements. If it does not work, you can share the data without sensitive information, the expected effect and the logic to achieve the effect. Feel free for anything about this.
VAR BaseTable = CALCULATETABLE( 'database'[table], 'database'[Compliant] = 0, 'database'[Team] IN @Team, 'database'[Course] IN @Course ) VAR SummaryTable = SUMMARIZE( BaseTable, 'database'[StaffID], "TrainingTracked", SUM('database'[TrainingTracked]), "DemNumDiff", SUM('database'[Denominator]) - SUM('database'[Numerator]), "TrackDemNumDiff", SUM('database'[TrackedDenominator]) - SUM('database'[TrackedNumerator]), "NotComplaint", IF( [TrainingTracked] = 16 && [TrackDemNumDiff] > 0, 1, IF([TrainingTracked] <> 16 && [DemNumDiff] > 0, 1, 0) ) ) VAR FinalTable = FILTER( SummaryTable, [NotComplaint] = 1 ) EVALUATE SELECTCOLUMNS( FinalTable, "StaffID", 'database'[StaffID], "Team", 'database'[Team], "FirstName", 'database'[FirstName], "LastName", 'database'[LastName], "CourseName", 'database'[CourseName], "DueOnDate", 'database'[DueOnDate] )Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi, bpdax
Based on your description, you want to implement DAX statements that have similar functionality to SQL statements, and the following are possible DAX statements. If it does not work, you can share the data without sensitive information, the expected effect and the logic to achieve the effect. Feel free for anything about this.
VAR BaseTable =
CALCULATETABLE(
'database'[table],
'database'[Compliant] = 0,
'database'[Team] IN @Team,
'database'[Course] IN @Course
)
VAR SummaryTable =
SUMMARIZE(
BaseTable,
'database'[StaffID],
"TrainingTracked", SUM('database'[TrainingTracked]),
"DemNumDiff", SUM('database'[Denominator]) - SUM('database'[Numerator]),
"TrackDemNumDiff", SUM('database'[TrackedDenominator]) - SUM('database'[TrackedNumerator]),
"NotComplaint", IF(
[TrainingTracked] = 16 && [TrackDemNumDiff] > 0, 1,
IF([TrainingTracked] <> 16 && [DemNumDiff] > 0, 1, 0)
)
)
VAR FinalTable =
FILTER(
SummaryTable,
[NotComplaint] = 1
)
EVALUATE
SELECTCOLUMNS(
FinalTable,
"StaffID", 'database'[StaffID],
"Team", 'database'[Team],
"FirstName", 'database'[FirstName],
"LastName", 'database'[LastName],
"CourseName", 'database'[CourseName],
"DueOnDate", 'database'[DueOnDate]
)
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
- bpdax2 years agoNew Member
Thank you for your help. I managed to write a similar piece of code, I just changed the last part of the code to a NaturalLeftOuterJoin to get the rest of the things I needed.