Articles

Row-level security (RLS): one report, everyone sees their own

How to set up RLS in Power BI, Tableau and the database: static and dynamic rules, access tables, hierarchies, common leaks and how to test it works.

21 min readSergiy Belyakov

A regional manager should see their region, a facility director their facility, and the head office analyst the whole network. The usual answer is copies: a separate report for each audience. Six months later there are twenty copies, the formulas differ, and the meeting once again starts with whose number is right.

Row-level security (RLS) solves this differently. One report, one model, and each user sees only the rows they are entitled to. Below is how it works in Power BI, Tableau and the database, where rules usually leak and how to test that they work.

What RLS is

RLS is a rule that filters rows of data depending on who opened the report. The rule lives in the data model or in the database, not on the report page. That is why another filter, a new visual or a user's own report on the same model cannot get around it.

OlenaKyiv regionTarasLviv regionIrynaOdesa regionRegionFacilityAmount, kKyivHospital 1420LvivPolyclinic 3310OdesaHospital 7270KyivPrimary care150LvivHospital 2190OdesaOutpatient80One model: everyone sees only their own rowsOlena sees 2 of 6 rows, total 570Taras sees 2 of 6 rows, total 500Iryna sees 2 of 6 rows, total 350
A made-up example. One report and one model; the rule decides which rows each user sees.

An analogy: a pass in a building with a single entrance. One building, but doors open only where you are allowed. The analogy is imperfect, because you can at least see the doors you cannot open, while a user never sees other people's rows at all: for them those rows do not exist, and totals are calculated from their part only.

What RLS does not do

RLS limits rows. Other mechanisms limit everything else, and they are often confused.

What needs limiting How it is done
Which records a person sees (their region, their facility) RLS
Whether a person sees a table or a column (for example "Salary") object-level security (OLS)
Which report pages are visible hidden pages, app audiences: this is navigation, not protection
Whether a person can open the report at all workspace, app or project permissions

A hidden page does not protect data. The model will return the same rows to anyone who is allowed to build their own reports on it.

Static and dynamic rules

A static rule is a separate role for each value: a role "Lviv" with the filter [Region] = "Lviv". Easy to start with. But 24 regions mean 24 roles, and every person has to be added to the right role by hand.

A dynamic rule is one role and an access table: the user's email and the region open to them. The rule takes whoever signed in and looks them up in the table. A new employee means a new row in the table, not a change to the model.

rule on the dimensionrelationship 1 → ∞Who opened the reportUSERPRINCIPALNAME() = olena@…Access tableolena@… → KyivRegions (dimension)only Kyiv remainsSales (facts)only Kyiv rows
Dynamic RLS: the rule finds the user in the access table, filters the dimension, and the ordinary relationship carries the filter to the facts.

In Power BI it is convenient to put this rule on the region dimension:

[RegionKey] IN
    CALCULATETABLE (
        VALUES ( 'Access'[RegionKey] ),
        'Access'[Email] = USERPRINCIPALNAME ()
    )

From there the filter flows through the ordinary one-to-many relationship into the fact table, as in a star schema. You can instead relate the access table to the dimension, but then the filter has to travel against the relationship. By default security filters flow in one direction only, so you need the "Apply security filter in both directions" setting. It works, but this is exactly where most mistakes happen, and on large models it slows queries down.

The access table is data too. It needs an owner (usually HR or the process owner), a source and a refresh date. Otherwise a person who has left keeps seeing their region for another month, and a new one sees nothing.

Hierarchies: a manager sees their teams

A department head should see all regions, a regional manager all facilities in the region, a facility director only their facility. The simplest approach is to store a level and a code in the access table. The row "olena@… → region 32" opens all facilities of that region through the dimension, the row "taras@… → facility 3205" opens just one facility.

For arbitrary hierarchies (units within units of unknown depth) DAX has the PATH and PATHCONTAINS functions: the rule checks whether the user's unit sits on the path from the root to the row.

Tableau and databases

Tableau. The simplest option is a user filter, but for many people an entitlement table is more practical: join it to the data and add a data source filter USERNAME() = [Username], or ISMEMBEROF("group") for groups. With Data Management you can keep the rules centrally in data policies on virtual connections, and every workbook inherits them.

Database. In PostgreSQL this is ALTER TABLE … ENABLE ROW LEVEL SECURITY plus CREATE POLICY with a condition on the user. Note that the table owner and superusers bypass policies unless you turn on FORCE ROW LEVEL SECURITY. In SQL Server and Azure SQL it is CREATE SECURITY POLICY with a predicate function.

A rule in the database protects data for every tool at once: BI, Excel, APIs. But a BI model in import mode reads the database with a single technical account, so the database rule only ever sees that account. Passing the actual report viewer to the database is possible only in DirectQuery with single sign-on (SSO), and not for every source. That is why the rule is usually repeated in the model for reporting.

Where RLS usually leaks

  1. A filter in a visual instead of a rule. A slicer, bookmark or page filter is a convenience. Anyone who can edit the report will simply remove it.
  2. Workspace permissions. In Power BI RLS applies only to Viewers. Admins, Members and Contributors can edit the model and see everything. Managers who should see only their part get the Viewer role or access through an app.
  3. Share of total. ALL() does not remove RLS, so "share of the whole network" is calculated from the visible part. A regional manager sees 100% where the network share is 8%. If a comparison with the network is needed, prepare network totals as a separate aggregated table without detail and deliberately leave it unrestricted.
  4. A new user. "Not in the table, show everything" is the worst rule. The right default: no access row, no data. In Power BI a person without a role in a model with RLS sees empty reports.
  5. Guests and a different name format. USERPRINCIPALNAME() returns the sign-in name, which is not always the email. For guests from another organisation it can look like user_partner.com#EXT#@…, and the rule will not find them in the table.
  6. Data that has left the model. An exported file, a copy of the model, a separate dataset from the same source without rules. RLS protects only the model where it is set up.
  7. Testing as an admin. The developer sees everything and concludes that it all works.

How to test that the rules work

Role: Kyiv570Role: Lviv500Role: Odesa350Sum of roles1,420Grand total1,4201,4801,420 = 1,420: nobody is lost!New region without a rule: 60 seen by no roleIf the grand total is larger than the sum of roles, some rows are seen by nobody
Made-up numbers. The simplest RLS test: what all roles see adds up to the grand total.
  1. Look through a role's eyes. In Power BI Desktop it is "View as", in the service "Test as role" with a specific person selected. Take one person from each level of the hierarchy.
  2. Test accounts with the Viewer role. That is how managers will see the report.
  3. Reconcile the totals. The sum of what all roles see should equal the grand total. Less means some rows are seen by nobody: a new region, an empty key. More means roles overlap, and that should be a conscious decision.
  4. Check the access table as data. Duplicates, people who have left, emails in different case, guests with a different name format.
  5. Audit once a quarter. Who has workspace permissions and who sits in which roles.

A short checklist

  • One report, no copies for different audiences.
  • The rule lives in the model or the database, not in a page filter.
  • The access table has an owner, a source and a refresh date.
  • No access means no data.
  • Readers have the Viewer role, not Member.
  • Shares and network comparisons are calculated deliberately.
  • Rules tested under real roles, totals reconciled.

Where to start

Take the report that is copied most often for different audiences. Count the copies and write down how they differ. If it is only a filter on region, facility or unit, it is a ready candidate for one report with RLS. How this fits into the wider reporting setup is covered in BI architecture: four options. I help with this as part of business intelligence and data governance.

How many copies of the same report live in your organisation?

A similar problem in your team?

Describe the situation in a few sentences. I will reply with where I would start and whether I can help.

Discuss your project

Short weekly notes on data in the Telegram channel (in Ukrainian): @belyakovconsult

All articles

Glossary