Forum Discussion

brdrok's avatar
brdrok
Helper I
1 year ago
Solved

Alternative to CountRows

Hello Power BI Experts,   I have the following DAX query: var myCount = CALCULATE( COUNTROWS(FactGL), REMOVEFILTERS('StdParametersNRT_Standalone'), TREATAS(VALUES( 'StdParameters...
  • DataNinja777's avatar
    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 result
    

    This 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,