Knowledge Drop

Can I use/reference a `parameter:` of type: number in a liquid statement?

  • 5 April 2021
  • 0 replies
  • 196 views

Userlevel 5

Last Tested: Nov 6, 2020

 

Yes, you can do this using the assign Liquid syntax.

For example:

parameter: parameter_value_to_pass {

type: number

}

 

measure: my_measure {

type: sum

sql: ${TABLE}.<FIELD>;;

html: {% assign var=_filters['parameter_value_to_pass'] | plus: 0 %}

{% if value < var %}

<div style="color: blue">{{ value }}</div>

{% else %}

<div style="color: orange">{{ value }}</div>

{% endif %} ;;

}

 

Where | plus: 0 casts the var value from String to Integer. You could could also use | times: 1.

ex.

html: {% assign var=_filters['parameter_value_to_pass'] | times: 1 %}

 

There is also an alternate option for this which is to pass the parameter through a dimension and then reference the dimension in the { } liquid.

You can also use type: unquoted.

ex.

parameter: threshold {

type: unquoted

default_value: "5"

}

 

dimension: over_threshold {

type: yesno

sql: ${FIELD} > {% parameter threshold %} ;;

}

 

This content is subject to limited support.                

 


0 replies

Be the first to reply!

Reply