Forum Discussion
Dax Help
- 6 years ago
Well, never say never.
Behold:
IDA_m = 1+max('Table'[PX_Last])/10000 IDA_p = var d=max('Table'[As of Date]) return 10000000*PRODUCTX(filter(all('Table'),'Table'[As of Date]<=d),[IDA_m])
Please define "previous". Previous day, or previous row in the visual? What if there are multiple PX_LAST values for a date?
lbendlin Thank you for the response.
To answer your question, by "Previous" I mean the value from previous day (same as previous row if placed in descending order by Date) . And there will not be multiple PX_LAST for any given date.
Please let me know if you have any other questions.
- lbendlin6 years agoSuper User
"by "Previous" I mean the value from previous day (same as previous row if placed in descending order by Date)"
You see, this is exactly where my confusion comes from. I would call that the NEXT row. The previous row is on top of the current row, and the next row is below it - at least in my cultural perception. (I also wouldn't put dates in descending order but that's probably just me)
Here is how I would start:
var d = max('Table'[As of Date])
var prev_d = calculate (max('Table'[As of Date]),ALL('Table'),'Table'[As of Date]<d)
That gives you the latest date before your filter context date.
And now it becomes really complex since your measure depends on itself. Most likely this will lead to some sort of circular reference.
Where does the starting value come from? is that the 10 mil under the July line?
- Anonymous6 years agoNot applicable
lbendlin thanks for your input and yes you are right. That would be the next row. Dint realise we could see the same thing from either way, my bad.
Yeah the complex part would be tackling the circular reference.
The starting value (10 mil) was just entered manually in the spread sheet to start the base calculation. The first value will have to refer to this 10 mil in the calculation.
Thanks,
SV
- lbendlin6 years agoSuper User
We would have to list all the dates that are prior or equal to the filter context date and then have to successively apply the formula.
for 7/1/2013 it would be
(1+ (-13*1e-4))*1e7 = 1e7 + (-13*1e3)
or more generic
(1+PX_Last_7_1*1e-4)*1e7
For 8/1/13 it would be
(1+ PX_Last_8_1*1e-4) (1+PX_Last_7_1*1e-4)*1e7
For 9/1/13 it would be
(1+ PX_Last_9_1*1e-4)(1+ PX_Last_8_1*1e-4) (1+PX_Last_7_1*1e-4)*1e7
So we _should_ get away with a cumulative product of (1+PX*1e-4), and then at the very end multiply that by 10 mil.
Having said that I have no idea how to do cumulative products in Power BI. All I know is SUMX 😞