# How to count on nested predicate

**URL:** <https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984>\
**Category:** GraphQL\
**Created:** [July 16, 2021, 2:07pm UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984 "2021-07-16T14:07:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abecker](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@abecker](https://discuss.dgraph.io/u/abecker)\
**Post date:** [July 16, 2021, 2:07pm UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984/1 "2021-07-16T14:07:07Z")

</div>

Hello,

i am quite new to dgraph and graphql and trying to define some first queries on my schema.  
now i’d like to count edges with a particular predicate but they are nested. could someone give me a hint how to do that?

here some details :  
schema:  
person → owns → animal.  
animal → carriesHorns → boolean.

now i like to count:  
how many animals do people own (on average) where the animal carriesHorns is true?

thanks!  
Anne

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [July 17, 2021, 2:08pm UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984/2 "2021-07-17T14:08:30Z")

</div>

Try something like this.

```auto
{
  me(func: Type(Person)) @filter(something) {
    name
    count(owns) @filter(eq(carriesHorns, "true"))
  }
}

```

---

<div class="post-metadata">

**Author:** ![abecker](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@abecker](https://discuss.dgraph.io/u/abecker)\
**Post date:** [July 20, 2021, 7:21am UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984/3 "2021-07-20T07:21:04Z")

</div>

hi,

sorry, I think I missed mentioning 1 nesting layer. we have some kind of n-ary relations / reification, therefore the schema is more like

Person - hasRelationship1 - MultirelationConcept  
MultirelationConcept - hasRelationShip2- Person  
Person - hasBooleanProperty - true

so I do not have to apply the filter the out-edges target of the first subject but on the object of the second (MultirelationConcept - hasRelationShip2- Person(filter boolean property=true))

---

<div class="post-metadata">

**Author:** ![abecker](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@abecker](https://discuss.dgraph.io/u/abecker)\
**Post date:** [July 22, 2021, 9:25am UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984/4 "2021-07-22T09:25:21Z")

</div>

@MichelDiz do you have any suggestion with this additional nesting layer?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [July 22, 2021, 2:29pm UTC](https://discuss.dgraph.io/t/how-to-count-on-nested-predicate/14984/5 "2021-07-22T14:29:30Z")

</div>

Not sure, I’m confused with your examples. Maybe this?

```auto
{
  me(func: Type(Person)) @filter(something) {
    name
     hasRelationship1 { 
      count(hasRelationship2) @filter(eq(hasBooleanProperty, "true")) { 
         uid name 
       }
     }
  }
}

```

If you share an example(sample) of your dataset reflecting exactly that structure would help a lot.

Cheers.
