Parametrised values not working as expected

Hi,

I’m trying to use parameters to switch between different columns in a visualisation. So the user can select measure `a`, `b` or `c` as desired.

I’ve created the parameters as required below (with aliases used for field labels/values):

  parameter: new_parameter {
type: unquoted
allowed_value: {label: "a label"
value: "a"}
allowed_value: {label: "b label"
value: "b"}
allowed_value: {label: "c label"
value: "c"}
default_value: "a"
}

Then the associated measure:

  measure: new measure {
type: sum
sql: ${TABLE}.{% parameter new_parameter %} ;;
}

But when I try and run these I get a message to the affect of “Name a not found inside of Table”. This is in spite of the measures used working fine in other contexts. Any ideas why this may be happening? Help is greatly appreciated!

Solved Solved
1 5 452
1 ACCEPTED SOLUTION

Yes, there’s another way of doing it but a bit more code, unfortunately..

measure: new_measure {
sql:
{% if new_parameter._parameter_value == "a" %}
${a}
{% elsif new_parameter._parameter_value == "b" %}
${b}
{% endif %} ;;
}

You’re losing the dynamic part because you can’t inject the name of the parameter, which means every time you add a new allowed_value, you have to remember to add another elsif..

View solution in original post

5 REPLIES 5
Top Labels in this Space