Hey there! Is there a way to do a TOP n or BOTTOM ...
# gooddata-platform
p
Hey there! Is there a way to do a TOP n or BOTTOM n in an insight? And alongside the same lines, to sort result?
j
You can build metrics using WHERE TOP or BOTTOM(n) IN / OF functions and use those metrics in an insight. Feel free to review https://help.gooddata.com/doc/growth/en/dashboards-and-insights/maql-analytical-query[…]on-reference/numeric-functions/rank/where-top-or-bottom-n-in
p
Hey Jan, Thanks for your answer. I'm not sure this addresses my question. My understanding of the proposed solution is that it filters records before aggregation, when what I want is filtering after aggregation. I'll rewrite it with an example in mind: Basically what I want to do is the following SQL:
Copy code
SELECT
   attr,
   SUM(revenues) AS revenues
FROM dataset
WHERE {some_condition}
GROUP BY attr
ORDER BY revenues DESC
LIMIT 5
Or in GD terms: Given a dataset with an attribute named "attr", a fact column named "revenues", and some 100,000 records, If I want to display a horizontal bar chart where: • Vertical axis = attr • Horizontal axis = SUM(revenues) • Only the 5 attrs with the highest SUM(revenues) are shown How do I achieve such an insight?
p
Hey @Jakub Sterba! That seems to fit the bill 🙂 I'll try it out within the next 7-14 days and I'll come back to you with confirmation of resolution Thanks!