Jing
07/10/2023, 7:28 PMMoises Morales
07/10/2023, 7:53 PMJing
07/10/2023, 7:55 PMJing
07/10/2023, 8:08 PMMoises Morales
07/10/2023, 8:52 PMSELECT SUM (sales_rank) WHERE (SELECT SUM (sales_rank) BY customer_id) = 1
and add the count metric to the insight separately.Jing
07/10/2023, 9:03 PMSELECT COUNT(customer_id) WHERE (SELECT SUM (sales_rank) BY customer_id) = 1
? the goal of this metric is to count customer_id with sales_rank=1. My use case is that each customer_id may have multiple sales_rank. example dataset : customer_id sales_rank date
abc 1 5/1/23
abc 2 5/2/23
abc 3 5/3/23
cde 1 6/1/23. Could you elaborate the computation of (SELECT SUM (sales_rank) BY customer_id) = 1
does it select all customers with sales_rank=1? what is the logic behind it?Moises Morales
07/10/2023, 9:38 PMMichal Hauzírek
07/11/2023, 8:27 AMsales_rank
in your data as a fact, the filter for such fact should work both in GoodData Cloud and GoodData Platform.
It will only work within a MAQL metric (i.e. not as a dropdown filter) and in case of GoodData Platform, the computation performance might be a bit worse than if it was an attribute (in GD Cloud it depends how you index your tables).
It will also only work if WHERE part is structurally applicable to the metric after SELECT in that particular LDM, but if I understood it correctly, you have both the customer_id
and sales_rank
in the same dataset, so that should be the case and something like SELECT COUNT({attribute/customer_id}) WHERE {fact/sales_rank}=1
should work. And in my simple test it worked for me.
Is it a simple metric like this that is not working for you or something more complex that also involves other datasets?
And what is the data type of the fact in your database? Can’t something like WHERE {fact/sales_rank}=1.0
help?
Lastly - is the sales_rank really recognized as a fact by GoodData (i.e. does it have green “123” icon in the Analyze tab)? I can imagine if it was for some reason an attribute and in GD Platform you would use it in a filter and manually wrote a number after the “=” and not selected it from the value list, such filter would get ignored. But here I am really just guessing what might be wrong.