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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Anonymous
Not applicable

Grouped moving average for defined

Hi All,

 

I have a table like this               

Countries

Cities

Years

Temperature

Country1

City1

Year1

Temperature(value)

Country1

City1Year2Temperature(value)

Country1

City1Year3Temperature(value)

Country1

City2Year1Temperature(value)

Country1

City2Year2Temperature(value)

Country1

City2Year3Temperature(value)

Country2

City3Year1Temperature(value)
Country2City3Year2 Temperature(value)
Country2City3Year3 Temperature(value)
Country2City4Year1 Temperature(value)

 

I would like to calculate the moving average temperature by City and Country. All of my previous attempts have slipped through the Country/City groups meaning that moving averages contained data from previous cities and years.

 

Is there any solution that somehow strictly calculates inside the boundaries?

 

The intended solution would look like this for a 2-year moving average

Countries

Cities

Years

TemperatureTemp Moving Average

Country1

City1

Year1

Temperature(value)-

Country1

City1Year2Temperature(value)M.AVG1

Country1

City1Year3Temperature(value)M.AVG2

Country1

City2Year1Temperature(value)-

Country1

City2Year2Temperature(value)M.AVG1

Country1

City2Year3Temperature(value)M.AVG2

Country2

City3Year1Temperature(value)-
Country2City3Year2 Temperature(value)M.AVG1
Country2City3Year3 Temperature(value)M.AVG2
Country2City4Year1 Temperature(value)-

 I would be very grateful even if someone only pointed out the problem or directed me in the right direction. 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
Please try

 

Temp Moving Average =
CALCULATE (
    AVERAGE ( TableName[Temperature] ),
    ALLEXCEPT ( TableName, TableName[Countries], TableName[Cities] ),
    TableName[Years] <= MAX ( TableName[Years] )
)

 

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @Anonymous 
Please try

 

Temp Moving Average =
CALCULATE (
    AVERAGE ( TableName[Temperature] ),
    ALLEXCEPT ( TableName, TableName[Countries], TableName[Cities] ),
    TableName[Years] <= MAX ( TableName[Years] )
)

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.