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[WeekRank Value] && 'Date'[Week Rank]<=max('Date'[Week Rank])))
 
Which calculates the Last N Weeks Covid cases excluding the current week. The numbers should change dynamically with the What-if-Parameters selection. The parameter starting from 2 and increasing incrementally by 1 till 28 weeks
Which I use it like below : 
 

I want to alculate the Trend %. The trend % is calculated by comparing the Last N weeks with the N weeks prior to the Last N weeks Covid cases. For example, if week # 8 & week 9 are the Last N Weeks then it should be compared with the week # 6 & week # 7 dynamically.

amitchandak 

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

2 Replies

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Community Support

    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.