Forum Discussion
Measure that dynamically calculates average cost (avoiding circular dependency)
Hi leolapa_br did you spot which part of your code create circular dep. issue? I would suggest to debug part by part starting it with first, second VAR-iable ... continue to spot issue. This approach should be time saver in case you want / need another logic to create. Hope this help
- leolapa_br3 years ago
Resolver II
There are actually a couple of culprits:
- The prior average cost piece of the code (part 1 of my question above), as it's attempting to get the prior row from the very same column.
- The total cost of shares sold PRIOR to the date of each respective row (part 3 of my question above) since it's trying to sum up one calculated item that uses average cost itself as part of its own calculation.
I suspected I was going to run into this circular dependency issue right when I started developing the code since the pieces are interdependent upon themselves. However, the method is careful enough to go after rows of data that although from precedent data, happened prior to each respective row where the calculation is taking place, thus a circular dependency issue should be avoided.
This same dynamic calculation technique is applied in Excel using OFFSET and/or INDEX functions that makes the calculation ranges sort of 'run along' prior to each row of data, so when well implemented they don't bump into circular referencing issues. So I thought we're supposed to accomplish the same in DAX, I just don't know how...