Groupby and sum predicate

hello everyone, in my case I had a visitor and the duration spent but cam be many visits that’s why each visitor can have multiple duration it so I want calculate average time spent by visitor

data like that


data {
   dt_duration
   data_visitor {
  uid
}

so I want to groupby data_visitor and sum durations after that I will calculate average but I have a problem

this my query

 {
  var(func:has(dt_evt_name)) @groupby(data_visitor){
  id as count(uid)
}
  q(func: uid(id)) {
    uid
    dr as dt_duration
    total : sum(val(dr))
  }
  
 
}

I had error : “message”: “: Invalid variable aggregation. Check the levels.”

1 Like

As in the doc, the sum function should be at a higher level of the variable.

1 Like