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.
Hello everyone,
I would like to calculate a time series of [Rate of Return] of an index and need your help.
By calculating the returns, I want to display the current price [Close] in relation to a starting price [Previous Close Price], based on a user-defined time period. While [Close] changes correspondingly for each date, [Previous Close Price] should always refer to the value of the first date in the selected period (see Slicer à e.g. 19.02.2020).
Example: the formula to calculate the [Rate of Return] for the date of 21.02.2020 should be as follows:
[Rate of Return of 21.02.2020] = ( [Close of 21.02.2020] – [Previous Close Price of 19.02.2020]) / [Previous Close Price of 19.02.2020]
With this DAX, I have tried to solve the problem. But unfortunately, the [Rate of Return] is always calculated referring to [Previous Close Price] of the previous row.
Rate of Return =
//Create table corresponding to user-defined period
VAR
table_timeperiod = FILTER('Historical Data', 'Historical Data'[Date] >= [minSelectedDate] && 'Historical Data'[Date] <= [maxSelectedDate])
//Determine PreviousClosePrice of first date
VAR
PreviousClose_t0 = CALCULATE(
MAX('Historical Data'[Previous Close Price]), FILTER('Historical Data', 'Historical Data'[Date] = [minSelectedDate])
)
RETURN
//Calculate RateofReturn for each row (=date)
CALCULATE(
SUMX('Historical Data', ('Historical Data'[Close]- PreviousClose_t0) / PreviousClose_t0),
table_timeperiod)
Basically, I want to create the scheme of a YTD return time series calculation (for each date within the selected period). However, with a start date that has not necessarily to be the beginning of a year.
Do you have any ideas how do adjust my DAX? Thank you so much for your help.
Regards.
@Anonymous
YTD Return Rate for a variable time period - Microsoft Power BI Community
Is this same question from you? If so, can you delete the old post and share your sample under the new post?
Regards
Paul
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 |
---|---|
114 | |
99 | |
82 | |
70 | |
61 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |