Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello Expert,
I want to create a measure that compare dynamic date range . For example:
Scenario 1: if user selects randomly 14th - 16th sept. So it should calculate data from 7th - 9th sept of last week. like this in given image.
Scenario 2: If user select 1st - 30th sept , It should calculate previous month 1st - 31th Aug.
Please help me to find dynamic solution to this problem.
Thanks you in advance.
Solved! Go to Solution.
@Uzi2019 Try this DAX:
First create a measure to get the no. of days between date range:
No.ofDay = DATEDIFF(MIN(Date),MAX(Date),DAY)+1
Then create a measure which will get the sales value of prev selected days:
Prev Days Sales = CALCULATE([Sales], DATEADD(Date[Date], - [No.ofDay], DAY)
For Scenario 1, you can use the following measure in DAX:
This will calculate the sum of "Value" for the selected date range (14th-16th Sept) by using DATESBETWEEN function with a date range starting 7 days before the selected start date and ending 7 days before the selected end date.
For Scenario 2, you can use the following measure in DAX:
This will calculate the sum of "Value" for the selected date range (1st-30th Sept) by using DATESBETWEEN function with a date range starting from the first day of the previous month and ending on the last day of the previous month.
Note: In both scenarios, replace "Table" with the name of your table and "Value" with the name of your column that you want to aggregate.
This solution would not work for me.
I need one measure which dynamically calculate same previous period as per date range selected by user.
Date range can be 7 days , 3 days, 21 days or 1 month etc in same date range filter. So previous period measure should calculate as per date selection made by user.
@Uzi2019 Try this DAX:
First create a measure to get the no. of days between date range:
No.ofDay = DATEDIFF(MIN(Date),MAX(Date),DAY)+1
Then create a measure which will get the sales value of prev selected days:
Prev Days Sales = CALCULATE([Sales], DATEADD(Date[Date], - [No.ofDay], DAY)
Hey @Tahreem24
Thanks alot. It actually kinda work for me.