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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rishari
Frequent Visitor

DAX Optimization SUMX ( SUMMARIZE ) - Performance Issue

I'm not able to optimize this measure. I'm new to Power BI DAX. Kindly suggest me a way to run this DAX faster.

If I am wrong, please suggest me any other alternative way to achieve the below DAX

DAX Measure:
Measure name =
SUMX (
SUMMARIZE (table_name',
table_name'[Col1],table_name'[Col2],table_name'[col3],table_name'[col4],table_name'[col5],

"result",
CALCULATE (
DISTINCTCOUNTNOBLANK ( table_name'[col1] ),
FILTER (
table_name',
SUM ( table_name'[Counter] ) = 1
)
)
),
[result]
)

11 REPLIES 11
rishari
Frequent Visitor

@tamerj1 @johnt75 @Greg_Deckler -

I have created a temporary column using concat and counter column in the dataset.

temp_column = table_name[col1], table_name[col2]. table_name[col3], table_name[col4], table_name[col5]
Counter = 1 if the couter sum = 1 else 0

 

And I updated this DAX.
CALCULATE(
            DISTINCTCOUNTNOBLANK ( TableName [Temp_column] ),
            KEEPFILTERS ( tableName [Counter] = 1 )
 )


Still, I'm facing the issue. The value is not matching. DAX is really difficult, please help me on this.

tamerj1
Super User
Super User

@rishari 

Please try

MeasureName =
SUMX (
SUMMARIZE (
FILTER ( table_name, table_name[Counter] = 1 ),
table_name[Col1],
table_name[Col2],
table_name[col3],
table_name[col4],
table_name[col5],
"result", COUNTROWS ( VALUES ( table_name[col1] ) )
),
[result]
)

Hi @tamerj1 - I tried this, but instead of numbers, I'm getting blank

@rishari 

Please try

MeasureName =
SUMX (
FILTER (
SUMMARIZE (
table_name,
table_name[Col1],
table_name[Col2],
table_name[col3],
table_name[col4],
table_name[col5],
"@Result", COUNTROWS ( VALUES ( table_name[col1] ) ),
"@Counter", SUM ( table_name[Counter] )
),
[@Conter] = 1
),
[@Result]
)

Hi @tamerj1 - I'm getting the value now. It loads much faster. But still we have more granularity, hence it is not loading in the matrix. It takes much time

@rishari 
Try

MeasureName =
SUMX (
    SUMMARIZE (
        table_name,
        table_name[Col1],
        table_name[Col2],
        table_name[col3],
        table_name[col4],
        table_name[col5],
        "@Result", COUNTROWS ( VALUES ( table_name[col1] ) ),
        "@Counter", SUM ( table_name[Counter] )
    ),
    IF ( [@Conter] = 1, [@Result] )
)
johnt75
Super User
Super User

Its not best practice to use SUMMARIZE to add calculated columns, its better to use ADDCOLUMNS, e.g.

MyMeasure =
SUMX (
    ADDCOLUMNS (
        SUMMARIZE (
            'table_name',
            'table_name'[Col1],
            'table_name'[Col2],
            'table_name'[col3],
            'table_name'[col4],
            'table_name'[col5]
        ),
        "result",
            CALCULATE (
                DISTINCTCOUNTNOBLANK ( 'table_name'[col1] ),
                FILTER ( 'table_name', SUM ( 'table_name'[Counter] ) = 1 )
            )
    ),
    [result]
)

@johnt75 - I need a single value to add in the matrix.

This will return a single value, its just an optimized version of your code.

Greg_Deckler
Super User
Super User

@rishari Can you post sample data so can test and optimize.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler - Sorry, I can't. It is confidential

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors