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
yybi123
Helper I
Helper I

DAX to count 12 Months Sum

Hi All,

 

How can I get the total of 12 Months Volume including current month?
For example, the value required at Jan 2020 will be (sum of Feb-19 to Jan 2020)=33

 

MonthVolumeValue Required
Jan-191 
Feb-192 
Mar-191 
Apr-192 
May-192 
Jun-193 
Jul-194 
Aug-195 
Sep-196 
Oct-194 
Nov-192 
Dec-191 
Jan-20133
Feb-20233
Mar-20335
Apr-20134

 

Thanks!

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@yybi123 Try:

Measure = 
  VAR __Max = MAX('Table'[Month])
  VAR __Min = EOMONTH(__Max,-12)+1
RETURN
  SUMX(FILTER(ALL('Table'),[Month]>=__Min && [Month]<=__Max),[Volumn])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
yybi123
Helper I
Helper I

Thanks @Greg_Deckler  , it works.

How can I then display the calculated measure in a line graph that only show last 12 months on X-Axis? I tried filter the visual with relative date for Month in last 12 months then it affected the calculated measure value.

For example, the calculated measure number for Jan 2020 is 33 but when I applied the visual filter, the value will be changed.



@amitchandak , i tried your measure but it only gives me the value of the month. Ie Jan 2020 will be 1 it does not sum up from Feb2019 to Jan2020 value.

amitchandak
Super User
Super User

@yybi123 , with a date table.

 

example

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

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
Greg_Deckler
Community Champion
Community Champion

@yybi123 Try:

Measure = 
  VAR __Max = MAX('Table'[Month])
  VAR __Min = EOMONTH(__Max,-12)+1
RETURN
  SUMX(FILTER(ALL('Table'),[Month]>=__Min && [Month]<=__Max),[Volumn])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.