Default value for dynamic filtered measure

Knowledge Drop

Last tested: Feb 11, 2021
 

If you're creating a dynamic filtered measure like in this article, "if a user does not select a value in the filter-only field, the SQL will default to 1=1 (having no filtering effect on the measures)."

If you want to be able to have a default value for when a user doesn't select a value on the filter, we can use something like this:

filter: status_filter {

type: string

suggest_dimension: status

}

dimension: status_satisfies_filter {

type: yesno

hidden: yes

sql: {% if status_filter._is_filtered %}

{% condition status_filter %} ${status} {% endcondition %}

{% else %}

${status} = "cancelled"

{% endif %};;

}

measure: count_dynamic_status {

type: count

filters: [status_satisfies_filter: "yes"]

}

What you put after the {% else %} will be the default value applied to the filtered measure.

This content is subject to limited support.                

Version history
Last update:
‎07-07-2021 01:12 PM
Updated by: