Sub topic 2
Roles and table filter expressions
This chapter covers how a role is built in Power BI Desktop and how its DAX table filter expression decides which rows a member can see. It assumes you can load data and build a report, know the basics of a star schema (fact tables, dimension tables, one-to-many relationships), and can read simple DAX comparisons. You also need a Microsoft Entra ID work or school account and a Power BI workspace for the later steps that happen in the service.
What a role is
A role is a named set of rules stored inside a semantic model. Each rule is attached to one table and contains a DAX expression. When a person who belongs to the role opens a report, Power BI applies those rules before any visual runs its query. Rows that fail the rule are removed from that person's view of the model.
A role has three parts:
- A name, such as
West Sales. The name is how you refer to the role when you test it and assign members. - Zero or more table filters. Each table filter targets one table in the model.
- A list of members. Members are assigned in the Power BI service, not in Desktop. A later chapter covers assignment.
The roles live in the model, so they travel with the .pbix file when you publish it. Publishing does not add any members.
Table filter expressions
A table filter expression is a DAX expression that returns TRUE or FALSE for each row of the table it is attached to. A row is kept when the expression returns TRUE. A row is hidden when it returns FALSE or blank.
The expression is evaluated in row context. That means you can refer to columns of the table directly, as in a calculated column. You do not write FILTER(), and you do not write the table name in front of the filter as a function argument. You write only the condition.
This static filter is attached to a Region dimension table:
[Region] = "West"Power BI evaluates the condition once for every row of Region. Only rows where the Region column equals West remain. Because the filter sits on a dimension table, it also reduces the fact tables related to it. The next chapters explain that propagation in detail. For now, remember that you filter the dimension, and the relationship carries the effect to the facts.
Rules for the expression
- It must return a Boolean value. An expression that returns a number or text is rejected.
- It can use columns from the same table, constants, and functions such as
USERPRINCIPALNAME(). - It can reference other tables through functions such as
LOOKUPVALUE()orCALCULATETABLE(), as later chapters show. - It cannot use measures that depend on the report's filter context in a way you did not intend. Keep the expression simple and based on columns.
- You can leave a table without any filter. A table with no filter in the role is shown in full, subject to filters arriving from other tables.
Common comparison patterns
| Goal | Expression |
|---|---|
| One fixed value | `[Region] = "West"` |
| Several fixed values | `[Region] IN { "West", "Central" }` |
| Exclude a value | `[Region] <> "Internal"` |
| A numeric condition | `[Year] >= 2024` |
| Show everything on this table | `TRUE()` |
The last row is useful when you want a role to be explicit about a table it does not restrict.
Creating a role in Power BI Desktop
Follow these steps in Desktop.
- Open the report and go to the Modeling tab, then select Manage roles.
- Select New and type a role name.
- Select the table to filter, for example
Region. - In the DAX filter box, type the condition, such as
[Region] = "West". - Select Save.
Desktop checks the syntax when you save. If the expression does not return a Boolean, you see an error and the role is not saved.
Keep role names short and descriptive. Names are case-insensitive for matching purposes, but a consistent style makes the list easier to read when you have many roles.
What the filter does at query time
The diagram shows the order of events when a role member opens a report.
The filter is not a visual filter. Users cannot clear it, edit it, or remove it from the report. It also applies to every report and dashboard tile built on the same semantic model, which is the main reason to use RLS instead of report-level filters.
Checking the identity the model sees
Before you write a filter that depends on the user, check which identity the model receives. Add a measure to the model:
Current User = USERPRINCIPALNAME()Place it in a card visual. In Desktop without a role, it usually shows your own sign-in name. When you test a role (a later chapter explains how), it shows the identity you are testing as. This measure is a quick way to confirm that the value you compare against in a filter really matches what the model sees.
The function is introduced here so you can use it for checking. Chapters later in the tutorial use it inside filters, and they also cover how it differs from USERNAME().
Comparing two kinds of filter
You will meet two styles of table filter in this tutorial. Both use the same mechanism, and only the condition differs.
| Style | Example condition | Members of the role |
|---|---|---|
| Static | `[Region] = "West"` | Everyone in the role sees the same rows |
| Dynamic | `[ManagerEmail] = USERPRINCIPALNAME()` | Each member sees rows that match their own identity |
A static filter needs one role for each audience. A dynamic filter can serve many people with one role. A dynamic example, shown here only so you recognise its shape:
[ManagerEmail] = USERPRINCIPALNAME()This expression sits on a table that has a column of email addresses. For each user, only the rows whose ManagerEmail equals that user's sign-in name pass the test.
Behaviors to know
A role with no filters
A role can exist with no table filters at all. Its members then see all rows, because nothing removes any. This is occasionally useful as a "see everything" role, but it is also a common mistake. If you create a role, forget to add a filter, and assign people to it, they are not restricted.
A user who is in no role
If the model has roles defined, a user who is not a member of any role and who does not have a workspace role that bypasses RLS gets no data from the model. Reports show errors or empty visuals. Defining roles does not by itself make the data safe for people you forgot to assign, but it also does not expose data to them.
Blank and unmatched values
If a column contains blanks, the comparison [Region] = "West" returns FALSE for those rows, so they are hidden. If you want to keep blank rows, write that explicitly:
[Region] = "West" || ISBLANK ( [Region] )Check what the data contains before you decide. Rows with unexpected spellings, such as west with trailing spaces, can be missed by an exact comparison. DAX string comparison with = is case-insensitive, but trailing spaces still count, so clean the data in Power Query.
Filtering more than one table in a role
You can attach filters to several tables in the same role. The filters combine with AND logic across tables: a row must be allowed by every filter that applies to it, directly or through relationships. This is stricter than a single filter, and it is a frequent cause of reports that show less than you expect.
Performance
The expression runs for the filtered table on each query. Filters on small dimension tables are cheap. A filter placed directly on a large fact table is more expensive, because Power BI must evaluate the condition for many rows. Prefer filtering dimensions and letting relationships do the work.
Applying a role to a table that is on the "many" side
Filters on a dimension flow to the fact table because the relationship runs from the "one" side to the "many" side. The opposite direction does not happen by default. If you filter the fact table, the dimension table still shows all its rows.
For example, a filter of [Amount] > 1000 on a Sales table removes small sales. A Customer dimension related to Sales still lists every customer, including those with no allowed sales. Users could see the full list of customer names in a slicer. If the names are sensitive, filter the dimension itself instead.
Practical checklist
Use this list when you write a new role.
- Identify the dimension table that holds the attribute you want to restrict.
- Write the condition as a Boolean expression on that table.
- Confirm that a one-to-many relationship connects the dimension to each fact table you want to restrict.
- Add the
Current Usermeasure to a test page. - Test the role before you publish. The next chapters show how.
Exercises
Exercise
You create a role named West Sales with the filter [Region] = "West" on the Region dimension table. A Sales fact table has a one-to-many relationship from Region to Sales. What does a member of this role see in a table visual that lists Sales rows, and why?
Show answer
Only Sales rows whose related Region row is West. The filter removes all other rows from the Region table, and the relationship from Region (one side) to Sales (many side) passes that restriction on to Sales, so Sales rows for other regions are no longer reachable.
Exercise
A colleague adds the filter [Amount] > 1000 to the Sales fact table in a role. They expect that members will see only customers with large sales in a Customer slicer. Will that happen? What would you change?
Show answer
No. A filter on the fact table does not flow to the related dimension, because filters travel from the one side to the many side. The Customer slicer, based on the Customer table, still lists every customer. To restrict customer names, put a filter on the Customer table itself, for example with a condition that identifies the allowed customers.
Exercise
You save a role with a table filter but forget to assign any members in the service. A user with only the Viewer workspace role opens the report. What do they see, and what changes if you instead save the role with no table filters and assign the user to it?
Show answer
With roles defined and the user in none of them, the user gets no data from the model, so visuals are empty or show errors. If the role has no table filters and the user is assigned to it, the user sees all rows, because no filter removes anything.