Add A Filter For Pivoted "Percent of Row" Calculation

I am trying to create a filter so that my dashboard users have the ability to filter out servers with a low sample percentage. My data is sample percentage over time, pivoted by server name.

Initially, I calculated sample percentage by using the 'percent of row' table calculation on my 'count distinct' measure. I ran into trouble since you can't add a filter for table calculations. I tried to create a custom filter, but 'count distinct' is a measure and thus I can't.
So, I created a measure within lookml that calculates the percentage sample for me:

measure: percent_of_dvc_count {
sql: ${count_distinct} / SUM(${count_distinct}) OVER (PARTITION BY ${time});;
type: number
value_format_name: percent_0
}

This works, but when I try to filter on this within my explore I get the error:
Analytic function not allowed in HAVING clause at [104:67]
for this line in question in the SQL query that Looker has created:


HAVING ((( (COUNT(DISTINCT bq_ookla_overview_view.id )) / SUM((COUNT(DISTINCT bq_ookla_overview_view.id ))) OVER (PARTITION BY (FORMAT_TIMESTAMP('%F %T', bq_ookla_overview_view.ts_rslt , 'America/New_York'))) )) > 30))

I again can't create a custom filter on my measure since it's a measure. So I tried to define a filter directly within lookml as follows:

filter: percent_over_five {
type: yesno
sql: (${count_distinct} / SUM(${count_distinct}) OVER (PARTITION BY ${time})) > 0.05 ;;
}

But I then receive this error:
invalidQuery: Aggregate function COUNT not allowed in WHERE clause at [89:296]

Is there any way to achieve this filter? I need the window function or my percentage isn't accurate. Even when I move SUM(${count_distinct}) OVER (PARTITION BY ${time})) to a seperate intermediate measure, I still receive the 'having' error. 

0 1 132
1 REPLY 1

I think the way to resolve this is to make a dimension of the measure you are trying to apply the filter to. You can calculate the percentages in a derived table, join that back to your explore, and then the users can filter on the percentage exactly as they would any other dimension.

Top Labels in this Space
Top Solution Authors