Thank you but I get the following error with that approach: <type 'exceptions.TypeError'> list indices must be integers, not Expression
However, I did get this to work: t = db.items q = t.id>0 usum = t.sales.sum() usum.tablename = 'items' usum.readable = True usum.represent = False usum.formatter = lambda value:value usum.label = T('Sales') usum.table = t grid = SQLFORM.grid(q, fields=[t.country, t.state, usum], groupby=t.country|t.state, orderby=[t.country, t.state], ) list = [] list.append(['country','state','sales']) for row in db(t).select(t.country, t.state, usum, groupby=t.country|t.state): list.append([row.items.country, row.items.state, row[usum]]) On Thursday, February 19, 2015 at 12:29:19 AM UTC-8, 黄祥 wrote: > > please try : > sum_items = db.items.sales.sum() > db().select(sum_items, groupby = db.items.country)[sum_items] > > best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.