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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Build column with average of last 12 month

Hi all,
I have a table below:

Rick_ferreira_0-1617984040271.png


I need do create a column, using dax with avarage of the last 12 months, for instance:

Rick_ferreira_1-1617984095662.png

Basically, the avg column is the avarage of the last 12 month.

Can someone help me?
Thanks

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

If there is a date table in your model, you can try this Calculated column.

 

 

Avrage_last_12_month =

CALCULATE (

    AVERAGE ( 'Table'[value] ),

    DATESINPERIOD ( 'calendar'[Date], 'Table'[Date], -12, MONTH ),

    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )

)

 

 

If you don't have date table, you can try this Calculated column.

 

Avg last 12 months =

VAR day =

    YEAR (

        CALCULATE (

            SELECTEDVALUE ( 'Table'[Date] ),

            FILTER ( 'Table', 'Table'[Date] = MIN ( 'Table'[Date] ) )

        )

    )

VAR month_count =

    IF (

        'Table'[Date] >= DATE ( day, 12, 31 ),

        12,

        CALCULATE (

            COUNT ( 'Table'[Date] ),

            FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )

        )

    )

VAR cur_month =

    MONTH ( 'Table'[Date] )

VAR cur_year =

    YEAR ( 'Table'[Date] )

VAR sum_last_12_month =

    IF (

        cur_month < 12,

        CALCULATE (

            SUM ( 'Table'[value] ),

            FILTER (

                ALL ( 'Table' ),

                (

                    YEAR ( 'Table'[Date] ) = cur_year

                        && MONTH ( 'Table'[Date] ) <= cur_month

                )

                    || (

                        YEAR ( 'Table'[Date] ) = cur_year - 1

                            && MONTH ( 'Table'[Date] ) > cur_month

                    )

            )

        ),

        CALCULATE (

            SUM ( 'Table'[value] ),

            FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Date] ) = cur_year )

        )

    )

RETURN

    sum_last_12_month/month_count

 

 

The result looks like this:

v-cazheng-msft_0-1618214578213.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? 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

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

If there is a date table in your model, you can try this Calculated column.

 

 

Avrage_last_12_month =

CALCULATE (

    AVERAGE ( 'Table'[value] ),

    DATESINPERIOD ( 'calendar'[Date], 'Table'[Date], -12, MONTH ),

    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )

)

 

 

If you don't have date table, you can try this Calculated column.

 

Avg last 12 months =

VAR day =

    YEAR (

        CALCULATE (

            SELECTEDVALUE ( 'Table'[Date] ),

            FILTER ( 'Table', 'Table'[Date] = MIN ( 'Table'[Date] ) )

        )

    )

VAR month_count =

    IF (

        'Table'[Date] >= DATE ( day, 12, 31 ),

        12,

        CALCULATE (

            COUNT ( 'Table'[Date] ),

            FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )

        )

    )

VAR cur_month =

    MONTH ( 'Table'[Date] )

VAR cur_year =

    YEAR ( 'Table'[Date] )

VAR sum_last_12_month =

    IF (

        cur_month < 12,

        CALCULATE (

            SUM ( 'Table'[value] ),

            FILTER (

                ALL ( 'Table' ),

                (

                    YEAR ( 'Table'[Date] ) = cur_year

                        && MONTH ( 'Table'[Date] ) <= cur_month

                )

                    || (

                        YEAR ( 'Table'[Date] ) = cur_year - 1

                            && MONTH ( 'Table'[Date] ) > cur_month

                    )

            )

        ),

        CALCULATE (

            SUM ( 'Table'[value] ),

            FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Date] ) = cur_year )

        )

    )

RETURN

    sum_last_12_month/month_count

 

 

The result looks like this:

v-cazheng-msft_0-1618214578213.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

sayaliredij
Solution Sage
Solution Sage

Check out this article from SQLBI

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

 

This would help to solve your problem

 

Regards,

Sayali

 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks

I need to create a column on table not measure.
This article shows measure.

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