Forum Discussion
Arnabi
4 years agoRegular Visitor
Decade over Decade KPI
I'm Trying to create a DoD and DoD % Change KPI, to go along with my YoY KPI and YoY change. I was able to create a Decade column on my date table using the following DAX code (if someone has a bett...
- 4 years ago
Hi Arnabi,
To calculate DoD we can use datesbetween in a calculate function. Here is how I would approach this:
My test data:I created the decade column the same way you made it:
Decade =VAR DecadeStart =ROUNDDOWN( YEAR('Values DoD'[Date]), -1)VAR DecadeEnd = DecadeStart + 9RETURNDecadeStart & " - " & DecadeEndFor DoD calculation I used the following DAX:
DoD =var CYear = year(max('Values DoD'[Date]))var EODecade = date(roundup(if(right(CYear,1)="0",CYear+1,CYear),-1)-1,12,31)//Here I define end of decade based on selection. So for example 2011.1.1 would return 2020.31.12. The If condition is in place for years thath are multiple of 10var SODecade = date(ROUNDDOWN(CYear,-1),1,1) return //same for start of decadeCALCULATE (SUM('Values DoD'[Value]),DATESBETWEEN ('Values DoD'[Date],SODecade,EODecade)) //Actual DoD calculation
Last decade can be calculated similarly:Last Decade DoD =Var CYear = year(max('Values DoD'[Date]))var EODecade = date(roundup(if(right(CYear,1)="0",CYear+1,CYear),-1)-11,12,31)var SODecade = date(ROUNDDOWN(CYear,-1)-10,1,1) returnCALCULATE (SUM('Values DoD'[Value]),all('Values DoD'),DATESBETWEEN ('Values DoD'[Date],SODecade,EODecade)) //Here the difference is -11 and -10 in the variables. Also we need to use All due to Decade column
Finally DoD difference:DoD difference % = DIVIDE([DoD]-[Last Decade DoD],[Last Decade DoD])
End result:
Hopefully this helps and if it does consider accepting this as a solution!
ValtteriN
Community Champion
4 years agoHi Arnabi,
To calculate DoD we can use datesbetween in a calculate function. Here is how I would approach this:
My test data:
I created the decade column the same way you made it:
Decade =
VAR DecadeStart =
ROUNDDOWN( YEAR('Values DoD'[Date]), -1)
VAR DecadeEnd = DecadeStart + 9
RETURN
DecadeStart & " - " & DecadeEnd
For DoD calculation I used the following DAX:
DoD =
var CYear = year(max('Values DoD'[Date]))
var EODecade = date(roundup(
if(right(CYear,1)="0",
CYear+1,
CYear)
,-1)-1,12,31)
//Here I define end of decade based on selection. So for example 2011.1.1 would return 2020.31.12. The If condition is in place for years thath are multiple of 10
var SODecade = date(ROUNDDOWN(CYear,-1),1,1) return //same for start of decade
CALCULATE (
SUM('Values DoD'[Value]),
DATESBETWEEN (
'Values DoD'[Date],
SODecade,
EODecade
)
) //Actual DoD calculation
Last decade can be calculated similarly:
Last Decade DoD =
Var CYear = year(max('Values DoD'[Date]))
var EODecade = date(roundup(
if(right(CYear,1)="0",
CYear+1,
CYear)
,-1)-11,12,31)
var SODecade = date(ROUNDDOWN(CYear,-1)-10,1,1) return
CALCULATE (
SUM('Values DoD'[Value]),
all('Values DoD'),
DATESBETWEEN (
'Values DoD'[Date],
SODecade,
EODecade
)
) //Here the difference is -11 and -10 in the variables. Also we need to use All due to Decade column
Finally DoD difference:
Finally DoD difference:
DoD difference % = DIVIDE([DoD]-[Last Decade DoD],[Last Decade DoD])
End result:
End result:
Hopefully this helps and if it does consider accepting this as a solution!
Arnabi
4 years agoRegular Visitor
I greatly appreciate it...it worked beautifully