Forum Discussion
Calculating daily numbers based on MTD numbers
- Anonymous8 years ago
Hi kkalyanrr,
Based on the data and your requirement, the approach to be taken is finding the previous days value and substracting it from the current days MTD value.
Try the following steps
1. I named the data table as Table2
2. Created an Indexcolumn from 1 in the fact table.
3. Created an YearMonth column as
YearMonth = Year(Table2[Date]) * 100 + Month(Table2[Date])
4. Created a measure called DailySales
DailySales =
var PreviousValue =
CALCULATE(
SUM( Table2[Sales(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[Sales(MTD)])
)
)
Return
Calculate(Sum(Table2[Sales(MTD)]) - PreviousValue)In this measure we find the previousvalue first for each row and then finally substract ir from Sales[MTD]. This avoids creating a calculated column for the PreviousValue.
5. Created measures DailyRevenue
DailyRevenue =
var PreviousValue =
CALCULATE(
SUM( Table2[Revenue(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[Revenue(MTD)])
)
)
Return
Calculate(Sum(Table2[Revenue(MTD)]) - PreviousValue)6. Created measure DailyPageViews
DailyPageViews =
var PreviousValue =
CALCULATE(
SUM( Table2[PageViews(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[PageViews(MTD)])
)
)
Return
Calculate(Sum(Table2[PageViews(MTD)]) - PreviousValue)Sample output
If this works for you please accept it as a solution also give KUDOS.
Cheers
CheenuSing
Hi kkalyanrr,
Based on the data and your requirement, the approach to be taken is finding the previous days value and substracting it from the current days MTD value.
Try the following steps
1. I named the data table as Table2
2. Created an Indexcolumn from 1 in the fact table.
3. Created an YearMonth column as
YearMonth = Year(Table2[Date]) * 100 + Month(Table2[Date])
4. Created a measure called DailySales
DailySales =
var PreviousValue =
CALCULATE(
SUM( Table2[Sales(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[Sales(MTD)])
)
)
Return
Calculate(Sum(Table2[Sales(MTD)]) - PreviousValue)
In this measure we find the previousvalue first for each row and then finally substract ir from Sales[MTD]. This avoids creating a calculated column for the PreviousValue.
5. Created measures DailyRevenue
DailyRevenue =
var PreviousValue =
CALCULATE(
SUM( Table2[Revenue(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[Revenue(MTD)])
)
)
Return
Calculate(Sum(Table2[Revenue(MTD)]) - PreviousValue)
6. Created measure DailyPageViews
DailyPageViews =
var PreviousValue =
CALCULATE(
SUM( Table2[PageViews(MTD)] ),
FILTER( ALL(Table2) ,
SUMX( FILTER( Table2, EARLIER(Table2[Index]) = Table2[Index] -1 && EARLIER([YearMonth]) = [YearMonth] ),Table2[PageViews(MTD)])
)
)
Return
Calculate(Sum(Table2[PageViews(MTD)]) - PreviousValue)
Sample output
If this works for you please accept it as a solution also give KUDOS.
Cheers
CheenuSing
Thank you, Brilliant Stuff.