# How to Use Grouping Sets in Django

DevFeed: [How to Use Grouping Sets in Django](<https://devfeed.tech/articles/how-to-use-grouping-sets-in-django-33912.md>)

Original publisher: [Read original article](<https://hakibenita.com/how-to-use-grouping-sets-in-django>)

Author: Haki Benita

Published: 2019-03-09T22:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [Django](<https://devfeed.tech/topics/django.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [dashboards](<https://devfeed.tech/topics/dashboards.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [django](<https://devfeed.tech/tags/django.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [metrics](<https://devfeed.tech/tags/metrics.md>), [optimizing](<https://devfeed.tech/tags/optimizing.md>), [orm](<https://devfeed.tech/tags/orm.md>), [performance](<https://devfeed.tech/tags/performance.md>), [query](<https://devfeed.tech/tags/query.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

This tutorial explains how advanced SQL grouping sets can optimize a Django admin dashboard. It describes a dashboard whose separate aggregation queries became slow as data grew, and discusses combining metrics while handling averages and distinct user counts correctly.

## Source excerpt

How we cut a heavy admin dashboard response time in half with advanced SQL and some Django hackery. I recently had the pleasure of optimizing an old dashboard. The solution we came up with required some advanced SQL that Django does not support out of the box. In this article I present the solution, how we got to it, and a word of caution.