Forum Discussion
Calculate %Change
- Anonymous6 years ago
Ok, I understand. If you always want to have the same number of dates in the previous period you could do something like this. But if you for example select a month with 31 days it will compare to the previous 31 days, not the previous month.
SalesSelectedPeriod = SUM(Sales[TotalSales])
SalesPreviousPeriod = CALCULATE(SUM(Sales[TotalSales]), FILTER(ALL(Sales[Date]), Sales[Date]<MIN(Sales[Date]) && Sales[Date]>=MIN(Sales[Date])-COUNT(Sales[Date])))
Change = Sales[SalesSelectedPeriod] - Sales[SalesPreviousPeriod]
Change % = DIVIDE([Change]; [SalesPreviousPeriod])
There might be problems if you don't have sales every day. In that case you should use a date dimension that has all dates, even days without sales.
Hi Anonymous,
Thank you for quick response and time.
I need to compare the period selected in the current slicers with the same last period back to that selected period.
In the below image, you can see the relative date slicer, in which we select
last 1 week, so %change is for the selected week and one week back of the selected week, same as if we select
last 1 month, so it displays %change for selected month and last one month back and so on
Ok, I understand. If you always want to have the same number of dates in the previous period you could do something like this. But if you for example select a month with 31 days it will compare to the previous 31 days, not the previous month.
SalesSelectedPeriod = SUM(Sales[TotalSales])
SalesPreviousPeriod = CALCULATE(SUM(Sales[TotalSales]), FILTER(ALL(Sales[Date]), Sales[Date]<MIN(Sales[Date]) && Sales[Date]>=MIN(Sales[Date])-COUNT(Sales[Date])))
Change = Sales[SalesSelectedPeriod] - Sales[SalesPreviousPeriod]
Change % = DIVIDE([Change]; [SalesPreviousPeriod])
There might be problems if you don't have sales every day. In that case you should use a date dimension that has all dates, even days without sales.
- Anonymous6 years agoNot applicable
Anonymous,
Thank You so much for the Solution, It seems Working.
Thank you for your precious time.