Groupby on top of Sorting on Dgraph

Consider below scenario where student details are stored in Dgraph

Schema

<att_date>_: datetime @index(year) .
<att_status>_: string @index(term) .
<students>: [uid] @reverse .
<name>_: string @index(term) .
<student_id>_: string @index(hash) @upsert .
type <Attendence> {
    att_date
    att_status
    students
}
type <Student> {
    student_id
    name
}

Mutation

{
    set{
        _:s1 <student_id> "1" .
        _:s2 <student_id> "2" .
        _:s2 <student_id> "3" .

        _:s1 <name> "A" .
        _:s2 <name> "B" .
        _:s2 <name> "C" .

        _:s1 <dgraph.type> "Student" .
        _:s2 <dgraph.type> "Student" .
        _:s3 <dgraph.type> "Student" .


        _:e1 <att_date> "2022-02-01" .
        _:e1 <att_status> "Present" .
        _:e1 <dgraph.type> "Attendence" .

        _:e2 <att_date> "2022-02-02" .
        _:e2 <att_status> "Present" .
        _:e2 <dgraph.type> "Attendence" .
    
        _:e1 <students>  _:s1 .
        _:e1 <students>  _:s2 .
        _:e1 <students>  _:s3 .

        _:e2 <students>  _:s1 .
        _:e2 <students>  _:s2 .

    }
}

I need to find count of students based on max date on which student is present.

I am able to find the max present date for each student by below query

{
  q(func: type(Student)){
    uid 
    student_id
    ~students(orderdesc: att_date, first: 1) {
        att_date
    }
  }
 
}

but I am unable to attach group by to above query like a variable.

I want to know is there any better way to query or model this data.

Thanks in advance