Forum Discussion
Power BI result is different from SQL result
- 4 years ago
Hi Anonymous ,
I think some mistake on your SQL statement. The priority of AND and OR is different.
Please try this sql to check if the same:
SELECT * FROM myFacilitySite site INNER JOIN myQuarantineCase mq ON site.fkeyCaseID = mq.ID INNER JOIN myCareFacility mcf ON mq.FacilityID = mcf.ID INNER JOIN lkuClearance lclr ON site.ClearanceStatusId = lclr.ID WHERE mq.EntryDate BETWEEN '1/1/2022' AND '7/23/2022' AND ( lclr.ID = 2 OR lclr.ID = 3 ) AND mcf.IsActive = 1 GROUP BY mcf.[Name] ORDER BY COUNT(site.ID) DESC, acf.[Name]Or you can change the mode of your table to DirectQuery and use the performance analyzer, copy the query and you will get // Direct Query which is sql statement.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
I think some mistake on your SQL statement. The priority of AND and OR is different.
Please try this sql to check if the same:
SELECT
*
FROM
myFacilitySite site
INNER JOIN myQuarantineCase mq ON site.fkeyCaseID = mq.ID
INNER JOIN myCareFacility mcf ON mq.FacilityID = mcf.ID
INNER JOIN lkuClearance lclr ON site.ClearanceStatusId = lclr.ID
WHERE
mq.EntryDate BETWEEN '1/1/2022'
AND '7/23/2022'
AND (
lclr.ID = 2
OR lclr.ID = 3
)
AND mcf.IsActive = 1
GROUP BY
mcf.[Name]
ORDER BY
COUNT(site.ID) DESC,
acf.[Name]
Or you can change the mode of your table to DirectQuery and use the performance analyzer, copy the query and you will get // Direct Query which is sql statement.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.