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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Henault
New Member

Line Chart for Trailing 12 month sales Limited to a certain number of years

Hello,

 

I'm looking to improve the reporting and user experience in my organization through Power BI. Part of this process is to replicate one of our manual Excel based reports in the Power BI environment with the goal of adding additional functionality such as drill down capabilities as a demonstration of whats possible.

 

I'd like assistance creating a graph that will show me trailing 12 month sales over a 3 year look back period.  I would like the visual to automatically update the display to show the most recent year of data in my fact table and display an additional 2 full years prior to that (i.e. max year in my table is 2022) so I would like the trailing twelve months to display from January 1, 2019 through current date in 2022.  I have many years of data in my table so the January 1, 2019 displayed start date in my graph should already be the calculated trailing twelve months from January 2nd 2018.    Ideally, it like to handle this in DAX and not have to select values from a visual filter.

 

Below is the code I was able to work through mostly as a proof to myself that trailing twelve months is possible but its only a starting point as I work my way through this learning experience.  I appreciate the assistance.

 

TTM NetIncome =
 
var StartDay = lastdate(
DATEADD('Calendar'[Date], -11,MONTH)
)

var EndDay = LASTDATE('Calendar'[Date])

Return

CALCULATE([Net Income]DATESBETWEEN('Calendar'[Date]StartDay, EndDay ))

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

See if my solution here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

See if my solution here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Henault , Try like

 

Rolling 12 Sales =
var _max = maxx(allselcted(date),date[date]) // or today()
var _min = date(year(_max), month(_max)-12,1)
return
CALCULATE(SUM(Sales[Sales Amount]),filter(date, date[date] <=_max && date[date] >=_min))

 

 

or

 

Rolling 12 Sales =
var _max = maxx(allselcted(date),date[date]) // or today()
var _min = date(year(_max), month(_max)-12,day(_max))
return
CALCULATE(SUM(Sales[Sales Amount]),filter(date, date[date] <=_max && date[date] >=_min))

 

or

 

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.