Sub topic 3
Static roles: one role per audience
This chapter assumes you can load data into Power BI Desktop, you know a star schema (fact tables, dimension tables, one-to-many relationships), and you can read simple DAX comparisons. You also need a work or school account and a workspace for the later publishing step.
What a static role is
A static role is a row-level security (RLS) role whose filter uses a fixed value written into the DAX. Every member of the role sees the same slice of data. If the West sales team and the East sales team need different views, you create two roles: one with "West" in its filter and one with "East".
Static roles are the simplest form of RLS. They suit small, stable audiences. They become a burden when the number of audiences grows, because each new audience needs a new role. Later chapters cover dynamic roles, which avoid that.
Create a static role in Desktop
Assume a model with a Region dimension table related to a Sales fact table. The relationship is one-to-many, with Region on the one side.
- In Power BI Desktop, open the Modeling tab and choose Manage roles.
- Select Create and name the role
West Sales. - Select the
Regiontable. - In the table filter expression box, enter the filter below.
- Save the role.
[Region] = "West"This is a table filter expression. It must return TRUE or FALSE for each row of the table it is attached to. Rows where it returns TRUE stay visible. All other rows are hidden from members of the role.
Repeat the steps with a role named East Sales and the expression [Region] = "East".
How the filter reaches the fact table
You only filtered the Region table, yet members of West Sales also see only West rows in Sales. The filter travels along the relationship from the one side to the many side, in the same direction a slicer on Region would filter Sales.
The reverse is not true. A filter placed on a fact table does not restrict the dimension tables, unless the relationship is set to filter in both directions. For that reason, put static filters on the dimension tables whenever you can.
Worked example
Suppose the Region table contains these rows, and Sales has one row per order.
| Region | Orders in Sales |
|---|---|
| West | 120 |
| East | 95 |
| North | 60 |
A member of West Sales who opens a card showing the count of orders sees 120. A member of East Sales sees 95. A member of neither role, who has been given access to the model through other means, may see all 275 rows, which is why role assignment and workspace roles matter. The service chapters return to this.
Allowing more than one value
A static role can match several values. Use IN with a table constructor:
[Region] IN { "West", "North" }This role suits a manager who covers two regions. Do not write [Region] = "West" || [Region] = "North" unless you prefer it. Both forms work, and IN is easier to extend.
Common mistakes
- Typos in the value.
"west"is matched without regard to case in DAX comparisons, but"Wes"matches nothing. A role that matches nothing gives an empty report, not an error. - Filtering the fact table instead of the dimension. This works for the fact table, but leaves the dimension values visible in slicers and wastes the relationship.
- Hard-coding too many roles. If you find yourself creating a role per person, switch to a dynamic role.
Check your understanding
Exercise
A model has a Product dimension table related one-to-many to a Sales fact table. You want a role named Bikes Only that shows only rows for the Bikes category. Which table do you attach the filter to, and what is the expression? Assume the column is Product[Category].
Show answer
Attach the filter to the Product table with [Category] = "Bikes". The filter then flows through the one-to-many relationship to Sales, so members see only Bikes sales rows.
Exercise
Why does a static role scale poorly when a company has 40 sales regions and each region has its own audience?
Show answer
Each region needs its own role with its own hard-coded value, so you must create, name, and maintain 40 roles and assign members to each one. Adding or renaming a region means editing roles. A dynamic role with a security mapping table handles all regions with one role.