Hi GD Team, I'm running into a bit of a problem c...
# gooddata-cloud
p
Hi GD Team, I'm running into a bit of a problem conceptually and wondering if this is possible. I have a fact named Devices Seen that counts the number of mobile devices seen in a location. I want that value to be represented as a percentage, which is easy enough using the 'show in % button'. My issue now is I want to to show the Top 20 devices seen with an associated label (Home Local Government Area). Firstly I cannot use the show in %, and even if I did the %s would be calculated for the Top 20 and not all the Home Local Government Areas which would be incorrect. See the screenshot for an example. If the data was to be cut off at the top 20 mark I assume the percentages would be calculated as the top 20 being '100%' rather than all existing rows in the data. Is there a way I can implement a visualisation limit so that the data is still calculated over the full dataset for correct percentages but only the top 20 are shown?
1
m
Hi Paiwand, one option how to achieve this more complex condition is to use a MAQL metric. You can achieve the “show in percent” by dividing the standard metric by the same metric with “`BY ALL OTHER`” (meaning the total overall number). You can then achieve the filtering to TOP 20 with
HAVING TOP(20) IN (metric)
condition. The trick is to use
HAVING
instead of
WHERE
, this causes the filter to be applied after the inner metric is calculated and therefore it won’t affect the percentages and their base. So something like this should work:
Copy code
SELECT
  SUM({fact/devices_seen}) / (SELECT SUM({fact/devices_seen}) BY ALL OTHER)
  HAVING TOP(20) IN (SELECT SUM({fact/devices_seen}))
🙌 1
Alternatively in GoodData Cloud you could use the “Top/Bottom Values” filter in the visualization. But for some reason when you use this, it won’t allow you to select the “show as %” so you would need to use the first half of my previous metric anyways. To enable the “Top/Bottom Values” filter: • you need to click the filter icon • then check the “top/bottom values” • then click apply • in the popup that opens, set TOP and 20 • set which metric should be used for the calculation This will also work with the HAVING logic so it won’t mess with the base of your percentages.
p
Hi @Michal Hauzírek, first MAQL works perfect. Thank you!
1