Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Justas4478
Post Prodigy
Post Prodigy

DAX query optimisation

Hi, I have this DAX query:

Justas4478_0-1716370792303.png

Days Shorted = VAR _Table =
    SUMMARIZE(
         'Outbound Delivery',
         'Product Category'[Level 2],
         'Date'[Date],
         "@Shorted", 'Outbound Delivery'[Shorted Qty]
    )
VAR _Result =
    COUNTX(
        FILTER(
             _Table,
              [@Shorted] <> 0
        ),
        [@Shorted]
    )+0
RETURN
  _Result

The query takes long time to run, I was hoping there is any ways that it can be optimised to make it faster.
Thanks.
9 REPLIES 9
some_bih
Super User
Super User

Hi @Justas4478 try to remove "+0" and compare your performance, eventually update your "solution"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






@some_bih that reduced load time massively.
However it brings back probem that I had before.
Since I have this measure:

Days Shorted group = SWITCH('Outbound Delivery'[Days Shorted],0,"0 days Short",1,"1 days Short",2,"2 days Short",3,"3 days Short",4,"4 days Short","5 days Short or more")
If I remove  '+0' then values returned for 0 are blank and 'Days Shorted group' measure fails to capture them.
These are results that I get.
Justas4478_0-1716450991641.png

Is there any way to implement '+0' without creating massive time increase or to make 0 show up as 0 and not blank?

Hi @Justas4478 

without model and relationships, it is hard to spot issue. Still try to replace VAR _Table with below code

 

VAR _Table =
ADDCOLUMNS(
SUMMARIZE(
'Outbound Delivery',
'Product Category'[Level 2],
'Date'[Date])
,
"@Shorted", 'Outbound Delivery'[Shorted Qty])





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






@some_bih It definitelly made query much faster, but it still fails to load larger amount amount of data faster or because of this:

Justas4478_0-1716468272570.png 

 

Hi @Justas4478 without model and relationships, it is hard to spot issue.  





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






@some_bih The one thing I noticed if I remove 
This from the table rows:

Justas4478_1-1716469381783.png

It loads data almoust instantly.
This is realationship between 'Product' table and 'Outbound Delivery' table that holds query.
Because it is using live data model I can't do any changes to set realationships.

Justas4478_2-1716469656573.png

I dont know is this any helpfull.

Hi @Justas4478 not enought to provide some solution from my side 🙂

Play a bit with CALCULATETABLE so you filterout blank result (combination measure without +0 and filter <> blank rows for text column





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Hi  @Justas4478 ,

 

 

As far as I know, the summarize() function creates a table, and creating a table is an operation that generally consumes a large amount of time, so you might consider optimizing performance by removing extended columns from summarize() and adding them using the addcolumns() function.

Optimize SUMMARIZE with ADDCOLUMNS in Dax #ssas #tabular #dax #powerpivot - SQLBI

Best practices using SUMMARIZE and ADDCOLUMNS - SQLBI

 

There are also some suggestions for optimizing the model here:

  • Remove unused tables or columns, where possible. 
  • Avoid distinct counts on fields with high cardinality – that is, millions of distinct values.  
  • Take steps to avoid fields with unnecessary precision and high cardinality. For example, you could split highly unique datetime values into separate columns – for example, month, year, date, and so on. Or, where possible, use rounding on high-precision fields to lower cardinality – (for example, 13.29889 -> 13.3).
  • When connecting to data sources via Direct Query, consider indexing columns that are commonly filtered or sliced again. Indexing greatly improves report responsiveness. 

You can use DAX Studio to optimize the inspection of DAX statements from a performance perspective and use the Performance analyzer to check the performance of each of your report elements when users interact with them, and which aspects of performance consume the most (or least) resources

https://daxstudio.org/

https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-performance-analyzer

 

This is the related document, you can view this content:

Optimizing DAX expressions involving multiple measures - SQLBI

Improve Power BI Performance by Optimizing your DAX | by MAQ Software | MAQ Software | Medium

All the secrets of SUMMARIZE - SQLBI

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous Thanks I will try your suggestions.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.