Totalize and hops

Hi,

I'm using neo4j 3.5 community edition and trying totalize and get hops from a specific node. I'm running to totalize:

MATCH (p:Person{id:123})-[r]->(m) 
RETURN p,count(distinct(r.idSale)) as qtd,sum(r.value) as value,type(r) as type,r.seg as segment,m

How I get hops when its totalize??I'm trying something like these:

MATCH (p:Person{id:123})-[r]->(m)-[r2*2]->(m2) 
RETURN p,count(distinct(r.idSale)) as qtd,sum(r.value) as value,type(r),m,count(distinct(r2.idSale)) as qtd2,sum(r2.value) as total2,type(r2),m2

In your first example the number of hops from person 123 to any of the other nodes will always be 1 as you don't specify a variable length for the number of hops when specifying relationship type.

On the second example, you could do this:

MATCH (p:Person{id:123})-[r*..3]->(m)
...

r in this case is now a list of relationships, so we need to change the return statement to take that into account. We can use the APOC Library's collection functions to process the results.

MATCH (p:Person{id:123})-[r*..3]->(m)
RETURN apoc.coll.toSet([rel in r | rel.idSale]), 
                apoc.coll.sum([rel in r | rel.value]),
                [rel in r | type(r)],
                size(r) as hops

Thanks for your help, I'm trying run your example but I get this error :

My Graph:

What I'm trying:

I had a typo in the query:

MATCH (p:Person{id:123})-[r*..3]->(m)
RETURN apoc.coll.toSet([rel in r | rel.idSale]), 
                apoc.coll.sum([rel in r | rel.value]),
                [rel in r | type(rel)],
                size(r) as hops