How to add filter in SQL derived table

I have this sql derived table to show the distinct values of 2 columns (TOP_1 and TOP_2) and I want to add a filter to the dashboard if the "combined_value" is IN the column TOP_1 or TOP_2, for it to work similarly as liquid variables.

view: campaigns_distinct {
derived_table: {
sql:
SELECT DISTINCT combined_value
FROM (
SELECT ARRAY<STRING>[TOP_1] AS combined_value
FROM `project.xxxx.CLIENTS_TOP_CAMPAIGNS`
WHERE TOP_1 IS NOT NULL
UNION ALL
SELECT ARRAY<STRING>[TOP_2]
FROM `project.xxxx.CLIENTS_TOP_CAMPAIGNS`
WHERE CAMPANA_DESC_VTA_2 IS NOT NULL
)
CROSS JOIN UNNEST(combined_value) AS combined_value
WHERE combined_value IN {% condition TOP_1_o_2 %}
;;
}

filter: TOP_1_or_2 {
type: string
default_value: "TOP_1"
suggestions: ["TOP_1","TOP_2"]
bypass_suggest_restrictions: no
}

dimension: combined_value {
type: string
sql: ${TABLE}.combined_value ;;
primary_key: yes
}
}

0 0 85
0 REPLIES 0
Top Labels in this Space
Top Solution Authors