Search code examples
powerbidaxpowerbi-desktoppower-bi-report-server

How to calculate roll up summary using dax


Hi I have a dataset like this, the date difference between each sprint is 14 days.

 Team       DateBegin   Sprint   Points
   Team1      1/2/2021    Sprint1   30
   Team1      1/16/2021   Sprint2   40
   Team1      1/30/2021   Sprint3   20
   Team1      2/13/2021   Sprint4   70
   Team1      2/27/2021   Sprint5   90
   Team1      3/11/2021   Sprint6   55
   Team1      3/25/2021   Sprint7   40
   Team2      1/2/2021    Sprint1   30
   Team2      1/16/2021   Sprint2   40
   Team2      1/30/2021   Sprint3   20
   Team2      2/13/2021   Sprint4   70
   Team2      2/27/2021   Sprint5   90
   Team2      3/11/2021   Sprint6   55
   Team2      3/25/2021   Sprint7   40

I wanted to calculate the Sum average using the last 3 sprints. for example

for Sprint7- sum(Sprint6+Sprint5+Sprint4)/3
For Sprint6- sum(Sprint5+Sprint4+Sprint3)/3

Something like For each Sprint look up the last 3 sprints and Sum them up and take the average(measure).


Solution

  • You can average the points for the 3 prior sprints like this:

    Last3Avg =
    VAR ThisSprintStart = SELECTEDVALUE ( Sprints[DateBegin] )
    VAR SprintsToDate =
        FILTER ( ALLSELECTED ( Sprints ), Sprints[DateBegin] < ThisSprintStart )
    RETURN
        AVERAGEX ( TOPN ( 3, SprintsToDate, Sprints[DateBegin] ), [Points] )