# Error; "Vars can be assigned only when grouped by UID attribute"

**URL:** <https://discuss.dgraph.io/t/error-vars-can-be-assigned-only-when-grouped-by-uid-attribute/17834>\
**Category:** Dgraph\
**Created:** [October 4, 2022, 5:16pm UTC](https://discuss.dgraph.io/t/error-vars-can-be-assigned-only-when-grouped-by-uid-attribute/17834 "2022-10-04T17:16:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenW](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/benw/32/7532_2.png) [@BenW](https://discuss.dgraph.io/u/BenW)\
**Post date:** [October 4, 2022, 5:16pm UTC](https://discuss.dgraph.io/t/error-vars-can-be-assigned-only-when-grouped-by-uid-attribute/17834/1 "2022-10-04T17:16:15Z")

</div>

To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.

## What I want to do

Get a total count of groups. Using groupby to group by a predicate value, want to know how many groups there are for pagination.

## What I did

This is the query I’m using:

```auto
query q($lexicon: string, $first: int) {
  var(func: type(Lexicon)) @filter(eq(Lexicon.language, "EN")) {
     Lexicon.lexicalEntries {
       LE as uid
    }
  }
  var(func: uid(LE)) @groupby(headword: LexicalEntry.headword, count) {
    H as count(uid)
  }
  q(func: uid(H)) {
    total: val(H)
  }
}

```

I get the following error: `"Vars can be assigned only when grouped by UID attribute".`

I think this might be the fix? but looks like it hasn’t been merged into any release yet? [feat(DQL): @groupby on scalar fields and count duplicate by minhaj-shakeel · Pull Request #7746 · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/pull/7746)

## Dgraph metadata

> **21.03**
>

---

<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:** [October 4, 2022, 7:55pm UTC](https://discuss.dgraph.io/t/error-vars-can-be-assigned-only-when-grouped-by-uid-attribute/17834/2 "2022-10-04T19:55:59Z")

</div>

> [@BenW](#):
>
> I think this might be the fix?

Yes. I think it is.

> [@BenW](#):
>
> but looks like it hasn’t been merged into any release yet?

It is in [Dgraph v21.12.0 - Zion](https://github.com/dgraph-io/dgraph/releases/tag/v21.12.0)

---

<div class="post-metadata">

**Author:** ![BenW](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/benw/32/7532_2.png) [@BenW](https://discuss.dgraph.io/u/BenW)\
**Post date:** [October 4, 2022, 8:02pm UTC](https://discuss.dgraph.io/t/error-vars-can-be-assigned-only-when-grouped-by-uid-attribute/17834/3 "2022-10-04T20:02:45Z")

</div>

> [@MichelDiz](#):
>
> It is in [Dgraph v21.12.0 - Zion](https://github.com/dgraph-io/dgraph/releases/tag/v21.12.0)

How did you figure that out? Dgraph’s git branches are pretty hectic!
