Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Arnabi
Regular 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 better one do share)

Decade =
VAR DecadeStart =
ROUNDDOWN( DateDimension[Year], -1)
VAR DecadeEnd = DecadeStart + 9
RETURN
DecadeStart & " - " & DecadeEnd
 
but i want to calculate the change of a measure over a decade rather than year and place it on the graph as well .  My current YoY and %YoY change Dax code is 

LYNationWideRatio = CALCULATE([NationWideHomePriceRatio], SAMEPERIODLASTYEAR(DateDimension[Date]))

%YoYNationWideRatio = DIVIDE([DiffNationWideRatio], [LYNationWideRatio], 0)

 

Arnabi_1-1638694893006.png

 


 

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi Arnabi,

To calculate DoD we can use datesbetween in a calculate function. Here is how I would approach this:
My test data: 

ValtteriN_0-1638709552291.png

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: 
DoD difference % = DIVIDE([DoD]-[Last Decade DoD],[Last Decade DoD])

End result:

ValtteriN_2-1638709784675.png



Hopefully this helps and if it does consider accepting this as a solution!


 


 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ValtteriN
Super User
Super User

Hi Arnabi,

To calculate DoD we can use datesbetween in a calculate function. Here is how I would approach this:
My test data: 

ValtteriN_0-1638709552291.png

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: 
DoD difference % = DIVIDE([DoD]-[Last Decade DoD],[Last Decade DoD])

End result:

ValtteriN_2-1638709784675.png



Hopefully this helps and if it does consider accepting this as a solution!


 


 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I greatly appreciate it...it worked beautifully 

 

Arnabi_0-1638810039235.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.