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.
Hi,
Here is the kind of data set i have :
Date | Product | Price | Rank |
22/08/2017 | A | 95.50 | 1 |
22/08/2017 | B | 61.11 | 1 |
22/08/2017 | C | 65.74 | 1 |
21/08/2017 | A | 49.61 | 2 |
21/08/2017 | B | 60.61 | 2 |
21/08/2017 | C | 52.30 | 2 |
20/08/2017 | A | 75.13 | 3 |
20/08/2017 | B | 91.19 | 3 |
20/08/2017 | C | 85.00 | 3 |
16/08/2017 | A | 37.84 | 4 |
16/08/2017 | B | 99.51 | 4 |
16/08/2017 | C | 94.63 | 4 |
I 'm trying to compute the Day on Day price variation for each product. I managed to have something that works only if i have data on each days (but i will not have always daily datas, most of the time, nothing on weekend and sometimes one data points can miss on week days also)
Here is my column formula :
DoD Price= CALCULATE( ((AVERAGE(DataBase[Price]))-CALCULATE( AVERAGE(DataBase[Price]);DATEADD(DataBase[Date];-1;DAY); ALLEXCEPT(DataBase;DataBase[Date];DataBase[Product]))); ALLEXCEPT(DataBase;DataBase[Date];DataBase[Product]) )
I was thinking about using the "Rank" column wich is computed with this formula :
Rank = RANKX(DataBase;DataBase[Date];;DESC;Dense)
But i don't know if and how i can use to compute somthing like
CALCULATE ( AVERAGE(DataBase[Price]) - CALCULATE( AVERAGE(DataBase[Price]);RANK=RANK+1))
since the Rank+1 will always existe except for the oldest value.
Many thanks for your help
Regards
Pierre
Solved! Go to Solution.
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
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)?
exactly yes ! That's why i was thinking about using the "rank" column.
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
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
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
That's perfect many thanks !
Is it easely adaptable for MoM variation or 21days on 21 days variation ?
Oh and one last question, what is difference between using your solution as column formula or as a measure ?
Thanks
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 !
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |