Forum Discussion
Recursive graph calculation in Dax
Hi,
I have solved the following problem in power query but are looking for an alternative and improved performance solution using DAX.
It is effectively a recursive graph solution and required to perfrom an costing solution.
I have a setup of Input Costs:
| CostPool | Input Cost |
| CostPool 10 | 100 |
| CostPool 11 | 150 |
The following relationship table exists:
| SrcCostPool | SrcLayer | DestCostPool | DestLayer | Allocation Factor | Relationship |
| CostPool 10 | L1 | CostPool 21 | L2 | 0.333333 | CostPool 10-CostPool 21 |
| CostPool 10 | L1 | CostPool 22 | L2 | 0.666667 | CostPool 10-CostPool 22 |
| CostPool 11 | L1 | CostPool 31 | L3 | 1 | CostPool 11-CostPool 31 |
| CostPool 21 | L2 | CostPool 31 | L3 | 0.272727 | CostPool 21-CostPool 31 |
| CostPool 21 | L2 | CostPool 32 | L3 | 0.727273 | CostPool 21-CostPool 32 |
| CostPool 22 | L2 | CostPool 31 | L3 | 0.993084 | CostPool 22-CostPool 31 |
| CostPool 22 | L2 | CostPool 32 | L3 | 0.006916 | CostPool 22-CostPool 32 |
| CostPool 31 | L3 | CostPool 41 | L4 | 0.193614 | CostPool 31-CostPool 41 |
| CostPool 31 | L3 | CostPool 43 | L4 | 0.805477 | CostPool 31-CostPool 43 |
| CostPool 31 | L3 | CostPool 51 | L5 | 0.000267 | CostPool 31-CostPool 51 |
| CostPool 31 | L3 | CostPool 52 | L5 | 0.000642 | CostPool 31-CostPool 52 |
| CostPool 32 | L3 | CostPool 41 | L4 | 0.278034 | CostPool 32-CostPool 41 |
| CostPool 32 | L3 | CostPool 43 | L4 | 0.385561 | CostPool 32-CostPool 43 |
| CostPool 32 | L3 | CostPool 42 | L4 | 0.336406 | CostPool 32-CostPool 42 |
| CostPool 41 | L4 | CostPool 52 | L5 | 0.033149 | CostPool 41-CostPool 52 |
| CostPool 41 | L4 | CostPool 53 | L5 | 0.966851 | CostPool 41-CostPool 53 |
| CostPool 42 | L4 | CostPool 52 | L5 | 0.041096 | CostPool 42-CostPool 52 |
| CostPool 42 | L4 | CostPool 53 | L5 | 0.958904 | CostPool 42-CostPool 53 |
| CostPool 43 | L4 | CostPool 52 | L5 | 0.023904 | CostPool 43-CostPool 52 |
| CostPool 43 | L4 | CostPool 53 | L5 | 0.976096 | CostPool 43-CostPool 53 |
The relationship is effectively a layer graph type model where a layer of CostPool nodes have a dependancy on a previous layer/s of nodes. For example
Cost of CostPool 21 = Input Cost 10 * Allocation Factor (CostPool 10-Costpool 21),
CostPool 31 = Input Cost 11 * Allocation Factor (CostPool 11-CostPool31) + Cost of CostPool 21 * Allocation Factor (CostPool 21-CostPool 31)
This will be repeated until the last layer. For the example it will be all the CostPool nodes in L5.
Can someone maybe help with a solution in DAX?
Many thanks
2 Replies
- Greg_DecklerCommunity Champion
tonie_tollig Not 100% certain what you are going for here but recursion is not generally possible in Power BI. I have done extension research in this area and never found a good way. Runge-Kutta and the Limits of DAX - Microsoft Power BI Community
- tonie_tolligFrequent Visitor
Thanks Greg
That is not the best news but at least I know not to spend to much more time on DAX while we wait for the implementation of PREVIOUSVALUE in DAX