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
Sure, here are a few suggestions on how to achieve this:
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:
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:
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:
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:
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:
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:
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