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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
bbui11
Frequent Visitor

How to Calculate Sum of 12-Month Rolling Average Value in Matrix

Hi,

I have a requirement to calculate the sum of a 12-month sales rolling average measure for a given material.

Final Result would look like this:

Date Slicer: 1/1/2022 – 12/31/2023

 

Material #

Sum of Sales Moving Average for each month within the scope of the date slicer.

ABC

x

CDE

x

EFG

x

HIJ

x

KLM

x

 

I’m able to calculate the 12-month sales rolling average value appropriately on other matrix/line charts with an appropriate Month-Year axis, but I’m having a hard time summing up the 12-month sales rolling average values in the matrix above.

 

The matrix above would need to interact with a date slicer and various other slicers related to material #.

 

So pretty much:

  • Would need to calculate the 12-month sales rolling average value for each month for each given material within the time frame designated by the date slicer/ other slicers

 

  • Sum up all the  12-month sales rolling average value for each month within the date slicer, and present it in the matrix above.

 

Any tips/suggestions are greatly appreciated. Thanks so much for your help!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, 

I am not sure if I understand your question correctly, but I tried to create a sample pbix file like below.

please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1698814052127.png

 

 

Sales total: = 
SUM( Sales[Sales] )

 

monthly rolling average: = 
AVERAGEX (
    VALUES ( 'Calendar'[Year-Month sort] ),
    CALCULATE ( SUM ( Sales[Sales] ) )
)

 

_12months rolling average: = 
VAR _selectedmaxdateslicer =
    MAX ( 'Calendar'[Date] )
VAR _t =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= EOMONTH ( _selectedmaxdateslicer, 0 )
                && 'Calendar'[Date]
                    >= EOMONTH ( _selectedmaxdateslicer, -12 ) + 1
        ),
        'Calendar'[Year-Month sort]
    )
RETURN
    AVERAGEX ( _t, CALCULATE ( SUM ( Sales[Sales] ) ) )

 

sum of 12months rolling avg: = 
SUMX ( VALUES ( 'Calendar'[Year-Month sort] ), [_12months rolling average:] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
bbui11
Frequent Visitor

Awesome! Yes, this is the proof of concept I was looking for. Thank you so much!

Jihwan_Kim
Super User
Super User

Hi, 

I am not sure if I understand your question correctly, but I tried to create a sample pbix file like below.

please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1698814052127.png

 

 

Sales total: = 
SUM( Sales[Sales] )

 

monthly rolling average: = 
AVERAGEX (
    VALUES ( 'Calendar'[Year-Month sort] ),
    CALCULATE ( SUM ( Sales[Sales] ) )
)

 

_12months rolling average: = 
VAR _selectedmaxdateslicer =
    MAX ( 'Calendar'[Date] )
VAR _t =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= EOMONTH ( _selectedmaxdateslicer, 0 )
                && 'Calendar'[Date]
                    >= EOMONTH ( _selectedmaxdateslicer, -12 ) + 1
        ),
        'Calendar'[Year-Month sort]
    )
RETURN
    AVERAGEX ( _t, CALCULATE ( SUM ( Sales[Sales] ) ) )

 

sum of 12months rolling avg: = 
SUMX ( VALUES ( 'Calendar'[Year-Month sort] ), [_12months rolling average:] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi,

 

Quick follow up question. For the "_12 months rolling average" calculation, if I wanted to include the entire dataset in the scope of the 12 month rolling average calculation, what would be the best adjustment to the measure?

Ex. With the date slicer set to 1/1/2022 -1/31/2022, the current "_12 months rolling average" measure would be equal to the total sales in january 2022, but I would want the _12 months rolling average" calculation to consider the sales for 2/1/2021 - 1/31/2022.

Thanks in advance!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.