Forum Discussion
DoD Variation column using Dateaddd on Business Days
- Anonymous9 years ago
Hi pitucc,
My formula is a measure, if you direct use it as calculate column ,it may caused the issue.
In addition, if you need you can also use below formula: (calculate column version)
DoD diff = VAR previous_date = MAXX ( FILTER ( ALL ( 'Sample' ), [Date] < EARLIER ( [Date] ) ), [Date] ) RETURN IF ( previous_date <> 0, AVERAGEX ( FILTER ( ALL ( 'Sample' ), [Product] = EARLIER ( [Product] ) && [Date] = EARLIER ( [Date] ) ), [Price] ) - AVERAGEX ( FILTER ( ALL ( 'Sample' ), [Product] = EARLIER ( [Product] ) && [Date] = previous_date ), [Price] ), 0 )Regards,
Xiaoxin Sheng
- 9 years ago
Hello,
I just wnated to close the topic, to compute a variation for anything alse than day on day, in the computation of "previous_avg" just replace "current_date" by " (current_date-XX) where XX is the lag you want for your variation.
For a WoW variation I have used the code below :
WoW Cheap = VAR current_Product =LASTNONBLANK ( DataBase[Name]; [Name] ) VAR current_date = MAX ( DataBase[ValuationDate] ) VAR current_avg = AVERAGEX ( FILTER ( ALL ( DataBase ); [Name] = current_Product && [ValuationDate] = current_date ); [Cheap] ) VAR previous_avg = AVERAGEX ( FILTER ( ALL ( DataBase ); [Name] = current_Product && [ValuationDate] = MAXX ( FILTER ( ALL ( DataBase ); [Name] = current_Product && [ValuationDate] < (current_date-6) ); [ValuationDate] ) ); [Cheap] ) RETURN IF ( previous_avg <> 0; current_avg - previous_avg; 0 )Many thanks once again for your help !
So, in the case of a missing date, do you want to calculate from the last date that there is?
For example:
22/08/2017, A, 95.50
24/08/2017, A, 95.60
So, on 23/08/2017 the price difference should be 0 and on 24/08/2017 the price difference should be .10 (not 95.60)?
- pitucc9 years agoHelper I
exactly yes ! That's why i was thinking about using the "rank" column.
- Anonymous9 years agoNot applicable
Hi pitucc,
If you want to calculate day of day moving average diff, you can try to use below formula:
DoD Avg Diff = VAR current_Product =LASTNONBLANK ( 'Sample'[Product], [Product] ) VAR current_date = MAX ( 'Sample'[Date] ) VAR current_avg = AVERAGEX ( FILTER ( ALL ( 'Sample' ), [Product] = current_Product && [Date] = current_date ), [Price] ) VAR previous_avg = AVERAGEX ( FILTER ( ALL ( 'Sample' ), [Product] = current_Product && [Date] = MAXX ( FILTER ( ALL ( 'Sample' ), [Product] = current_Product && [Date] < current_date ), [Date] ) ), [Price] ) RETURN IF ( previous_avg <> 0, current_avg - previous_avg, 0 )Regards,
Xiaoxin Sheng
- pitucc9 years agoHelper I
Hello,
Thanks for your help but I have litterally copy pasted your formula but it don't have the same result as you do...
Any idea why ?
Furthermore, is the formula easely adaptable to compte a Month on month variation difference ?
Thanks