Skip to content

Commit c76aae0

Browse files
Add chart filter user attribute documentation (#396)
Documents the new chart filter feature that allows using ${lightdash.user.email} and ${lightdash.attribute.<name>} in filter values. This enables dynamic filtering based on the logged-in user's attributes. --- Created by Mintlify agent
1 parent ca6fc87 commit c76aae0

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

references/workspace/user-attributes.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ User attributes can be used in these specific contexts within the model.yaml fil
5252
- `any_attributes:` - For column and table access control (OR logic - at least one condition must match)
5353
- `sql_on:` - For filtering joins
5454

55+
User attributes can also be used in:
56+
57+
- **Chart filter values** - Filter charts dynamically based on the logged-in user
58+
5559
<Info>
5660
User attributes cannot currently be referenced inside`sql:` tags within the model YAML files.
5761
</Info>
@@ -107,6 +111,23 @@ When referencing user attributes in SQL you can use the following [SQL variables
107111
If you are self hosting you can enable [SMTP](/self-host/customize-deployment/configure-smtp-for-lightdash-email-notifications) or [SSO](/self-host/customize-deployment/use-sso-login-for-self-hosted-lightdash) authentication to allow users to verify their email address.
108112
</Info>
109113
114+
### Using user attributes in chart filter values
115+
116+
You can reference user attributes directly in chart filter values to create dynamic filters based on the logged-in user. This is useful for creating charts that automatically filter to show only data relevant to the current user.
117+
118+
To use a user attribute in a filter value, enter one of the following references:
119+
120+
- `${lightdash.user.email}` - The logged-in user's email address
121+
- `${lightdash.attribute.<attribute_name>}` - A custom user attribute value
122+
123+
For example, if you have a chart showing sales data and you want each user to only see their own records, you can add a filter where `sales_rep_email` is equal to `${lightdash.user.email}`. When the chart runs, the filter value will be replaced with the actual email of the logged-in user.
124+
125+
Similarly, you can use custom attributes like `${lightdash.attribute.country}` to filter data based on a user's assigned region or department.
126+
127+
<Info>
128+
If a user attribute referenced in a filter value is not set for the current user, the query will return a `Forbidden` error.
129+
</Info>
130+
110131
### Row filtering with `sql_filter`
111132

112133
Row-level security (RLS) in Lightdash is implemented using the `sql_filter` property combined with user attributes. This allows you to restrict which rows each user can see based on their attributes.
@@ -637,4 +658,4 @@ Let's walk through an example:
637658
</Tab>
638659
</Tabs>
639660

640-
In this example, the `${lightdash.attributes.fruit}` will be replaced with `'kiwi','orange','coconut'`. The final SQL will be `my_model.fruit IN ('kiwi','orange','coconut)`
661+
In this example, the `${lightdash.attributes.fruit}` will be replaced with `'kiwi','orange','coconut'`. The final SQL will be `my_model.fruit IN ('kiwi','orange','coconut)`

0 commit comments

Comments
 (0)