Forum Discussion

AnF0's avatar
AnF0
New Member
1 year ago
Solved

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.

  • 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] )
    

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

6 Replies

  • 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
        )
    )

     

     

  • Ashish_Excel's avatar
    Ashish_Excel
    Icon for Solution Supplier rankSolution Supplier

    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.

  • 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] )
    

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.