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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
danielcontente
Helper II
Helper II

Average per row based on slicer

Hi all, 

 

I have created a table and would like to create a measure that will average the values per row for the 2 previous years.

In the below table, the result for WEEK 41, for example, would be 487,003 (average of 2020 and 2021)

 

Thanks in advance 

 

danielcontente_0-1673362308502.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @danielcontente ,

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _today=YEAR(TODAY())
var _1year=
SUMX(FILTER(ALL('Table'),'Table'[Year]=_today -1&&'Table'[Weeknumber]=MAX('Table'[Weeknumber])),[Value])
var _2year=
SUMX(FILTER(ALL('Table'),'Table'[Year]=_today -2&&'Table'[Weeknumber]=MAX('Table'[Weeknumber])),[Value])
return
DIVIDE(
    _1year+_2year,2)

2. Result:

vyangliumsft_0-1673414437908.png

 

Best Regards,

Liu Yang

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

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi  @danielcontente ,

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _today=YEAR(TODAY())
var _1year=
SUMX(FILTER(ALL('Table'),'Table'[Year]=_today -1&&'Table'[Weeknumber]=MAX('Table'[Weeknumber])),[Value])
var _2year=
SUMX(FILTER(ALL('Table'),'Table'[Year]=_today -2&&'Table'[Weeknumber]=MAX('Table'[Weeknumber])),[Value])
return
DIVIDE(
    _1year+_2year,2)

2. Result:

vyangliumsft_0-1673414437908.png

 

Best Regards,

Liu Yang

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

FreemanZ
Community Champion
Community Champion

hi @danielcontente 

try like:

Average = 
VAR _2020 = CALCULATE(SUM(TableName[Value]), YEAR(TableName[Date])=2020)
VAR _2021 = CALCULATE(SUM(TableName[Value]), YEAR(TableName[Date])=2021)
RETURN
(_2020+_2021)/2

 

AlB
Community Champion
Community Champion

I cannot copy the data from a picture

Dynamic based on what? Why not 2022 and 2021?

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Dynamic based on the current year.

AlB
Community Champion
Community Champion

Hi @danielcontente 

1. Can you share a sample of the relevant tables in your model? Or, ideally, the pbix?

2. How are the "2 previous years" determined? Is it always 2020 and 2021 or dynamic?

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

the previous two years are dynamic

Hi, the table is in the first comment (there is a picture).

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.