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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Noeleke1301
Helper III
Helper III

Show N last periods in line chart

Hi all,

I want to dynamically show the N last periods in a line chart. I've read the SQLBI article, but that works with months and the DATESINPERIOD formule, which I cannot use because I use custom ISO periods.

 

Please help, I'm trying to use an offset column in my date table, which is set to 0 on the current period and counts back in the past. So 3 periods ago has offset -3

 

My current formula:

 

On time performance trend =
VAR _LastPeriodWithData = CALCULATE( MAX( dimDate[Period Offset] ) , FILTER( dimDate , dimDate[Date] <= MAX( trips[Date] ) ) )
return

CALCULATE( [ON TIME PERFORMANCE] , FILTER( dimDate , dimDate[Period Offset] >=  _LastPeriodWithData -3 && dimDate[Period Offset] <=  _LastPeriodWithData ) )
 

But this still shows everything in the chart, not just the last 3 periods. How do I correct this?

Noeleke1301_0-1678265982164.png

 

There is a single relationship between dimDate[Date] and trips[Date]

 

2 REPLIES 2
amitchandak
Super User
Super User

@Chaithanya6 , refer if these two from guyinacube can help

https://www.youtube.com/watch?v=EZifdFfjTNg

https://www.youtube.com/watch?v=v79MjJZoIZg

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

@Noeleke1301 , Try with this one change in var

VAR _LastPeriodWithData = CALCULATE( MAX( dimDate[Period Offset] ) , FILTER( allselected(dimDate) , dimDate[Date] <= MAX( trips[Date] ) ) )

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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