# Operations between related nodes of the same relation type

**URL:** <https://community.neo4j.com/t/operations-between-related-nodes-of-the-same-relation-type/36594>\
**Category:** Cypher\
**Tags:** data-modeling\
**Created:** [April 9, 2021, 2:46pm UTC](https://community.neo4j.com/t/operations-between-related-nodes-of-the-same-relation-type/36594 "2021-04-09T14:46:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sullirobert](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sullirobert/32/17666_2.png) [@sullirobert](https://community.neo4j.com/u/sullirobert)\
**Post date:** [April 9, 2021, 2:46pm UTC](https://community.neo4j.com/t/operations-between-related-nodes-of-the-same-relation-type/36594/1 "2021-04-09T14:46:42Z")

</div>

Greetings,  
I have a question about how to perform operations between children nodes. I have a document node(s) with about ~1200 children each containing a single value of a named metric. I'd like to pull two specific related node to create a ratio, then repeat for a list of parent nodes.  
I'm thinking of using a user def function or a change in the modeling, but hoping for another opinion.

for example:

```auto
match( documents:Document )-[:hasMetric]->(x:Metric {name="revenue })
match( documents:Document )-[:hasMetric]->(y:Metric {name="profit })
...
// for every document, return y.value / x.value

```

the model is very simple right now as I do not want to over complicate it yet, but is that my issue? Maybe each named metric needs its own relation type, but that would be 1,000s of relation types on millions of nodes.

thanks for any reply, and please let me know how to clarify.  
Cheers.

---

<div class="post-metadata">

**Author:** ![elena.kohlwey](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/elena.kohlwey/32/31033_2.png) [@elena.kohlwey](https://community.neo4j.com/u/elena.kohlwey)\
**Post date:** [April 12, 2021, 7:25am UTC](https://community.neo4j.com/t/operations-between-related-nodes-of-the-same-relation-type/36594/2 "2021-04-12T07:25:16Z")

</div>

Hi sullirobert,

welcome to the community!

I am not sure if I got the whole problem and feel free to clarify if there is more but for your example you could do something like:

```auto
MATCH (x:Metric {name:"revenue"})<-[:hasMetric]-( documents:Document )-[:hasMetric]->(y:Metric {name:"profit" })
RETURN y.value/x.value

```

If you have more than two metrics, probably something like the following will work:

```auto
MATCH ( documents: Document )
WITH documents
MATCH (documents)-[:hasMetric]->(x:Metric {name:"revenue" }), (documents)-[:hasMetric]->(y:Metric {name:"profit" }), (documents)-[:hasMetric]->(z:Metric {name:"cost" })
RETURN ...

```

Regards,  
Elena

---

<div class="post-metadata">

**Author:** ![sullirobert](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sullirobert/32/17666_2.png) [@sullirobert](https://community.neo4j.com/u/sullirobert)\
**Post date:** [April 12, 2021, 8:19pm UTC](https://community.neo4j.com/t/operations-between-related-nodes-of-the-same-relation-type/36594/3 "2021-04-12T20:19:31Z")

</div>

yup. works! thank you
