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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BIdeveloperDK
New Member

AVERAGEX with FILTER is very slow - running/cumulative total

Dear PBI Oracles,

 

I have a table consisting of some items named cItem with four belonging measures. I'm trying to calculate a running average of mAdjustPickRatio in a measure named mCumMeanAdjustPickRatio - based on their rank of the measure mRankAvgPickSize.

As I'm calculating an average of an existing average measure (mAdjustPickRatio), I'm sadly forced to use AVERAGEX. As demonstrated with the red box, for row/rank 11, I want the running average of all items less or equal to rank 11. 
Udklip2.PNG

 

However, the problem is that using AVERAGEX or SUMX in combination with FILTER, is very slow (two minutes or so), although I only have a thousand rows. I've tried following two measures:

mCumMeanAdjustPickRatio = 
VAR MyData = SUMMARIZE(ALLSELECTED(ITEM_DIM[cItem]);ITEM_DIM[cItem];"AvgPick";[mAvgPickSize];"AdjustPick";[mAdjustPickRatio];"Rank";[mRankAvgPickSize])
VAR CurrentRank = [mRankAvgPickSize]

RETURN
AVERAGEX(
    FILTER(MyData;[Rank]<=CurrentRank)
    ;[AdjustPick]
)

And: 

mCumMeanAdjustPickRatio2 = 
VAR CurrentRank = [mRankAvgPickSize]
RETURN
AVERAGEX(
    CALCULATETABLE(
        FILTER(
            ALLSELECTED(ITEM_DIM[cItem]);[mRankAvgPickSize]<=CurrentRank))
            ;[mAdjustPickRatio]
)

Both really slow.
The issue with AVERAGEX and SUMX, in combination with FILTER, is that is loops over the same data, and thus calculate a new table for each row, although I tried to make a constant table with VAR in example 1.

How can I fix this insane slow formula?

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@BIdeveloperDK,

 

You may take a look at https://www.sqlbi.com/topics/optimization/.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.