Forum Discussion

JustinDoh1's avatar
JustinDoh1
Post Prodigy
1 year ago
Solved

Performance issue with AVERAGEX

I have a about 1.1 million rows of data with 7 columns.

 

I tried this measure called "Average" to filter my visual, PBI visual is having a big performance/memory issue.

 

Below is detail of that measure that is causing performance issue: 

 

Average = AVERAGEX
                   (
                    VALUES(DimDate[DateFormat]),
                        CALCULATE(
                                            [ClientD_M1]
                                           )
                    )

 

When I tried on the visual as 'Average is not 0', the visual is having a performance issue:

 

Bottom is detail of a measure called  [ClientD_M1]:
 
ClientD_M1 = count('TblCensus'[ClientID]) + 0
 
Is there any better way to optimize the DAX of "Average" by chance?
 
Or is there any way to apply the filter (value that is greater than 0) in other possibly way?
 
Thanks.
  • JustinDoh1 Instead of using VALUES, you can use SUMMARIZE to create a summarized table that might perform better.

     

    Average =
    AVERAGEX(
    FILTER(
    SUMMARIZE(
    'TblCensus',
    DimDate[DateFormat],
    "ClientD_M1", [ClientD_M1]
    ),
    [ClientD_M1] > 0
    ),
    [ClientD_M1]
    )

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi JustinDoh1 ,

    The AVERAGEX function combined with VALUES may cause performance issues because of the excessive number of rows and context transitions it creates. If you can simplify the context in which AVERAGEX operates, it might help. You can try using the following DAX:

    Average = 
    AVERAGEX(
        ALLSELECTED(DimDate[DateFormat]),
        [ClientD_M1]
    )
    

    If possible, pre-aggregate data in Power Query or in the data source to reduce the number of rows processed in DAX and reduce context switching.

    Another approach is to use SUMMARIZE to create a table with the precomputed values, and then use AVERAGEX on that summary table.

    Average = 
    VAR SummarizedTable = 
        SUMMARIZE(
            'TblCensus',
            'TblCensus'[DateFormat],
            "ClientCount", COUNT('TblCensus'[ClientID])
        )
    RETURN
        AVERAGEX(
            SummarizedTable,
            [ClientCount]
        )
    

    Hope this will help you!

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

  • JustinDoh1 Instead of using VALUES, you can use SUMMARIZE to create a summarized table that might perform better.

     

    Average =
    AVERAGEX(
    FILTER(
    SUMMARIZE(
    'TblCensus',
    DimDate[DateFormat],
    "ClientD_M1", [ClientD_M1]
    ),
    [ClientD_M1] > 0
    ),
    [ClientD_M1]
    )

    • JustinDoh1's avatar
      JustinDoh1
      Post Prodigy

      bhanu_gautam I have a question. I am experimeting with performance. It appears that when I try the same query in Bookmark, it is really slow or even it crashes. It says "There's not enough memory to complete this operation." Why is that? 

  • Anonymous Thank you for your help. I think applying additional filter later to the visual would still slow down the performance so I chose "bhanu_gautam"'s soltuion. I have a question. You mentioned about "pre-aggregate data in Power Query". How do I go about doing this?

     

     

      • JustinDoh1's avatar
        JustinDoh1
        Post Prodigy

        Anonymous  Regards to my case where I need to filter by "Average" is not 0, how do I group by? "Average" is a measure. Would Power Query work with a measure, not just column? Thanks.