Forum Discussion

amirabedhiafi's avatar
amirabedhiafi
Impactful Individual
5 years ago
Solved

Trend calculation dynamically

I have this model :      I have the following measure :  LastNWeeks = CALCULATE(SUM('COVID Data'[COVID Cases]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-WeekRank[WeekRa...
  • v-janeyg-msft's avatar
    5 years ago

    Hi, amirabedhiafi 

     

    According to your description, I think you can create another measure to display ‘the N weeks prior to the Last N weeks’, so you can use one slicer to get data from two different time periods.

    Like this:

    Last2NWeeks-LastNWeeks =
    VAR LastNWeeks =
        CALCULATE (
            SUM ( 'COVID Data'[COVID Cases] ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Week Rank]
                    >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value]
                    && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] )
            )
        )
    VAR Last2NWeeks =
        CALCULATE (
            SUM ( 'COVID Data'[COVID Cases] ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Week Rank]
                    >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value] * 2
                    && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] )
            )
        )
    RETURN
        Last2NWeeks - LastNWeeks

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.