 # How to sum up values of facets

My usecase:
I have jobTitle Node. I have a relation called NEXT from jobTitle to jobTitle. There is a property called cnt that tells the weight of the relationship.
For a given jobTitle i need to find all the next progressions and sort them based on the sum of weights of the edges.
eg:
data i have:
(j1)-[:next{cnt:10}]-(j2)-[:next{cnt:5}]-(j3) = 15
(j1)-[:next{cnt:5}]-(j3)-[:next{cnt:15}]-(j4) = 20
(j1)-[:next{cnt:10}]-(j2)-[:next{cnt:7}]-(j5) = 17

out put:
(j1)->(j3)->(j4)
(j1)->(j2)->(j5)
(j1)->(j2)->(j3)

query i tried

``````{
q(func:has(name))@filter(eq(name,"j1"))@recurse(depth:3){
name
NEXT@facets(orderdesc: cnt)@filter(not eq(name,"j1"))
}
}

``````

this query is giving me result as
(j1)->(j2)->(j5)
(j1)->(j2)->(j3)
(j1)->(j3)->(j4)

points i am stuck at
1)how to add these facets properly in a progression?
2)how to order result based on sum of facet values?
3)How to get my expected result?
Any idea is welcomed.

Hey @Mounika_Mandadi, Is it known that the path can be of length 2 only? Or can it be of any arbitrary length?

@ahsan it can be arbitrary.

``````{
"set": [
{
"uid": "_:j1",
"name": "j1",
"dgraph.type": "jobTitle",
"next": [
{
"uid": "_:j2",
"name": "j2",
"dgraph.type": "jobTitle",
"next|cnt": "10",
"next": [
{
"uid": "_:j3",
"name": "j3",
"next|cnt": "5",
"dgraph.type": "jobTitle"
},
{
"uid": "_:j5",
"name": "j5",
"next|cnt": "7",
"dgraph.type": "jobTitle"
}
]
},
{
"uid": "_:j3",
"name": "j3",
"next|cnt": "5",
"dgraph.type": "jobTitle",
"next": [
{
"uid": "_:j4",
"name": "j4",
"next|cnt": "15",
"dgraph.type": "jobTitle"
}
]
}
]
}
]
}
``````

Is quite hard to stop to read this patterns and try to figure out how to transport to RDF or JSON.

### Some points.

Maybe there’s a wrong relationship, can you check it out?
The relationship between (j1)->(j2)->(j5) and (j1)->(j2)->(j3) cannot have two facets unless there are two entities with the same name as "j2 ". If J2 is an unique entity, it is not possible to have two facets between j1 and j2 on the same edge.

After that confirmations I can address the other questions.

J2 is unique entity and if we observe in the sample data i have provided , i have given the same facet value right in line 1 and in line 3? “(j1)-[:next{cnt:10}]-(j2)”.