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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
EP1
Advocate IV
Advocate IV

Graph showing 6 weeks before and after date range

I am trying to create a graph in PowerBi Desktop that allows the user to select a period using two dates and then shows data for 6 weeks before and 6 weeks after that period as per the below graph. Is there anyway to do this in PowerBi?

 

I thought of using a filtered table, but obviously that won't work, since filtered tables are not dynamic. I think that I need some way of creating a measure that ignores external filters (the slicer) but keeps internal filters (the date axis) and also filters to the date range.

 

I got as far as getting a total for the period before (and, by the same logic the period after) but the measure ignores the interal filters (date axis) and I am not sure how to continue from here (I can't find an ALL function that would keep internal filters).

 

measure = 
var min_date = DATEADD(FIRSTDATE(ALLSELECTED('Date'[Date])),-1,DAY)
return CALCULATE([value],ALL('Date'),DATESINPERIOD('Date'[Date],min_date,-42,day))

 

I've experimented with using a second date column in the date table but I haven't managed to get that to work. I also experimented with using the date column from the data table as the slicer and trying to selectively ignore filters but that doesn't work either.

 

Capture.PNG

1 ACCEPTED SOLUTION
EP1
Advocate IV
Advocate IV

OK, so I managed to solve this problem by using an independent date table and creating 2 measures:

 

period_value = 
var min_date = FIRSTDATE(ALLSELECTED('Date2'[Date]))
var max_date = LASTDATE(ALLSELECTED('Date2'[Date]))
return IF(AND(min_date<=MAX('Date'[Date]),max_date>=MAX('Date'[Date])),[value],0)

 

6wks_before_and_after = 
var min_date = FIRSTDATE(ALLSELECTED('Date2'[Date]))
var max_date = LASTDATE(ALLSELECTED('Date2'[Date]))
return IF(OR(AND(min_date>MAX('Date'[Date]),DATEADD(min_date,-42,DAY)<=MAX('Date'[Date])),
AND(max_date<MAX('Date'[Date]),DATEADD(max_date,42,DAY)=>MAX('Date'[Date]))),
[total_sales_qty],0)

 

These measures are for graphing purposes only. Not sure if anyone has a simpler solution?

View solution in original post

2 REPLIES 2
v_mark
Helper V
Helper V

@EP1 - Is there a way to use the Date coming from the original/non independent date table? 


EP1
Advocate IV
Advocate IV

OK, so I managed to solve this problem by using an independent date table and creating 2 measures:

 

period_value = 
var min_date = FIRSTDATE(ALLSELECTED('Date2'[Date]))
var max_date = LASTDATE(ALLSELECTED('Date2'[Date]))
return IF(AND(min_date<=MAX('Date'[Date]),max_date>=MAX('Date'[Date])),[value],0)

 

6wks_before_and_after = 
var min_date = FIRSTDATE(ALLSELECTED('Date2'[Date]))
var max_date = LASTDATE(ALLSELECTED('Date2'[Date]))
return IF(OR(AND(min_date>MAX('Date'[Date]),DATEADD(min_date,-42,DAY)<=MAX('Date'[Date])),
AND(max_date<MAX('Date'[Date]),DATEADD(max_date,42,DAY)=>MAX('Date'[Date]))),
[total_sales_qty],0)

 

These measures are for graphing purposes only. Not sure if anyone has a simpler solution?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors