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
lovekheart
Regular Visitor

Create a Matrix that has 3,6,12 month averages of measures

lovekheart_0-1750877729801.png

This picture showcases the end goal (sorry i dont have a better example) that i am trying to acheive. I do have a calender table and all the measures but cant seem to find how to achieve this for the matrix visual. Please reach out with any knowldege on this!

1 ACCEPTED SOLUTION

No worries, here's a sample PBIX.

The exact definitions of your measures shouldn't matter as long as they are explicit measures (which it sounds like they are) and respond correctly to 'Date' filters.

 

I've created two calculation groups in my sample PBIX:

  • Monthly Averages relative to Filtered Date
    Computes monthly averages relative to the max date filtered.
  • Monthly Averages relative to Current Month
    Computes monthly averages relative to the "current date" as returned by the TODAY ( ) function.

The calculation item expressions differ only in how they define the "reference date". I've also added variables for readability.

 

Sample calculation items:

------------------------------------------------------------------
-- Calculation Group: 'Monthly Averages relative to Current Month'
------------------------------------------------------------------
Last 12 Months = 
VAR ReferenceDate = EOMONTH ( TODAY ( ), 0 )
VAR NumMonths = 12
RETURN
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[Year Month] ),
            SELECTEDMEASURE ( )
        ),
        DATESINPERIOD ( 'Date'[Date], ReferenceDate, -NumMonths, MONTH )
    )

 

------------------------------------------------------------------
-- Calculation Group: 'Monthly Averages relative to Filtered Date'
------------------------------------------------------------------
Last 12 Months = 
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR NumMonths = 12
RETURN
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[Year Month] ),
            SELECTEDMEASURE ( )
        ),
        DATESINPERIOD ( 'Date'[Date], ReferenceDate, -NumMonths, MONTH )
    )

OwenAuger_0-1750996244132.png

 

 

Are you able to get something similar working?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

5 REPLIES 5
v-pgoloju
Community Support
Community Support

Hi @lovekheart,

 

Thank you for reaching out to the Microsoft Fabric Forum Community.

 

Try modifying the dax measure below

Measure = AVERAGEX (VALUES ( 'Date'[YearMonth] ),DIVIDE ( [Measure 5], [Measure 2], 0 ) * 100)


Best regards,
Prasanna Kumar

 

OwenAuger
Super User
Super User

Hi @lovekheart 

I would recommend a calculation group containing calculation items for each of the average calculations.

https://learn.microsoft.com/en-us/power-bi/transform-model/calculation-groups

 

Each calculation item's expression should contain SELECTEDMEASURE ( ) as a placholder for the measure it will be applied to.

For example, if your averages are defined as arithmetic means of monthly measure values for the last N months (as at the max date filtered), you might use this calculation item expression for "Last 3 months":

CALCULATE (
    AVERAGEX (
        VALUES ( 'Date'[Year Month] ), -- or column with month/year granularity
        SELECTEDMEASURE ( )
    ),
    DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH )
)

 

You could then construct the matrix with:

Is that enough to go on?

I could create a small example to demonstrate the setup if that would be useful.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

@OwenAugerHi thank you for this. I am still a bit confused (maybe sample will help more). I created the calculation group and by itself on the matrix  it pops up correctly before adding values. I changed the values in rows, but my chart is just blank and changes to show "calculation group column" instead of "Last 3 Months"...
I'm guessing my measures arent created properly for example all of them are in this similar example
measure = divide([measure 5],[measure 2],0) * 100

No worries, here's a sample PBIX.

The exact definitions of your measures shouldn't matter as long as they are explicit measures (which it sounds like they are) and respond correctly to 'Date' filters.

 

I've created two calculation groups in my sample PBIX:

  • Monthly Averages relative to Filtered Date
    Computes monthly averages relative to the max date filtered.
  • Monthly Averages relative to Current Month
    Computes monthly averages relative to the "current date" as returned by the TODAY ( ) function.

The calculation item expressions differ only in how they define the "reference date". I've also added variables for readability.

 

Sample calculation items:

------------------------------------------------------------------
-- Calculation Group: 'Monthly Averages relative to Current Month'
------------------------------------------------------------------
Last 12 Months = 
VAR ReferenceDate = EOMONTH ( TODAY ( ), 0 )
VAR NumMonths = 12
RETURN
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[Year Month] ),
            SELECTEDMEASURE ( )
        ),
        DATESINPERIOD ( 'Date'[Date], ReferenceDate, -NumMonths, MONTH )
    )

 

------------------------------------------------------------------
-- Calculation Group: 'Monthly Averages relative to Filtered Date'
------------------------------------------------------------------
Last 12 Months = 
VAR ReferenceDate = MAX ( 'Date'[Date] )
VAR NumMonths = 12
RETURN
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Date'[Year Month] ),
            SELECTEDMEASURE ( )
        ),
        DATESINPERIOD ( 'Date'[Date], ReferenceDate, -NumMonths, MONTH )
    )

OwenAuger_0-1750996244132.png

 

 

Are you able to get something similar working?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

This works perfect thank you for all you help!

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.