Liquid syntax

Lor26
New Member

Hello everyone,

I can’t understand why the following block of code works(First Block) while the one below(Second Block), using the equivalent liquid syntax doesn’t, what did I do wrong ?

Remark 1: I tried both blocks of code independently, not together.

Remark 2: The second block of code returns only the else clause so is always considered count regardless of the parameter filter metric_selector.

Remark 3: Obviously I’ve defined a parameter with allowed values and two measures before in the view.

Remark 4: The question pertains the more the Liquid syntax I’ve used since I think the error is there.

First Block:

measure: metric {

    label_from_parameter: metric_selector
    type: number
        sql:
        CASE
          WHEN {% parameter metric_selector %} = 'total_cost' THEN ${total_cost}
          WHEN {% parameter metric_selector %} = 'count' THEN ${count}
          ELSE NULL
        END ;;
  }
  

Second Block:
  measure: metric {
    
    label_from_parameter: metric_selector
    type: number
        sql: 
        {% if metric_selector._parameter_value == "total_cost" %}
        ${total_cost}
        {% else %}
        ${count}
        {%endif%};;
  }

Thank you !

Solved Solved
0 1 555
1 ACCEPTED SOLUTION

Lor26
New Member

I solved this problem today.

Basically, I had created a parameter called metric_selector of type String: so, when we reference about a value of a string parameter inside a liquid clause {% text here %} we have to use “’some_text’”.

The Second Block works fine in this way:

Second Block Corrected:
  measure: metric {
    
    label_from_parameter: metric_selector
    type: number
        sql: 
        {% if metric_selector._parameter_value == "’total_cost’" %}
        ${total_cost}
        {% else %}
        ${count}
        {%endif%};;
  }

Otherwise, without correcting anything from the original Second Block of the question is sufficient to change the type of the Paramter metric_selector from String to Unquoted.

Remark: Using an unquoted parameter there’s this thing to consider: in the allowed values it’s not possible to use a space to separate two words .

View solution in original post

1 REPLY 1

Lor26
New Member

I solved this problem today.

Basically, I had created a parameter called metric_selector of type String: so, when we reference about a value of a string parameter inside a liquid clause {% text here %} we have to use “’some_text’”.

The Second Block works fine in this way:

Second Block Corrected:
  measure: metric {
    
    label_from_parameter: metric_selector
    type: number
        sql: 
        {% if metric_selector._parameter_value == "’total_cost’" %}
        ${total_cost}
        {% else %}
        ${count}
        {%endif%};;
  }

Otherwise, without correcting anything from the original Second Block of the question is sufficient to change the type of the Paramter metric_selector from String to Unquoted.

Remark: Using an unquoted parameter there’s this thing to consider: in the allowed values it’s not possible to use a space to separate two words .

Top Labels in this Space
Top Solution Authors