Forum Discussion
Alternative to CountRows
- 1 year ago
Hi brdrok ,
You're right that COUNTROWS is overkill if you're just trying to check for existence—like a WHERE EXISTS in SQL. The cleaner and more efficient alternative in DAX is to use the ISINSCOPE or ISEMPTY family of logic, depending on the use case. Since you're working with calculated logic and want to return 1 if any record exists after applying filters, the most direct and performant alternative is using NOT ISEMPTY(...).
Here’s how you can rewrite your DAX measure:
VAR myTable = CALCULATETABLE( FactGL, REMOVEFILTERS('StdParametersNRT_Standalone'), TREATAS(VALUES('StdParametersNRT_Standalone'[InvestmentVehicleKey]), FactGL[CompanyKey]), TREATAS(VALUES('StdParametersNRT_Standalone'[InvestorKey]), FactGL[InvestorKey]) ) VAR result = IF(NOT ISEMPTY(myTable), 1, 0) RETURN resultThis avoids row counting and directly checks whether any row exists after applying the same filters.
Let me know if you'd like to convert it into a measure or keep it in a calculated column—or tailor it further!
Best regards,
Thank you DataNinja777,
you truly do your name justice 😃
Once again thank you!!!