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

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

Reply
Gonqq
Helper I
Helper I

Optimizing a DAX Formula

Hi everyone. I'm having trouble with a small dax formula: it consumes a lot of memory and i can't add anymore rows to a mtarix because of it. The formula is the following:

Gonqq_0-1632911650588.png

It was one of my first ever formulas on power bi and now im coming back to upgrade it so i can add more rows to a matrix i have. How can i optimize this formula?

 

Thank you in advance

 

5 REPLIES 5
v-kkf-msft
Community Support
Community Support

Hi @Gonqq ,

 

Has your problem been solved? If it is solved, please mark a reply which is helpful to you.

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

 

Best Regards,
Winniz

 

mahoneypat
Microsoft Employee
Microsoft Employee

I'm surprised this is slow, so I'm assuming you have many combinations of values based on the columns used in the matrix.  I would first look at the query behind the matrix using Performance Analyzer and try to reduce granularity.  If that can't be improved, I would use nested IF functions instead of SWITCH(TRUE().  Your expression forces all 3 variables to be evaluated every time.  Try to nest them so that you eliminate the most early on.

 

NewExpression =
IF (
    SELECTEDVALUE ( Contas[Grupo Conta] ) <> 62,
    "N/A",
    IF (
        SUM ( Principal[Real] ) > 0,
        "N/A",
        IF (
            SUM ( Principal[PO] ) > 0,
            "N/A",
            GE
        )
    )
)

 

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


Greg_Deckler
Community Champion
Community Champion

@Gonqq One way would be to have your GE row be this:

VAR GE = DIVIDE(R; P; "N/Orc")



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , thank you. I tried it out and it still pulls a lot of memory. I'm almost certain that it's the switch condition that's causing the problem but i really must have that condition.

@Gonqq Try: VAR C = IF(gc + R + P = 62, "n.a";GE)

Arithmatic is faster than comparison operators and no need for a SWITCH if it is just a single condition.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.