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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
joepath
Helper II
Helper II

DAX Query, ALL function performance issue.

Hello,

Is there any way to rewrite the below qeury in optimize way, its taking lot of time to return the result in tabular report.

Calculating total order for each product, across time,country and employee.

 

Total Order Measure = CALCULATE(

                             COUNT(Fact[dimOrderID]),OR(Fact[OrderType]="aaa",Fact[OrderType]="bbb")
                              ,ALL(dimDate[dimDateID])
                             ,ALL(dimCountry),ALL(dimEmployee)

                  )

Table would be like below. and Totalorder will be change by report filter.

Filter: country   Filter: Date, Filter: Employee

Product      TotalOrder.

 

Thanks,

1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

The problem is you are removing the existing filters from Date, Employee and Country because of which CALCULATE never returns blank for combinations where there is no row in the Fact table and your code triggers the CROSSAPPLY (CROSSFJOIN) behaviour of DAX Engines which returns all the possible combinations of the columns in the visual/matrix, since available information here is limited you can use this:

 

 

Total Order Measure =
IF (
    NOT ISEMPTY ( Sales ),
    CALCULATE (
        COUNTROWS ( VALUES ( Sales[ProductKey] ) ),
        OR ( Fact[OrderType] = "aaa", FactROI[OrderType] = "bbb" ),
        ALL ( dimDate[dimDateID] ),
        ALL ( dimCountry ),
        ALL ( dimEmployee )
    )
)

 

View solution in original post

6 REPLIES 6
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @joepath - what is the "FactROI[OrderType]" that is included in your query?  Is this necessary.  I would need a model and dax studio to try by I would explore using REMOVEFILTERS instead of using the separate ALL references

Thanks Daryl-Lynch-Bzy looking into this, tried AntrikshSharma solution and its working fine now.

AntrikshSharma
Super User
Super User

The problem is you are removing the existing filters from Date, Employee and Country because of which CALCULATE never returns blank for combinations where there is no row in the Fact table and your code triggers the CROSSAPPLY (CROSSFJOIN) behaviour of DAX Engines which returns all the possible combinations of the columns in the visual/matrix, since available information here is limited you can use this:

 

 

Total Order Measure =
IF (
    NOT ISEMPTY ( Sales ),
    CALCULATE (
        COUNTROWS ( VALUES ( Sales[ProductKey] ) ),
        OR ( Fact[OrderType] = "aaa", FactROI[OrderType] = "bbb" ),
        ALL ( dimDate[dimDateID] ),
        ALL ( dimCountry ),
        ALL ( dimEmployee )
    )
)

 

Thanks it solved my problem

@AntrikshSharma After applying the  NOT ISEMPTY ( Sales ) a bug is coming.below 19301, 19302 are the dimension column values, and other 2 columns are measure, and in the 3rd column where I applied the above dax.Before appying the IF( NOT( ISEMPTY(FactROI)) below is the result which is working fine, even 19302 dimension doest have value in the first column but 3rd one still showing the result.

joepath_0-1650298012976.png

Now after applying the IF( NOT( ISEMPTY(FactROI)) 2nd row gone.

joepath_1-1650298230102.png

How to fix it without impacting the result? if I remove if condition then performance is very slow.

 

Thanks,

 

 

 

 

 

 

Thanks AntrikshSharma that was quick reply, Tested the your suggestion working well.

Can you also look at the below post if you have some suggestion.

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dax-Query-optimization/m-p/2281488

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.