Reply
Anno2019
Helper IV
Helper IV

Most effecient way to include a IF statement in measure, Best Practise

Hi Guru's

 

I have many variables that need to be created and they are mostly always relying an if statement.

My reports performance is slowing down drastically.

What is the best practice to optimize performance when using this type of formula?

Should I create a Measure or better to create a Calculated Column?

Should I use SUMX? or is there a performance optimizing alternative?

 

Value Actual =
SUMX(
    'Data',
    IF(
        'Data'[Value Category]="Included in Pricing Model",
        'Data'[Price],
        0
    )
)
1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @Anno2019 

In your example it doesn't look like you need to use SUMX.  Instead start with a base measure that sums your price

 

Price Amount = SUM ( 'Data'[Price] )

 

Then you use that in measures that apply the filtering you need

 

Value Actual =
CALCULATE (
[Price Amount],
KEEPFILTERS ( 'Data'[Value Category] = "Included in Pricing Model" )
)

 

 SUMX is an iterator which can be expensive if you use it when you don't need to. 

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

Hello @Anno2019 

In your example it doesn't look like you need to use SUMX.  Instead start with a base measure that sums your price

 

Price Amount = SUM ( 'Data'[Price] )

 

Then you use that in measures that apply the filtering you need

 

Value Actual =
CALCULATE (
[Price Amount],
KEEPFILTERS ( 'Data'[Value Category] = "Included in Pricing Model" )
)

 

 SUMX is an iterator which can be expensive if you use it when you don't need to. 

@jdbuchanan71  This sounds great, will most certainly try this.  I have base measures for all my measures so will be easy to apply.

VijayP
Super User
Super User

In my Opinion always creating a measure is best instead of creating additional column in the Data

First Create a measure with SUMX or SUM based on the data and then filter that with other parameters in another measure.

If you have some data sample I can help further




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)