The filter "Xxxx" is not allowed when using liquid parameter in dynamic derived tables

Mincho
New Member

Hello,

I have a problem, I am trying to dynamically query column from the database, I wish to create a parameter where users can use it as a drop down to select which column they wish to select however no matter how I put my parameter (quoted/string, etc) I am unable to do so.

So I have tried several ways but the erros I either get is that it is either quoted cause its a string or whenever it is not quoted (regardess if we have the sum inside or outside the parameter) we have `The filter "${sales^_price}" is not allowed.`

This is really driving me insane.

derived_table: {
    sql:
    with cte as (
      select
          long_week,
          day,
          sum({% parameter kpi_value %})  as parameter
          --sum(quantity) as parameter,
          --sum(total_gbp_latest) as gross_total_gbp,
          --sum(total_gbp_latest - total_tax_gbp_latest) as next_total_gbp,


      from "REPORTING"."FACT_ORDER_LINE" fact_order_line
      full outer join "REPORTING"."DIM_CALENDAR"  dim_calendar
          on (TO_CHAR(TO_DATE(fact_order_line."DATE_CREATED" ), 'YYYY-MM-DD')) = (TO_CHAR(TO_DATE(dim_calendar."DATE" ), 'YYYY-MM-DD'))
      WHERE (fact_order_line."STATUS" ) IN ('completed', 'paid', 'pending', 'processing', 'partially_refunded')  and is_returned = FALSE and is_refunded = FALSE and is_gifting = FALSE
      group by
          1,2
      order by long_week desc nulls last limit 200
      )
      select
          p.long_week,
          p.mon,
          p.tue,
          p.wed,
          p.thu,
          p.fri,
          p.sat,
          p.sun
      from cte
          pivot(sum(parameter) for day in ('MON','TUE','WED','THU','FRI','SAT','SUN')) AS P (long_week, mon, tue, wed, thu, fri, say, sun)
          order by long_week desc
          ;;
  }

  dimension: long_week {
    type: number
    sql: ${TABLE}.long_week ;;
  }


  dimension: MON {
    type: string
    sql: ${TABLE}.mon ;;
  }

  dimension: TUE {
    type: string
    sql: ${TABLE}.tue ;;
  }

  dimension: WED {
    type: string
    sql: ${TABLE}.wed ;;
  }

  dimension: THU {
    type: string
    sql: ${TABLE}.thu ;;
  }

  dimension: FRI {
    type: string
    sql: ${TABLE}.fri ;;
  }

  dimension: SAT {
    type: string
    sql: ${TABLE}.sat ;;
  }

  dimension: SUN {
    type: string
    sql: ${TABLE}.sun ;;
  }

  parameter: kpi_value {
    type: unquoted
    allowed_value: {
      label: "Sales Units"
      value: "quantity"
    }
  }
0 1 1,004
1 REPLY 1

Mincho
New Member

Fixed with
following column in derived table

 CASE
            WHEN {% parameter kpi_value %} = 'quantity' then sum(quantity)
            WHEN {% parameter kpi_value %} = 'total_gbp_latest' then sum(total_gbp_latest)
            ELSE NULL
            END as parameter_value

and parameter

  parameter: kpi_value {
type: string
allowed_value: {
label: "Sales Units"
value: "quantity"
}
allowed_value: {
label: "Gross GBP"
value: "total_gbp_latest"
}
Top Labels in this Space
Top Solution Authors