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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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


✔ Answered? Mark as solution

Muhammad Hasnain | Super User • Fabric • Power BI • Data Engineering

Let's connect on LinkedIn
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


✔ Answered? Mark as solution

Muhammad Hasnain | Super User • Fabric • Power BI • Data Engineering

Let's connect on LinkedIn
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))

✔ Answered? Mark as solution

Muhammad Hasnain | Super User • Fabric • Power BI • Data Engineering

Let's connect on LinkedIn

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.