Forum Discussion

jlf81's avatar
jlf81
Frequent Visitor
5 years ago

Current vs Previous based on relative filter

Is there anyway to build a measure that would give you the current period vs the previous period, based on a relative filter. 

 

For eaxmple if the filter is set to last 30 days it would show the last 30 days minus days 31-60, a separate measure that just shows days 31-60

 

Then if you changed the relative filter to last 60, it would show it minus days 61-120, a separate measure that just shows days 61-120

 

If it's not possible with just 2 measures is there a neat way so I can have a number of different similar measures and use bookmarks to change the view of it?

 

4 Replies

  • jlf81 , Try a measure like

     

    Last Period =
    var _max =maxx(date,date[date])
    var _min =maxx(date,date[date])
    var datediff1 = datediff(_min,_max,day)
    var _maxX = _max-datediff1
    var _minX = _min -datediff1
    return
    CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

  • jlf81's avatar
    jlf81
    Frequent Visitor

    amitchandak Awesome, thank you.

     

    Is there any way to edit that to deal with YTD\MTD? or would I need to adjust that measure

     

    Little typo in you solution 'var _min =maxx(date,date[date])' should be 'var _min =minx(date,date[date])' shouldn't it? Also couldn't get that last bit to work, but replaced it with ,DATESBETWEEN('Dim Date'[Date],_minX,_maxX))) and that seems ok

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jlf81,

    Any update on your scenario? You only shared less information so that we not clarify your structure and do the test with them.

    Regards,

    Xiaoxin Sheng