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! Learn more

Reply
Anonymous
Not applicable

Average per ID using data from last 3 years

19I have a table with data por ID and sales per month Like this

Rick_ferreira_0-1624445931431.png

I need to create a calculated column with average per ID per month for each id like this

Rick_ferreira_1-1624445992569.png

I used that but it appears circular dependency.

Average_last_ 3_year =

VAR year_ref =

    YEAR ( T_[date])

VAR month_ref =

    MONTH ( T_[date])

RETURN

    IF (

        year_ref - 2

            >= MINX ( ALL ( T_[date]), YEAR ( T_[date]) ),

        AVERAGEX (

            FILTER (

                ALLEXCEPT(  T_, T[Id]),

                YEAR (( T_[date]) ) < year_ref

                    && YEAR (( T_[date]) >= year_ref - 3

                    && MONTH (( T_[date]) ) = month_ref

            ),

            T_[Valor]

        )

    )

What is it wrong(**

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @Anonymous ,

You need to change your column formula a bit:

Column =
VAR currYear = YEAR ( T[Date] )
VAR currMonth = MONTH ( T[Date] )
VAR currID = T[Id]
RETURN
    IF (
        currYear - 2 > MINX ( ALL ( T ), YEAR ( T[Date] ) ),
        AVERAGEX (
            FILTER (
                T,
                T[Id] = currID
                    && YEAR ( T[Date] ) < currYear
                    && YEAR ( T[Date] ) >= currYear - 3
                    && MONTH ( T[Date] ) = currMonth
            ),
            T[Value]
        )
    )

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

3 REPLIES 3
ERD
Community Champion
Community Champion

Hi @Anonymous ,

You need to change your column formula a bit:

Column =
VAR currYear = YEAR ( T[Date] )
VAR currMonth = MONTH ( T[Date] )
VAR currID = T[Id]
RETURN
    IF (
        currYear - 2 > MINX ( ALL ( T ), YEAR ( T[Date] ) ),
        AVERAGEX (
            FILTER (
                T,
                T[Id] = currID
                    && YEAR ( T[Date] ) < currYear
                    && YEAR ( T[Date] ) >= currYear - 3
                    && MONTH ( T[Date] ) = currMonth
            ),
            T[Value]
        )
    )

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

New column =

var _month = month([Date])

var _id = [id]

return

averagex(filter(Table, [id]=_id  && month([Date])  =_month ), [value])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

I need to calculate the average using always data from last 3 years.

Helpful resources

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

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