Hi everyone,
I have written a cypher query to calculate the sum of its next connected node, but for the lowest (last) node where there is no next connected node, how to make the below query work.
match p=(a:RM)[r1:transport]>(b:RM)[r2:transport]>(c:RM)[r3:transport]>(d:WIPProduction)[r4:transport]>(e:WIPStorage)[r5:transport]>(f:WIPStorage)[r6:transport]>(g:WIPProduction)[r7:transport]>(h:WIPStorage)[r8:transport]>(i:WIPStorage)[r9:transport]>(j:WIPStorage)[r10:transport]>(k:Production)[r11:transport]>(l:Storage)[r12:transport]>(m:Storage)
where a.Date=date('20211001')
with p,a,r1,b,r2,c,r3,d,r4,e,r5,f,r6,g,r7,h,r8,i,r9,j,r10,k,r11,l,r12,m, case when m.end_point=1 then 0 else sum((r13.quota)*(r13.bom_qty)*(n.Inflow_Requirement)) end as downstream_inflow_requirement
set m.Outflow_Requirement_Updated=downstream_inflow_requirement
with p,a,r1,b,r2,c,r3,d,r4,e,r5,f,r6,g,r7,h,r8,i,r9,j,r10,k,r11,l,
case when l.end_point=1 then 0 else sum((r12.quota)*(r12.bom_qty)*(m.Inflow_Requirement)) end as downstream_inflow_requirement
set l.Outflow_Requirement_Updated=downstream_inflow_requirement
with p,a,r1,b,r2,c,r3,d,r4,e,r5,f,r6,g,r7,h,r8,i,r9,j,r10,k, case when k.end_point=1 then 0 else sum((r11.quota)*(r11.bom_qty)*(l.Inflow_Requirement)) end as downstream_inflow_requirement
set k.Outflow_Requirement_Updated=downstream_inflow_requirement
return p ;
This formula has to repeat for all nodes from m to a ( I have written till k only), There are 2 issues I am facing here:

In the first with statement I am getting an error that variable r13, n is not defined , so how should i structure the formula to make it work as the formula has to be standard for all the nodes?

Is there any way that instead of repeating the same formula for different set of nodes till a, just if I put a parameter or something and that automatically cypher shifts and traverses the path for all variables ?
Please let me know if anyone has the solution for this.
Thanks,
Pragya