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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
RTERCERO
Helper I
Helper I

Optimize speed of SUMx and Share of category

Hello,

I'm calculating SKU adherence which considers evaluating row by Row, the calculation works properly when switching time frames however as I add rows to the model It becomes a lot slower, here are the mathematical Formulas with their measures:

 

RTERCERO_0-1649198617860.png

 

SKU Adherence Measure = 
VAR t_ =
    ADDCOLUMNS ( SKU_TEST, "a_", [% Adherence], "b_", [Participation] )
RETURN
    SUMX ( t_, [a_] * [b_] )

 


Where: 

RTERCERO_1-1649198617865.png

 

Adherence = 
IF( 
    DIVIDE([Real Amount],[Planned Amount])>1,
    1,
DIVIDE([Real Amount],[Planned Amount]))
Planned Amount = 
If(CALCULATE(SUMX(SKU_TEST,SKU_TEST[PLAN]),DATESYTD(SKU_TEST[Date]))=0,
    BLANK(),
CALCULATE(SUMx(VALUES(SKU_TEST[PLAN]),Calculate(SUM(SKU_TEST[PLAN]),DATESYTD(SKU_TEST[Date]))))
)
Real Amount = 
If(CALCULATE(SUMX(SKU_TEST,SKU_TEST[PLAN]),DATESYTD(SKU_TEST[Date]))=0,
    BLANK(),
CALCULATE(SUMx(VALUES(SKU_TEST[REAL]),Calculate(SUM(SKU_TEST[REAL]),DATESYTD(SKU_TEST[Date]))))
)

 

 

RTERCERO_2-1649198618128.png

 

Participation = 
If(
   [Planned Amount]=0,
    BLANK(),
DIVIDE([Planned Amount],[Total Plan of Selected Period]))
Total Plan of Selected Period = 
If(
   [Planned Amount]=0,
    BLANK(),
CALCULATE([Planned Amount] ,ALLSELECTED(SKU_TEST)))

 


First inquire is , how do I make it Faster?

Second inquire is related to "Participation", it should calculate based on "Product"  an be scalable to  into any other category as "Program" or "Area", Currently its not working like that, So I tried an alternate formula named "Participation 2" That calculates properly bus when used to calculate SKU adherence (SKU Adherence 2 for example on model) runs out of memory, also I would need to make a measure for each category:

  

 

SKU Adherence Measure 2 = 
VAR t_ =
    ADDCOLUMNS ( SKU_TEST, "a_", [% Adherence], "b_", [Participation 2] )
RETURN
    SUMX ( t_, [a_] * [b_] )
Participation 2 = 
If(
   [Planned Amount]=0,
    BLANK(),
DIVIDE([Planned Amount],[Total Plan of Selected Period 2])
)
Total Plan of Selected Period 2 = 
If(
   [Planned Amount]=0,
    BLANK(),
CALCULATE([Planned Amount] ,ALLSELECTED(SKU_TEST),SKU_TEST[PROGRAM]=min(SKU_TEST[PROGRAM])))

 

 

Attaching File Samples:https://we.tl/t-to7V3wpZpV

Best Regards

RT

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @RTERCERO ,

 

Unfortunately, due to the performance of my computer, opening the pbix you provided will get stuck, so I can't check your pbix.

In general, avoid bi-directional relations at all costs.

https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax/ 

What you need to know about the if statement is:

Incorrect DAX: 

Participation 2 = 
If(
   [Planned Amount]=0,
    BLANK(),
DIVIDE([Planned Amount],[Total Plan of Selected Period 2])
)

Here, measures are calculated continuously, meaning the [Total Rows] expression is calculated twice: first for the condition check, then for the true condition expression.

Correct DAX: 

Participation 2 = 
var Planned Amount_ = [Planned Amount]
var Total Plan of Selected Period 2_ = [Total Plan of Selected Period 2]
If(
   Planned Amount_=0,
    BLANK(),
DIVIDE(Planned Amount_,Total Plan of Selected Period 2_)
)

Instead of calculating the same expression multiple times, you can store the resulting measure value in a variable. You can use a variable reference wherever required. The same variable process applies to all instances where you call the same measure. Variables can help you avoid repetitive functions.


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

View solution in original post

1 REPLY 1
V-lianl-msft
Community Support
Community Support

Hi @RTERCERO ,

 

Unfortunately, due to the performance of my computer, opening the pbix you provided will get stuck, so I can't check your pbix.

In general, avoid bi-directional relations at all costs.

https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax/ 

What you need to know about the if statement is:

Incorrect DAX: 

Participation 2 = 
If(
   [Planned Amount]=0,
    BLANK(),
DIVIDE([Planned Amount],[Total Plan of Selected Period 2])
)

Here, measures are calculated continuously, meaning the [Total Rows] expression is calculated twice: first for the condition check, then for the true condition expression.

Correct DAX: 

Participation 2 = 
var Planned Amount_ = [Planned Amount]
var Total Plan of Selected Period 2_ = [Total Plan of Selected Period 2]
If(
   Planned Amount_=0,
    BLANK(),
DIVIDE(Planned Amount_,Total Plan of Selected Period 2_)
)

Instead of calculating the same expression multiple times, you can store the resulting measure value in a variable. You can use a variable reference wherever required. The same variable process applies to all instances where you call the same measure. Variables can help you avoid repetitive functions.


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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.