Forum Discussion
Dax Help
Hi, I am trying to calculate the below excel formula in Power BI as a calculated column (DAX or MQuery or Python)
Formula:
IDA = ((1 + (Current value of PX_LAST/10000)) * Next IDA value)
Sample Data with calculation:
| As of Date | PX_Last | IDA |
| 1/11/2013 | 1 | 10,066,030.73 |
| 1/10/2013 | 41 | 10,065,024.23 |
| 1/9/2013 | 43 | 10,023,926.13 |
| 1/8/2013 | -6 | 9,981,007.80 |
| 1/7/2013 | -13 | 9,987,000.00 |
| 10000000 |
Any help would be greatly appreciated!
Thasnk,
SV
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])
10 Replies
- lbendlinSuper User
Please define "previous". Previous day, or previous row in the visual? What if there are multiple PX_LAST values for a date?
- AnonymousNot applicable
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.
- lbendlinSuper 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?