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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
AnF0
New Member

Calculate Percentage Change With a Relative Date Slicer

I'm looking for a way to have a card visual show a percentage change but have it adjust with a relative date slicer applied to the page. I have seen previous measures for date range slicers but have not been able to find or get a measure that incorporates a relative date slicer. Essentially I want to be able to enter anything like last 7 days or last 90 days in the slicer and have the percentage change for the number of cases from that selected date range compared to the current date update. None of the previous measures I have tried have yielded anything useful, so an example would be greatly appreciated.

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @AnF0 

 

Create a numeric range parameter table. Assuming the name of the table created is LastXDays, the name of the automatically crate measure is also the same, create these measures. 

Last X Days = 
VAR _MaxDate =
    CALCULATE ( MAX ( Dates[Date] ), ALLSELECTED ( Dates ) )
VAR _StartDate = _MaxDate - [LastXDays Value] + 1
RETURN
    CALCULATE (
        [Total Revenue],
        KEEPFILTERS ( Dates[Date] >= _StartDate && Dates[Date] <= _MaxDate )
    )

Last X Days Prior = 
VAR _MaxDate =
    CALCULATE ( MAX ( Dates[Date] ), ALLSELECTED ( Dates ) )
VAR _EndDate = _MaxDate - [LastXDays Value] - 1
VAR _StartDate = _EndDate - [LastXDays Value] + 1
RETURN
    CALCULATE (
        [Total Revenue],
        KEEPFILTERS ( Dates[Date] >= _StartDate && Dates[Date] <= _EndDate )
    )

Last X Days Variance = 
[Last X Days] - [Last X Days Prior]

Last X Days Delta = 
DIVIDE ( [Last X Days Variance], [Last X Days Prior] )

danextian_0-1746882468719.png

Note: In the above example, the _MaxDate  is is the max of all the visible Dates[Date] rows. Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

6 REPLIES 6
v-priyankata
Community Support
Community Support

Hi @AnF0 
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

v-priyankata
Community Support
Community Support

Hi @AnF0 
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

v-priyankata
Community Support
Community Support

Hi @AnF0 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

danextian
Super User
Super User

Hi @AnF0 

 

Create a numeric range parameter table. Assuming the name of the table created is LastXDays, the name of the automatically crate measure is also the same, create these measures. 

Last X Days = 
VAR _MaxDate =
    CALCULATE ( MAX ( Dates[Date] ), ALLSELECTED ( Dates ) )
VAR _StartDate = _MaxDate - [LastXDays Value] + 1
RETURN
    CALCULATE (
        [Total Revenue],
        KEEPFILTERS ( Dates[Date] >= _StartDate && Dates[Date] <= _MaxDate )
    )

Last X Days Prior = 
VAR _MaxDate =
    CALCULATE ( MAX ( Dates[Date] ), ALLSELECTED ( Dates ) )
VAR _EndDate = _MaxDate - [LastXDays Value] - 1
VAR _StartDate = _EndDate - [LastXDays Value] + 1
RETURN
    CALCULATE (
        [Total Revenue],
        KEEPFILTERS ( Dates[Date] >= _StartDate && Dates[Date] <= _EndDate )
    )

Last X Days Variance = 
[Last X Days] - [Last X Days Prior]

Last X Days Delta = 
DIVIDE ( [Last X Days Variance], [Last X Days Prior] )

danextian_0-1746882468719.png

Note: In the above example, the _MaxDate  is is the max of all the visible Dates[Date] rows. Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ashish_Excel
Super User
Super User

Hi,

Share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.

techies
Super User
Super User

Hi @AnF0 please try this for the previous period measure

 

SelectedDays =
DATEDIFF(MIN('Date'[Date]), MAX('Date'[Date]), DAY) + 1
 
Cases_PreviousPeriod =
VAR MinDateVisible = MIN('Date'[Date])
VAR DaysSelected = [SelectedDays]
VAR PrevPeriod =
    DATESINPERIOD('Date'[Date], MinDateVisible - 1, -DaysSelected, DAY)
RETURN
CALCULATE(
    COUNTROWS('cases'),
    REMOVEFILTERS('Date'),
    FILTER(
        ALL('Date'),
        'Date'[Date] IN PrevPeriod
    )
)

 

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.