Forum Discussion

tonie_tollig's avatar
tonie_tollig
Frequent Visitor
5 years ago

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:

 

CostPoolInput Cost
CostPool 10 100
CostPool 11 150

 

The following relationship table exists:

SrcCostPool SrcLayer DestCostPool DestLayerAllocation FactorRelationship
CostPool 10 L1CostPool 21 L20.333333CostPool 10-CostPool 21
CostPool 10 L1CostPool 22 L20.666667CostPool 10-CostPool 22
CostPool 11 L1CostPool 31 L31CostPool 11-CostPool 31
CostPool 21 L2CostPool 31 L30.272727CostPool 21-CostPool 31
CostPool 21 L2CostPool 32 L30.727273CostPool 21-CostPool 32
CostPool 22 L2CostPool 31 L30.993084CostPool 22-CostPool 31
CostPool 22 L2CostPool 32 L30.006916CostPool 22-CostPool 32
CostPool 31 L3CostPool 41 L40.193614CostPool 31-CostPool 41
CostPool 31 L3CostPool 43 L40.805477CostPool 31-CostPool 43
CostPool 31 L3CostPool 51 L50.000267CostPool 31-CostPool 51
CostPool 31 L3CostPool 52 L50.000642CostPool 31-CostPool 52
CostPool 32 L3CostPool 41 L40.278034CostPool 32-CostPool 41
CostPool 32 L3CostPool 43 L40.385561CostPool 32-CostPool 43
CostPool 32 L3CostPool 42 L40.336406CostPool 32-CostPool 42
CostPool 41 L4CostPool 52 L50.033149CostPool 41-CostPool 52
CostPool 41 L4CostPool 53 L50.966851CostPool 41-CostPool 53
CostPool 42 L4CostPool 52 L50.041096CostPool 42-CostPool 52
CostPool 42 L4CostPool 53 L50.958904CostPool 42-CostPool 53
CostPool 43 L4CostPool 52 L50.023904CostPool 43-CostPool 52
CostPool 43L4CostPool 53 L50.976096CostPool 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