1. Lighthouse

Level 4 · A row-level security role for the West

The request

From Gregory Hall, West Region Sales Director

“My two West Coast leads are getting the sales report next week. They should see customers in California, Oregon and Washington and nothing else: not their sales, not their customer counts, not a single row from other states.”

Your goal

Write the rule for a role called West on the customers table: keep the rows whose customers[state] is CA, OR or WA. The visual shows the Sales and Customers each member of the role sees.

  • Each user sees only their rows: check every line of the visualnot done yet

Your role rule

Security role
Visual
A card of [Sales], [Customers] for each user
Measures in the report
Sales = CALCULATE(SUM(order_items[line_total]), orders[status] = "completed")Customers = COUNTROWS(customers)
Data pane: tables and columns
  • order_items order_item_id, order_id, product_id, quantity, unit_price, discount_pct, line_total
  • orders order_id, customer_id, order_date, status, channel, shipping_fee, coupon_code
  • products product_id, name, category, subcategory, unit_price, unit_cost, launched_on, is_active
  • customers customer_id, first_name, last_name, email, city, state, signup_date, segment, referral_source
  • returns return_id, order_item_id, returned_on, reason, refund_amount
  • Date Date, Year, Quarter, Month Number, Month, Year Month, Year Quarter, Day, Weekday Number, Weekday

Loading the editor…

    VisualBefore your rule, every user sees everything
    The visual before your answer
    UserSalesCustomers
    Kayla Simmons (West)5,894,284.442,018
    Jason Reyes (West)5,894,284.442,018

    Mote checks your result

    Press Check. Mote fills in your answer and compares it with what the report needs.

    The lesson

    Row-level security (RLS) hides rows of data from people who shouldn’t see them. You define roles in Power BI Desktop; each role holds a rule per table, a DAX expression that returns TRUE or FALSE for every row. Members of the role see only the rows where the rule says TRUE, and every visual, total and export follows.

    What you are working in

    This page is a practice tool, not Power BI. You write the rule for one role on the customers table; the engine runs it on every customer, then fills the visual with what each member of the role would see: their Sales and their number of Customers. It follows Power BI’s rules, so a rule that works here works there.

    To do it for real in Power BI Desktop: Modeling → Manage roles → New, name the role West, select the customers table, and either build the filter in the drop-down editor (state is one of CA, OR, WA) or select Switch to DAX editor and type the rule below. Press Save. To check it, Modeling → View as, tick West, OK: the whole report now shows what the role sees, with a yellow bar until you Stop viewing.

    The rule

    customers[state] IN {"CA", "OR", "WA"}

    IN { … } tests whether the value is one of a list. It is shorter and clearer than chaining ORs:

    customers[state] = "CA" || customers[state] = "OR" || customers[state] = "WA"

    Both keep the same rows. Text comparisons in DAX ignore case, so "ca" would match too.

    One rule, every table

    You only filter customers, yet Sales shrinks as well. A security filter behaves like a filter from a slicer that nobody can clear: it flows from the one side of each relationship to the many side. Customers filters orders, orders filters order lines, and every measure built on them sees West data only. That is why rules belong on small dimension tables: one short rule, and the star schema carries it everywhere.

    The opposite direction is not filtered by default. A West member still sees all 120 products in the product list, because products sits on the one side of its relationship with order_items. Usually that is fine (product names aren’t secret); if it isn’t, the products table needs its own rule.

    Roles are not people

    Desktop defines what each role can see. It doesn’t decide who is in it: you add people and groups to roles in the Service after publishing (a later level). A static role like this one needs a role per region, so with ten regions you maintain ten roles and ten lists. The next level replaces them with one dynamic rule.

    Common mistakes

    • A value, not a test. customers[state] on its own isn’t TRUE or FALSE.
    • Rules on the fact table. Filtering order_items row by row works, but it is slower and leaves customers and orders unfiltered.
    • Testing as yourself. As the report’s author you see everything; use View as.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.