Can I use a user_attribute for a filter title on LookML dashboard?

hello, I have a customizable dimension label based on a user attribute and I am having trouble using that value as a filter title in a LookML dashboard. Any help or direction is appreciated. 

for example I have a dimension such as this:

  dimension: department {
    label: "{{ _user_attributes['ua_department'] }}"
    type: string
    sql: ${TABLE}.department ;;
  }

Where the label can be various values that have context for our users (team, division, squad, etc). This works as expected when users view an SSO embedded url dashboard with the relevant user attribute attached. The values within the dashboard reflect the label of the dimension that the user expects to see. 

However, If a dashboard is created that uses that dimension as a filter, the filter title will reflect whichever value that dimension has for the original user that created the dashboard. So, in many cases, the filter does not have meaningful context for the viewer. 

I am using LookML dashboards so the LookML ends up with a hard coded value for the filter title

  filters:
  - name: Division
    title: Division
    type: field_filter
    default_value: ''
    allow_multiple_values: true
    required: false
    ui_config:
      type: advanced
      display: popover

instead of "Division", I want the title and name of the filter to be the value of {{ _user_attributes['ua_department'] }}

Can anyone offer any suggestions on how to achieve this? Thank you

1 2 386
2 REPLIES 2

Roderick
Community Manager
Community Manager

Sure, here are a few suggestions on how to achieve this:

  • Use a LookML macro. A LookML macro is a reusable piece of code that can be used to generate LookML. In this case, you could create a macro that generates the filter definition, but with the title and name replaced by the value of the user attribute.
  • Use a LookML function. A LookML function is a piece of code that can be used to evaluate expressions and generate LookML. In this case, you could create a function that evaluates the user attribute and returns the value. You could then use this function to set the title and name of the filter.
  • Use a LookML template. A LookML template is a file that contains LookML code that can be used to generate other LookML files. In this case, you could create a template that contains the filter definition, but with the title and name replaced by placeholders. You could then use this template to generate the filter definition for each user.

Which approach you choose will depend on your specific needs. If you only need to generate a few filters, then using a macro or function may be the easiest option. If you need to generate a large number of filters, then using a template may be the best option.

Here is an example of how you could use a LookML macro to generate the filter definition:

Code snippet
macro: department_filter() {
  title: "{{ _user_attributes['ua_department'] }}"
  name: "{{ _user_attributes['ua_department'] }}"
  type: field_filter
  default_value: ''
  allow_multiple_values: true
  required: false
  ui_config:
    type: advanced
    display: popover
}

You could then use this macro in your LookML like this:

Code snippet
filters:
  - name: "Department"
    type: department_filter()

This would generate the filter definition with the title and name replaced by the value of the user attribute.

Here is an example of how you could use a LookML function to generate the filter definition:

Code snippet
function: department_filter(user_attribute) {
  title: user_attribute
  name: user_attribute
  type: field_filter
  default_value: ''
  allow_multiple_values: true
  required: false
  ui_config:
    type: advanced
    display: popover
}

You could then use this function in your LookML like this:

Code snippet
filters:
  - name: "Department"
    type: department_filter(_user_attributes['ua_department'])

This would generate the filter definition with the title and name replaced by the value of the user attribute.

Here is an example of how you could use a LookML template to generate the filter definition:

Code snippet
template: department_filter.lookml {
  title: "{{ user_attribute }}"
  name: "{{ user_attribute }}"
  type: field_filter
  default_value: ''
  allow_multiple_values: true
  required: false
  ui_config:
    type: advanced
    display: popover
}

You could then use this template to generate the filter definition for each user like this:

Code snippet
filters:
  - name: "Department"
    type: department_filter(_user_attributes['ua_department'])

This would generate the filter definition with the title and name replaced by the value of the user attribute.

I hope this helps!

 

I'm sorry, these sound like great solutions but almost seem to be generated by AI (the tell is the warning that the code snippets are generated by AI). I really hope these are true but I can't find any documentation regarding LookML macros, templates, nor functions. 

Where would I define the macro, function or template? In the model, view or dashboard? Thanks

 

Top Labels in this Space
Top Solution Authors