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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating for the past twelve month and twelve-month period one year ago

Hey as you can see from bottom picture I manage to get a 12 month period of date in the past 12 months. This was done by using Power Bi own relative data filter, also tried using Dax but this was faster. One issue now is that I wanted to have another 12-month period, but just started from 2 years ago, so in this case "2018", and then 12 months forward from there. This means that the measures would meet in the middle. I have posted another picture of my issue when I wanted to use the relative date just started from 2018 and forward. As you can see it also count the 12 month period from 2019 to 2020.

It should have been from 2018 to 2019 (12 months) & 2019 to 2020 (12 months). I don't want to just filter out the year by selecting because this would mean that every year I have to readjust it so next year it will be 2019 to 2020 and 2020 to 2021. Would really enjoy a solution where it automatically readjusts itself, when we went into the next calendar year. Kindly regards Martin 2018 date filter.PNGfrom 2018 and forward.PNGPast 12 month date filter.PNGPast 12 month (12 month period).PNG

 
1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First you need to create a slicer table using a dax expression as below:

 

SlicerTable = GENERATESERIES(0,12,1)

 

Then you need a measure as below:

 

 

Measure = var a = YEAR(TODAY())-SELECTEDVALUE(SlicerTable[InLastYear]) 
return CALCULATE(SUM('Table'[Value]),FILTER('Table',YEAR('Table'[Date])<a),ALLSELECTED('Table'))

 

 

Finally you will see:

 

20.png

 For the relatede .pbix file,pls click here.

 

Best Regards,
Kelly

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First you need to create a slicer table using a dax expression as below:

 

SlicerTable = GENERATESERIES(0,12,1)

 

Then you need a measure as below:

 

 

Measure = var a = YEAR(TODAY())-SELECTEDVALUE(SlicerTable[InLastYear]) 
return CALCULATE(SUM('Table'[Value]),FILTER('Table',YEAR('Table'[Date])<a),ALLSELECTED('Table'))

 

 

Finally you will see:

 

20.png

 For the relatede .pbix file,pls click here.

 

Best Regards,
Kelly

Anonymous
Not applicable

Hello @Anonymous 

Here is a simple Measure that I ussualy use to set the charts dynamically based on todays date.

This should work for you aswell:

Sales Previous 12 months = 
var MinDate = TODAY()-365
return
CALCULATE([Total Sales];FILTER(FactTable;RELATED(MasterCalendar[Date])>=MinDate))

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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