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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jonasdedual24
New Member

circular dependencies on moving average calculated column

I'm trying to create a moving average my table.

 

I have tryed below:

 

MovingAverage_Time_2 = 
VAR currentindex = Query1[Time]
VAR pastindex = currentindex - TIME(0, 10, 0)
VAR calc =  CALCULATE(
    AVERAGEx(Query1, Query1[audcad_close]),
    DATESBETWEEN(
        Query1[Time],
        "01.01.2024",
        "02.01.2024"
    )
)
/*VAR calc =  CALCULATE(
    AVERAGEx(Query1, Query1[audcad_close]),
    DATESBETWEEN(
        Query1[Time],
        pastindex,
        currentindex
    )
)
*/

RETURN calc

 

Unfortuantely, I get a an error message:

jonasdedual24_0-1705522224779.png

 

To simplify the error, I have repaced pastindex and currentindex with static values. However I still get same error.

There is no reference to MovingAverage_Time_2 and query1 is the only table in my model.

 

I've also tried to work with filters:

MovingAverage_Time = 
VAR currentindex = Query1[DateTime]
VAR pastindex = currentindex - TIME(0,[MovingAverage],0)
VAR calc = CALCULATE(
    AVERAGEx(Query1, Query1[audcad_close]),
    FILTER(
        Query1, 
        Query1[DateTime] > pastindex 
        && Query1[DateTime] <= currentindex
    )
)

RETURN calc

The above query works but the performance is not acceptable. I have about 100k rows.

 

Any help is highly apreciated.

 

 

1 REPLY 1
v-xinruzhu-msft
Community Support
Community Support

Hi @jonasdedual24 
Try the following code

MovingAverage_Time =
VAR currentindex = Query1[DateTime]
VAR pastindex =
    currentindex - TIME ( 0, [MovingAverage], 0 )
VAR _filter =
    FILTER (
        Query1,
        Query1[DateTime] > pastindex
            && Query1[DateTime] <= currentindex
    )
RETURN
    CALCULATE ( AVERAGE ( Query1[audcad_close] ), _filter )


Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.