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
paris
Helper V
Helper V

Add previous 4 years average using DAX

Hi All,
I have monthly sales by city from 1 Jul 2017 to 1 Aug 2021. 
I would like to add 4 year average sales by city to my graph(like red line in the graph) Please help!

 

powerbiparis.JPG

 

I tried to use similar dax I found in community , but did not work because...
It showed error when I typed Sales[Date].[Year]
I also do not know how to filter by city.... 

Measure =
AVERAGEX (
SUMMARIZE (
FILTER (
Sales,
YEAR ( Sakes[Date] )
>= YEAR ( TODAY () ) - 4
&& YEAR ( Sales[Date] ) < YEAR ( TODAY () )
),
Sales[Date].[Year]
),
CALCULATE ( SUM ( Sales[Sales] ) )
)

All the best,
Paris

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @paris 

 

For calculating the average, you can try the following two schemes.

1. Calculated column

 

Average =
CALCULATE (
    AVERAGE ( Sales[Sales] ),
    FILTER ( Sales, Sales[Month] = EARLIER ( Sales[Month] ) )
)

 

vzhangti_0-1636515864655.png

 

2. Measure

 

 Measure =
CALCULATE (
    AVERAGE ( Sales[Sales] ),
    FILTER ( ALL ( Sales ), Sales[Month] = MAX ( Sales[Month] ) )
)

 

vzhangti_1-1636515910995.png

 

Best Regards,

Community Support Team _Charlotte

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

Fowmy
Super User
Super User

@paris 

Can you use the following measure?

AVERAGEX (
    SUMMARIZE (
        FILTER (
            all(Sales[Year]),
            Sales[Year] >= YEAR ( TODAY () ) - 4  && Sales[Year]  < YEAR ( TODAY () )
        ),
        Sales[Year]
    ),
    CALCULATE ( SUM ( Sales[Sales] ) )
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi Fowmy,

Thank you for your reply. I tried your measure but it shows same number as original sales except there is no data in 2021. 

I  wanted to add average for 2017 - 2020 only so I also tried below but the result is the same number as original sales except there is no data in 2021. 

AVERAGEX (
SUMMARIZE (
FILTER (
all(Sales[Year]),
Sales[Year] >= 2017 && Sales[Year] < 2021
),
Sales[Year]
),
CALCULATE ( SUM ( Sales[Sales] ) )
)

Thank you again and hope you can help me further. 

All the best,
Paris



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.

Top Solution Authors
Top Kudoed Authors