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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
prv_1401
Helper I
Helper I

Dax measure to get previous 7days and next 7days of selected date

Hey guys !

 I am very new to PowerBI. Could you suggest me the Dax functions or the syntax with any examples to solve this issue .

 

I have to show a line chart visual which shows the previous 7days value and after 7days value of a selected date . So if I select a particular date the measure should filter the visual according to it and show according to the requirement .

 

Appreciate any help. Thank you ♥️

1 ACCEPTED SOLUTION
PaulOlding
Solution Sage
Solution Sage

Hi @prv_1401 

This solution uses a disconnected date table called 'Date Selector' (meaning it's a date table without any relationship to another table).  The slicer should use this table.

7and7 = 
VAR _SelectedDate = SELECTEDVALUE('Date Selector'[Date])
VAR _Dates = DATESBETWEEN('Date'[Date], _SelectedDate - 7, _SelectedDate + 7)
VAR _Result =
CALCULATE(
    [Total Sales],
    KEEPFILTERS(_Dates)
    )
RETURN
    _Result

 

PaulOlding_0-1662410077765.png

The line chart uses the Date column from the Date table.

PaulOlding_1-1662410097109.png

 

View solution in original post

4 REPLIES 4
PaulOlding
Solution Sage
Solution Sage

Hi @prv_1401 

This solution uses a disconnected date table called 'Date Selector' (meaning it's a date table without any relationship to another table).  The slicer should use this table.

7and7 = 
VAR _SelectedDate = SELECTEDVALUE('Date Selector'[Date])
VAR _Dates = DATESBETWEEN('Date'[Date], _SelectedDate - 7, _SelectedDate + 7)
VAR _Result =
CALCULATE(
    [Total Sales],
    KEEPFILTERS(_Dates)
    )
RETURN
    _Result

 

PaulOlding_0-1662410077765.png

The line chart uses the Date column from the Date table.

PaulOlding_1-1662410097109.png

 

Hi ..Thank you for replying 
what if the sales value in the table is percentage % ??
So for instance sales % for eachdate is given. You have mentioned there in dax [total sales] Is that a measure you created? .
In case of % how should I deal with it ?
@PaulOlding 

@prv_1401 

Yes, [Total Sales] is a measure.  You can replace it with any measure and the pattern should work, so one that returns a %age will be fine.

daXtreme
Solution Sage
Solution Sage

If you're very new to Power BI, I would then kindly suggest you should learn a bit about the philosophy of PBI because what you want to do is not the easiest thing under the sun. Here's an example of what you'd need to , more or less, implement: Show last 6 months based on user single slicer selection (youtube.com)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.