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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Infijeevan
Frequent Visitor

From Selected Month Previous 12 Months Values

Hi Friends,

 

I am facing issue in one of my report. I have 3 tables

Fact Incident Table

Fact Hour Table

Dim Date Table

 

Incident Table

DateIncidents
27-Jun-202175
01-Jun-202145
23-Jan-202185
20-Jan-202277
27-Mar-202154
01-Feb-202194
19-Jun-202079
16-Nov-202086
29-Sep-202182
11-Nov-202165

 

Hour Table

DateHours
29-Jun-20211200
10-Jun-20213221
23-Jan-20211319
20-Jan-20221473
27-Mar-20211224
01-Feb-20211144
19-Jun-20201177
16-Nov-20201144
29-Sep-20211198
11-Nov-20211005

 

And we have convetional DATE table as usual.

 

Now i want to create a calculation which shows data for previous 12 months from the selected month.

For an example, i have a month slicer from DATE table and lets say if i select Nov 2021 it has to show the data for previous 12 months including Nov 2021 i.e. from Dec 2020 to Nov 2021 and Result should be like the below.

 

MonthIncidentsHours
Dec-20               -                -  
Jan-21              85       1,319
Feb-21              94       1,144
Mar-21              54       1,224
Apr-21               -                -  
May-21               -                -  
Jun-21            120       4,421
Jul-21               -                -  
Aug-21               -                -  
Sep-21              82       1,198
Oct-21               -                -  
Nov-21              65       1,005

 

Please help me on this

@amitchandak @Greg_Deckler @diex @aj1973 @BA_Pete @Jihwan_Kim 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Picture1.png

 

Incidents: =
VAR slicerselect =
MAX ( Slicer_Dates[Date] )
VAR before12months = DATE( YEAR(slicerselect)-1, MONTH(slicerselect), DAY(slicerselect))
VAR datesperiod12months =
DATESBETWEEN ( Dates[Date], before12months+1, slicerselect )
RETURN
CALCULATE (
SUM ( Incident[Incidents] ),
KEEPFILTERS ( DATESBETWEEN ( Dates[Date], before12months, slicerselect ) )
)

 

 

Hours: =
VAR slicerselect =
MAX ( Slicer_Dates[Date] )
VAR before12months = DATE( YEAR(slicerselect)-1, MONTH(slicerselect), DAY(slicerselect))
VAR datesperiod12months =
DATESBETWEEN ( Dates[Date], before12months+1, slicerselect )
RETURN
CALCULATE (
SUM ( 'Hour'[Hours] ),
KEEPFILTERS ( DATESBETWEEN ( Dates[Date], before12months, slicerselect ) )
)
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Picture1.png

 

Incidents: =
VAR slicerselect =
MAX ( Slicer_Dates[Date] )
VAR before12months = DATE( YEAR(slicerselect)-1, MONTH(slicerselect), DAY(slicerselect))
VAR datesperiod12months =
DATESBETWEEN ( Dates[Date], before12months+1, slicerselect )
RETURN
CALCULATE (
SUM ( Incident[Incidents] ),
KEEPFILTERS ( DATESBETWEEN ( Dates[Date], before12months, slicerselect ) )
)

 

 

Hours: =
VAR slicerselect =
MAX ( Slicer_Dates[Date] )
VAR before12months = DATE( YEAR(slicerselect)-1, MONTH(slicerselect), DAY(slicerselect))
VAR datesperiod12months =
DATESBETWEEN ( Dates[Date], before12months+1, slicerselect )
RETURN
CALCULATE (
SUM ( 'Hour'[Hours] ),
KEEPFILTERS ( DATESBETWEEN ( Dates[Date], before12months, slicerselect ) )
)
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thanks @Jihwan_Kim it is working perfectly for me.

 

Thank you very much for coming up with sample file.

amitchandak
Super User
Super User

@Infijeevan , when you select a month to want to display 12 months then you need an independent date table. But if need only total of 12 months you can use rolling

 

example

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

 

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = eomonth(today(),-12)+1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

 

refer video for diff

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

 

Thanks for the reply, but i am getting different result like for all the months i am getting same result from Hrs table.

It would be great if you can share the sample PBI file here.

 

Thanks in advance

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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