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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Roy_tap
Helper I
Helper I

How to get a fixed period (previous N and Next N period) of value based on a single period selection

Hi,

I have 2 tables, one is period table and one is fact table with period

Period table contains Period column
2023.01 - 2024.12

Fact table contains the following
Period      Value
2023.09       3
2023.10       2
2023.11       4
2023.12       7
2024.01       5
2024.02       3
2024.03       2
2024.04       7
2024.05       6
2024.06       2

In my report, I have a Period Slicer (can be from Period table or Fact table) which can only single select a Period e.g. 2024.03

How can i get a line chart that will display a fixed Last 5 period and Next 2 period value i.e. 2023.10 - 2024.05? 
When i select 2024.04, it will display the period from 2023.11 - 2024.06.

Thanks

1 ACCEPTED SOLUTION
qqqqqwwwweeerrr
Super User
Super User

Hi @Roy_tap 

 

This can be achived by creating follwoing measure it is just one thing i taken date format little different i guess which should not be an issue here is my approahc to get the required things 
this measure needs to be created in your period table 

Value in certain period =
 var maxdate = MAX(Period[Period])
 var nexttwomonth = EOMONTH(maxdate,+2)
 var previousfourmonths = EOMONTH(maxdate,-6)
 var resulst =
               CALCULATE(SUM('Fact'[Values]),
                                         FILTER('Fact','Fact'[Period] >= previousfourmonths && 'Fact'[Period]<= nexttwomonth))
    RETURN resulst
Now in filter use the period from period table 
if you use this confreguration, with little change you should get the desired output
qqqqqwwwweeerrr_0-1712649028024.png

Here is another way of solving the same problem : https://youtu.be/uQPXYW79m3A?si=KmXniEIVGNy4KHzC

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Check for more intersing solution here: www.youtube.com/@Howtosolveprobem

Regards

View solution in original post

1 REPLY 1
qqqqqwwwweeerrr
Super User
Super User

Hi @Roy_tap 

 

This can be achived by creating follwoing measure it is just one thing i taken date format little different i guess which should not be an issue here is my approahc to get the required things 
this measure needs to be created in your period table 

Value in certain period =
 var maxdate = MAX(Period[Period])
 var nexttwomonth = EOMONTH(maxdate,+2)
 var previousfourmonths = EOMONTH(maxdate,-6)
 var resulst =
               CALCULATE(SUM('Fact'[Values]),
                                         FILTER('Fact','Fact'[Period] >= previousfourmonths && 'Fact'[Period]<= nexttwomonth))
    RETURN resulst
Now in filter use the period from period table 
if you use this confreguration, with little change you should get the desired output
qqqqqwwwweeerrr_0-1712649028024.png

Here is another way of solving the same problem : https://youtu.be/uQPXYW79m3A?si=KmXniEIVGNy4KHzC

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Check for more intersing solution here: www.youtube.com/@Howtosolveprobem

Regards

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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