Share custom dimension between different views to avoid rewrite

My use case is the following:

I have many views with a “country” dimension that is populated with ISO-8601 country codes, I would like to create another dimension at LookML level to avoid having to re-write the mapping and edit it in a single place in case I forgot or want to modify a mapping.

My first solution works and consists in writing a dimension with a sql CASE like so:

dimension: country_name {

  type: string

  map_layer_name: countries

  sql:

      CASE

        WHEN ${TABLE}.country = "IT" THEN "Italy"

        WHEN ${TABLE}.country = "DE" THEN "Germany"

        WHEN ${TABLE}.country = "ES" THEN "Spain"

        WHEN ${TABLE}.country = "FR" THEN "France"

        WHEN ${TABLE}.country = "AT" THEN "Austria"

        …

}

I would like to include this code in every view withouth repeating it, is there a way to include this code in my views, have a common view to derive this field from? or am I missing something else entirely?

0 1 185
1 REPLY 1
Top Labels in this Space
Top Solution Authors