Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.

Is it possible to extend two views and use a LookML parameter in the extended view?

I have two views:

  • country.view
view: country {
sql_table_name: my_project.my_dataset.country_table ;;

dimension: geo_country {
type: string
sql: ${TABLE}.Geo_Country ;;
}

dimension: dim_spend {
type: number
sql: ${TABLE}.Spend ;;
hidden: yes
}

measure: spend {
type: sum
sql: ${dim_spend} ;;
}
}


  • county.view
view: county {
sql_table_name: my_project.my_dataset.county_table ;;

dimension: geo_county {
type: string
sql: ${TABLE}.Geo_County ;;
}

dimension: dim_spend {
type: number
sql: ${TABLE}.Spend ;;
hidden: yes
}

measure: spend {
type: sum
sql: ${dim_spend} ;;
}
}

I created a view called demo_extensions.view (which extends country.view and county.view) with a parameter inside to filter by country or county. Here the code:

include: "country.view.lkml"
include: "county.view.lkml"

view: demo_extensions {
extends: [country, county]

parameter: dimension_picker {
type: unquoted
allowed_value: {
label: "Country"
value: "Country"
}
allowed_value: {
label: "County"
value: "County"
}
}

dimension: dimension_from_picker {
sql: {% if dimension_picker._parameter_value == "Country" %} ${geo_country}
{% elsif dimension_picker._parameter_value == "County" %} ${geo_county}
{% endif %};;
}

dimension: geo_country {
type: string
}

dimension: geo_county {
type: string
}

measure: spend {
type: sum
}
}

When i explore demo_extensions and filter by "Country" using the filter created via parameter, this error returns:

Query execution failed: - Name Geo_Country not found inside demo_extensions

The query executed is this:

SELECT
demo_extensions.Geo_Country AS demo_extensions_dimension_from_picker
FROM project.dataset.county_table AS demo_extensions
GROUP BY
1

I don't understand why it takes from the second extended view (county) and not from the first (country).

I've read in the documentation that in case of conflicts between elements in the extends parameter, the last element is given priority. But if so, what conflicts are there in my code?
Can someone help me?

Thank you!

Solved Solved
0 7 1,906
1 ACCEPTED SOLUTION

Hi Greta,

Actually you don’t need to go with extensions to do what you want to do.

Just use a single view with the liquid code into the `sql_table_name:` tag. You even could also use the liquid into each dimension if the column names from `country` and `county` tables would be different in some cases.

view: county_or_country {
sql_table_name:
{% if dimension_picker._parameter_value == "Country" %}
my_project.my_dataset.country_table
{% elsif dimension_picker._parameter_value == "County" %}
my_project.my_dataset.county_table
{% endif %}
;;

parameter: dimension_picker {
type: unquoted
allowed_value: {
label: "Country"
value: "Country"
}
allowed_value: {
label: "County"
value: "County"
}
}

dimension: dim_country {
type: string
sql:
{% if dimension_picker._parameter_value == "Country" %}
${TABLE}.country
{% elsif dimension_picker._parameter_value == "County" %}
NULL
{% endif %}
;;
hidden: yes
}

dimension: dim_county {
type: string
sql:
{% if dimension_picker._parameter_value == "Country" %}
NULL
{% elsif dimension_picker._parameter_value == "County" %}
${TABLE}.county
{% endif %}
;;
hidden: yes
}

dimension: dim_county_or_country {
type: string
sql:
{% if dimension_picker._parameter_value == "Country" %}
${TABLE}.country
{% elsif dimension_picker._parameter_value == "County" %}
${TABLE}.county
{% endif %}
;;
hidden: yes
}

}

Hope this helps.

View solution in original post

7 REPLIES 7
Top Labels in this Space