Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Automate a Year over Year Calculation

I want to calculate YoY growth

Here is my dax using a manual input of 40 for the fiscal week:

Sales Growth % (YoY)  = Calculate ([Total Sales], 'Sales'[Fiscal_Year]= 2020)/ Calculate ( [Total Sales], 'Sales'[Fiscal_Year]= 2019, filter('Sales', 'Sales'[Fiscal_Week]<= 40))-1

This dax works just fine and gives me -10%.  I just need to add automation.  So I use a max function and determine max fiscal week = 40:

Max Fiscal Week = Calculate(max('Sales'[Fiscal_Week]),'Sales'[Fiscal_Year]=2020)

That works just fine as well and returns a value of 40 (not text).  Now, I want to replace the 40 with Max Fiscal Week:

Sales Growth % (YoY) Test = Calculate ([Total Sales],'Sales'[Fiscal_Year]= 2020)/ Calculate ( [Total Sales], 'Sales'[Fiscal_Year]= 2019, filter('Sales', 'Sales'[Fiscal_Week]<= [Max Fiscal Week]))-1

This dax yields “Infinity”.  

3 Replies