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! Request now

Reply
ebrownretail
Resolver I
Resolver I

Avg Temp for specifc dates

Hi!

I am trying to pull the average temperature for a specific date/city so we can see how far above or below tomorrows forecast is. Any ideas? i tried the below, but it did not work. 

 

 

Avg Temp =
CALCULATE(AVERAGEX('weather history', 'weather history'[temp]), FILTER(DATESINPERIOD(Dates[Date], SELECTEDVALUE('weather history'[datetime]) , -5, YEAR), 'weather history'[datetime]))
3 REPLIES 3
Anonymous
Not applicable

Hi @ebrownretail , thanks for the reply from lszymk97.

 

Please try the following measure:

Avg Temp =
CALCULATE(
   AVERAGEX(
       'weather history',
       'weather history'[temp]
   ),
   FILTER(
       'weather history',
       'weather history'[datetime] >= DATEADD(SELECTEDVALUE('weather history'[datetime]), -5, YEAR) &&
       'weather history'[datetime] <= SELECTEDVALUE('weather history'[datetime])
   )
)

Best regards,

Joyce

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

lszymk97
Frequent Visitor

Hello,
Can you try to use below? Your formula references a 'Dates' table in the DATESINPERIOD function, but then tries to filter the 'weather history' table. 

Avg Temp =
CALCULATE( AVERAGE('weather history'[temp]), FILTER( ALL('weather history'), AND( 'weather history'[city] = SELECTEDVALUE('weather history'[city]), 'weather history'[datetime] <= SELECTEDVALUE('weather history'[datetime]), 'weather history'[datetime] > DATEADD(SELECTEDVALUE('weather history'[datetime]), -5, YEAR) ) ) )

i got this error for this

 

ebrownretail_0-1724096298240.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors
Top Kudoed Authors