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
Anonymous
Not applicable

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
Anonymous
Not applicable

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



Anonymous
Not applicable

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
Anonymous
Not applicable

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



Anonymous
Not applicable

So basically I need in columns:

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

Hi @Anonymous ,

 

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.

Anonymous
Not applicable

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
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