cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to divide the weight of a connection by the largest weight among all connections?

I have relations with different values in property and want divide all values by the maximum value and return result as new property for relationship/ How can i do that?

Do I have to first collect all the weight values of all relations, or is it possible somehow easier?

1 ACCEPTED SOLUTION

Thanks for the answer 🙂

The code almost worked, but I had to remove the "n" after "with"

Working code

match(n:Root)-[r:REL]->(m:Child)
with max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue

 

View solution in original post

4 REPLIES 4

You can try something like this:

match(n:Root)-[r:REL]->(m:Child)
with n, max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue

Thanks for the answer 🙂

The code almost worked, but I had to remove the "n" after "with"

Working code

match(n:Root)-[r:REL]->(m:Child)
with max(r.value) as maxValue, collect(r) as rels
unwind rels as rel
set rel.scaledValue = rel.value / maxValue

 

I guess you have multiple Root nodes and you want the max across all the relationships of type REL, regardless of the Root node they are connected too. 

Anyways, I am glad you got it to work.

As an alternative form, you can also use 'forEach' instead of 'unwind':

match(n:Root)-[r:REL]->(m:Child)
with n, max(r.value) as maxValue, collect(r) as rels
forEach(rel in rels |
    set rel.scaledValue = rel.value / maxValue
)