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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
joepath
Helper II
Helper II

Dax Query optimization

Hello,

 

Below query is for Total Sum of the positive values in tablur report, working as expected but liitle slow.

 

How to rewrite it in optimize way?

 

Correct Total Sum = SUMX(
FILTER(
ADDCOLUMNS(
SUMMARIZE(Fact,dimA[Aname],dimB[BName]),
"@MeasureA",[MeasureA],
"@MeasureB",[MeasureB)],
"@MeasureC",[MeasureC]

),
[@MeasureA]>0 && [@MeasureB]>0 && [@MeasureC]>0
)
,[@MeasureA]
)

 

Thanks,

7 REPLIES 7
m3tr01d
Continued Contributor
Continued Contributor

@joepath Most likely, the problem are inside the 3 measures you are using.

Please give us the exact code of the three measures.

Thank you

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

@joepath - I agree with the others that you query is structured well.  A small suggestion is to possibly remove "dimA[Aname], dimB[BName]" from the SUMMARIZE function.  Instead you could summarize by the FK_A and FK_B on the main fact table.  There is a small performance gain in the SUMMARIZE step because the query "may not" need JOINS between the Fact table and DimA and DimB tables.  However, this would not work through if "dimA[Aname]" and "dimB[BName]" are sets/groups of many FK_A and FK_B, or when the Filter Context applying to the Fact table is referencing these table anyway.

bcdobbs
Community Champion
Community Champion

Is there any relationship between measure a, b and c. Just wondering if you could look at it from a maths point of view as to what needs to be true for all 3 to be greater than zero. That might be faster to test than actually evaluating the full values.

 

If you create a calculated table which materialises the table inside the sumx how many rows do you get? I agree with the others. Initial thought is it looks "ok". How slow is the query?

 

Only other thought is depending on what you need to slice by are you able to preagregate anything in a calculated table to move some evaluation away to model processing instead of live at query time.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
mahoneypat
Microsoft Employee
Microsoft Employee

I agree that measure looks pretty good, and would have written it the same way. How big is your Fact table and how many rows should that SUMMARIZE table have?  One thing you could try would be to filter it sequentially with FILTER(FILTER(FILTER. Not sure it will help much but easy to try.

 

Correct Total Sum =
SUMX (
    FILTER (
        FILTER (
            FILTER (
                ADDCOLUMNS (
                    SUMMARIZE ( Fact, dimA[Aname], dimB[BName] ),
                    "@MeasureA", [MeasureA]
                ),
                [@MeasureA] > 0
            ),
            [MeasureB] > 0
        ),
        [MeasureC] > 0
    ),
    [@MeasureA]
)

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks all for looking into this, seems not much changes is required,

amitchandak
Super User
Super User

@joepath , this seems fine, need to check calculation for three measures

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  Measure have basic avg calculations, Is there any way to replace filter function with calculatedtable? I see filter always create prob on a big table.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Users online (3,406)