Forum Discussion

askme1217's avatar
askme1217
Frequent Visitor
1 year ago
Solved

Directquery measure help

I have few measures like this below for my import mode datamodel. When i switch to directquery, these measures wont work. How do i write this in directqiery. Total= CALCULATE(     DISTINCTCO...
  • v-saisrao-msft's avatar
    1 year ago

    Hi askme1217, 

    Thank you for reaching out to the Microsoft Fabric Forum Community. 

    Thank you lbendlin, for your insights. 

    The issue you're facing is due to how DirectQuery handles DAX expressions differently from Import mode. In your original measure, the use of FILTER ('SECT', [CFLAG] = "Y") can prevent query folding, which is essential in DirectQuery for performance and compatibility. Try replacing the FILTER function with a direct Boolean filter, like this: CALCULATE(DISTINCTCOUNT('STU_ENR'[ST_ID]), 'SECT'[CFLAG] = "Y"). 

    This approach allows Power BI to generate efficient SQL queries that are more likely to fold. Also, ensure that a proper relationship exists between the STU_ENR and SECT tables and enable "Assume Referential Integrity" if possible, as this helps Power BI push filters using inner joins. Lastly, while the blog post shared relates to memory usage in Import mode, it’s still relevant—DISTINCTCOUNT is resource-intensive, and in DirectQuery, ensuring proper indexing and query optimization on the data source side is just as important.

     

    If this post helps, then please give us ‘Kudos’ and consider accepting it as a solution to help other members find it more quickly.

     

    Thank you.