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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Dynamic calculation moving average depending on filter

I have the following problem:
I have calculated a dynamic measure index:

Index_Measur 2 =
CALCULATE (
COUNTROWS ( Tabelle1 ),
FILTER ( ALLSELECTED ( Tabelle1 ), Tabelle1[Faktor 1] < MAX ( Tabelle1[Faktor 1] ) )
)

and the moving average with the following function:

Moving Average_Measure IndexMeasure =
VAR Window_A = 10
VAR myResult =
SUMX(
FILTER(
Tabelle1,
Tabelle1[Index_Measur 2]> Tabelle1[Index_Measur 2]-Window_A &&
Tabelle1[Index_Measur 2] <=Tabelle1[Index_Measur 2]
),Tabelle1[Wert]
)
RETURN CONVERT(myResult/Window_A,DOUBLE)

 

Tabelle1[Werte] are the values for moving average

 

I cannot create a plot Moving mean as a function of dynamic index. Where is the error?

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Can please explain the logic here


Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

refer if this can help

https://exceleratorbi.com.au/pareto-analysis-in-power-bi/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hallo amitchandak,
thanks for the reply
I would like to calculate and display the moving average depending on the filter, e.g. factor 2 = A.
This are only test data!
Faktor 1Faktor 2WertIndexMoving Average Test
AB110.1
BA420.5
BA631.1
AB741.8
BB352.1
AA262.3
BB172.4
BB582.9
BA893.7
This are the basic data!
The index is calculate with: 
Index = RANKX(Tabelle1,Tabelle1[Index],,ASC)
 
The moving average with:
Moving Average Test =
VAR MyIndex = Tabelle1[Index]
VAR Window_A = 10
VAR myResult =
SUMX(
FILTER(
Tabelle1,
Tabelle1[Index] > MyIndex-Window_A &&
Tabelle1[Index] <= MyIndex
),Tabelle1[Wert]
)
RETURN FIXED(myResult/Window_A ,2)
I would now like to calculate moving average, e.g. if A is selected in column Factor 2.
I want to create a plot: Moving average as a function of the new dynamic index.
 
PREVIEW
Friedbert
 
Anonymous
Not applicable

HI @Anonymous,

Did you mean the 'window A' part should be replaced with the current selection from the filter?
If that is the case, you can create an unrelated table for all needed selection values and not have a relationship to the current table.
Then you can use the Dax function to get sections from the filter/slicer to interact with current expressions.

formula =
VAR Window_A =
    MAX ( NewTable[Value] )
VAR myResult =
    CALCULATE (
        SUM ( Tabelle1[Wert] ),
        FILTER (
            ALLSELECTED ( Tabelle1 ),
            Tabelle1[Index_Measur 2] > Tabelle1[Index_Measur 2] - Window_A
                && Tabelle1[Index_Measur 2] <= Tabelle1[Index_Measur 2]
        )
    )
RETURN
    CONVERT ( myResult / Window_A, DOUBLE )

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.