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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.