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! Request now

Reply
ariana_night
Frequent Visitor

Total average of last 12 months

I've been trying to get the right measure for what I am looking for with no luck.

When I bring in Report Date and Sum of Gross Dollars, I am simply trying to get the total average ($4,346,951) into a card visual, like I see in Excel when I export the data:

ariana_night_0-1722007921510.png

 

I've tried this DAX but get a total of $4,358,088 (close but no match)

 

 

12mthavginv =
VAR CurrentDate = MAX('Inventory Provision'[ReportDate])
VAR StartDate = EOMONTH(CurrentDate, -12) + 1
VAR mthstart = MONTH(StartDate)
var result = CALCULATE(
    SUM('Inventory Provision'[GrossDollars]), REMOVEFILTERS('Calendar'),
    'Calendar'[Date]>= StartDate, 'Calendar'[Date] <= CurrentDate)
RETURN
DIVIDE(result,12)

 

 

The goal is to get the total of the last 12 months for each report date i.e. if I filter the report to May 2024, I should see the 12 month average for the last 12 months from that current date. If I filter to June 2024, then last 12 months from that current date and so on and so forth. 

 

My report is filtered to May 2024, and I should see $4,346,951 in the below visual where it is highlighted.

ariana_night_1-1722008223089.png

 

2 REPLIES 2
MalkhazTsagarel
Regular Visitor

Hello, 
This code is dynamic, so if the last 12 months are not in our data,it will use minimum date in our data.
for example if we select  01.09.2023(september 1st), we wont have all 12 months before in our data,
so it will calculate average of last available data before 01.09.2023:
AVG=

VAR CurrentDate = MAX('Inventory Provision'[ReportDate])
VAR StartDate = IF(EOMONTH(CurrentDate, -12) + 1<MINX(ALL('Calendar'[reporting date]),'Calendar'[reporting date]),MINX(ALL('Calendar'[reporting date]),'Calendar'[reporting date]),EOMONTH(CurrentDate, -12) + 1)
VAR mthstart = MONTH(StartDate)
var result = CALCULATE(
    SUM('Inventory Provision'[GrossDollars]), REMOVEFILTERS('Calendar'),
    'Calendar'[Date]>= StartDate, 'Calendar'[Date] <= CurrentDate)
RETURN
DIVIDE(result,
COUNTROWS(DISTINCT(SELECTCOLUMNS(
        CALENDAR(StartDate, CurrentDate),
        "MonthNumber", MONTH([Date])))
This is calendar calculation:
Calendar = addcolumns(calendar(MIN('Inventory Provision'[ReportDate]),MAX('Inventory Provision'[ReportDate])),"reporting date",eomonth([Date],-1)+1).
@ariana_night  If it works please make it as solution
MalkhazTsagarel_0-1722190881041.png

 



DataNinja777
Super User
Super User

Hi @ariana_night 

I just copied and pasted your dax formula in Power BI and it was producing your required output as shown below:

DataNinja777_0-1722174071620.png

I attach the pbix file with the data model. 

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.