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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
teamanalytics
Frequent Visitor

calculate Average for previous year keeping filters on

So I am trying to write the query where I need the average of ratings from previous year to compare with current year.

The dataset has dates for past 5 years. How can I get the average for last year, last week compare to this year. I am writing something like this 

 

LYR =
AVERAGEX(
KEEPFILTERS(VALUES('Table_F'[Inbound_Outbound])),  # this is the filter so ratings are segregated in inbound and outbound
CALCULATE(AVERAGE('[Rating]))

)

9 REPLIES 9
teamanalytics
Frequent Visitor

teamanalytics_0-1644595647788.png

This is the output I am getting for average for all the years (ca/ea are the inbound and outbound channels) now this is YTD ratings, I need it to split it by year e.g average ratings for current year then append it to avg rating for 2021

Can you show the desired output in excel by exporting this data in excel


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



ChannelRatingLY RatingLY VarianceLW RatingLW Variance
CA4.694.77-0.074.76-0.07
EA4.704.86-0.164.87-0.17
 4.704.81-0.114.82-0.12
teamanalytics
Frequent Visitor

Hi mh2587, thanks for getting back to me. But it doesnt help with the filters required

Can elaborate further with your desire output and what filter you required with screenshots or something else


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



So basically I need in columns:

Current avg rating, last year's rating, variance, last week ratings & Variance

Hi @teamanalytics ,

 

Please try the following formula:

 

LY Rating = 
CALCULATE (
    [Rating],
    KEEPFILTERS ( VALUES ( 'Table_F'[Inbound_Outbound] ) ),
    DATESINPERIOD ( Dates[Date], MIN ( Dates[Date] ) - 1, -1, YEAR )
)

vkkfmsft_0-1644901323861.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Unfortunately its not working for me and giving me an error

 

"A single value for column 'Star_Rating' in table cannot be determined. a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

mh2587
Super User
Super User

LY Avg = CALCULATE(AVERAGE(Table[Rating]),DATEADD('Table'[Date],-1,YEAR))

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.