Forum Discussion

Petja's avatar
Petja
Icon for Advocate II rankAdvocate II
28 days ago
Solved

How to use DirectQuery table with complex visuals

Hi,

 

I'm doing a report which has quite complex visuals; multiple field parameters and relationships. I also have a very large data set, which causes the report to run out of memory if I don't reduce the amount of data significantly. I tried to fix this by changing the data table to DirectQuery but now my visuals won't run because they are too complex for SQL query:

 

 

I can't even view the attempted sql query because of the error (great design MS). Any way of solving this issue?

 

  • Hi Petja​ ,

    Sorry for the delay in response.

    Yes. If Performance Analyzer doesn't expose the query because the visual fails, you can capture it from the Power BI Desktop trace.

    Go to File → Options and settings → Options → Diagnostics → Open crash dump/traces folder. Then locate the active AnalysisServicesWorkspaces folder and open FlightRecorderCurrent.trc.

    If the source is SQL Server, you can also use SQL Server Profiler to capture the query directly at the database side.

    Thanks!!

6 Replies

  • ShahRukhSameer's avatar
    ShahRukhSameer
    Icon for Continued Contributor rankContinued Contributor

    Hi Petja,

     

    That error usually means Power BI has generated a SQL query that is too complex for the source to execute efficiently. I've run into this with DirectQuery models that use a combination of field parameters, complex measures, many relationships, and visuals that require multiple levels of aggregation.

     

    A few things I'd try:

    • Use Performance Analyzer to identify which visual is generating the problematic query.
    • Simplify field parameter logic where possible. Field parameters can sometimes produce much larger SQL queries than expected in DirectQuery mode.
    • Move complex calculations from DAX into the source database (SQL view or stored procedure) so Power BI has less work to push down.
    • Consider a Composite Model instead of making the entire table DirectQuery. Keep large fact tables in DirectQuery and import smaller dimensions/aggregations.
    • Create aggregation tables and let Power BI hit the imported aggregate table first, falling back to DirectQuery only when needed.
    • Review any measures that use iterators such as SUMX, FILTER, ADDCOLUMNS, or nested CALCULATE statements, as these can generate very complex SQL in DirectQuery.
    • Check whether bi-directional relationships can be reduced or replaced with a simpler model.

    One thing that stands out is that the report worked in Import mode but ran out of memory. In that situation, I'd usually look at aggregations, incremental refresh, model optimization, or a Composite Model before converting the entire dataset to DirectQuery. DirectQuery often solves the memory issue but introduces query complexity issues like the one you're seeing.

     

    Also, if you're using SQL Server, try capturing the generated SQL with SQL Profiler or Extended Events. Even when Power BI doesn't show the full query, the database side can often reveal which part of the query is causing the nesting limit or timeout.

    • Petja's avatar
      Petja
      Icon for Advocate II rankAdvocate II

      Thank you for a very detailed response. This is in line with what my understanding was of the subject but unfortunately my organisation does not provide the correct tools for optimizing the workflow. I should do all heavy lifting before power BI but unfortunately I am not able. 

       

      If you know how to capture the sql statement of a failed visual, would be much appreciated.

      • v-sathmakuri's avatar
        v-sathmakuri
        Icon for Community Support rankCommunity Support

        Hi Petja​ ,

        Sorry for the delay in response.

        Yes. If Performance Analyzer doesn't expose the query because the visual fails, you can capture it from the Power BI Desktop trace.

        Go to File → Options and settings → Options → Diagnostics → Open crash dump/traces folder. Then locate the active AnalysisServicesWorkspaces folder and open FlightRecorderCurrent.trc.

        If the source is SQL Server, you can also use SQL Server Profiler to capture the query directly at the database side.

        Thanks!!

  • Hi Petja 

    Can you share the information about your data model ,SQL Queries and Source.

    Based on athe information, you can simplify your model by aggregating data,creating materialized views etc.

    these all options depend on what your data model and source looks like.

    Please give kudos or mark it as solution once confirmed.

     

    Thanks and Regards,

    Praful