I have a binary tree structure that I am using to find the aggregate sum of values stored in each node. I achieve it as follows.

```
MATCH (d1:Distributor)-[*]->(d2:Distributor)
with d1, sum (d2.counter) AS tot_counter
RETURN d1.cid, tot_counter
```

There is a property called counter stored as a property of each node. So, while running the above query, I can group together the aggregate sum of the counter value of each branch. For instance, imagine the node 1, which has two children, 2 and 3. So the query should aggregate a sum of the branches of 1, ie...2+3 and return the same, and has to repeat this recursively to go the entire length of the graph.

For instance, it will return,

There are two situations in which I am facing problems.

- I need control over the node from where I need to start executing. For instance, I need the query to find the aggregate for all paths starting from 3. I tried the following query, but it doesn't do the work.

```
MATCH (d1:Distributor)-[*]->(d2:Distributor)
WITH d1, sum (d2.counter) AS tot_counter WHERE d1.cid="1"
RETURN d1.cid, tot_counter
```

This query only returns the aggregate sum of one node, I need the path to start from 1. Not to limit to 1.

Secondly, I want a mechanism by which I can store this aggregate sum of the branch's counter value obtained this way to be stored in another property called counter_sum of each node.

Is there any way I can achieve this?