Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
novel
Frequent Visitor

DYNAMIC RLS Setup based of SEARCH STRING Function

I have two tables, Table A and Table B.

  • Table A contains a column with primary keys assigned to specific users.

    • USER1: abcd-efg-hij
    • USER2: efg-hij-klm
    • USER1: jdgd-fgsy-jdsfs

    A single user can have multiple unique keys.

  • Table B contains keys that originate from Table A but with added extensions. For example:

    • abcd-efg-hij-kjfekbk-djbbjf-mnjd → CHINA
    • abcd-efg-hij → AUSTRIA
    • efg-hijwrd-sajd-wqeye → INDIA
    • efg-hij-klm-sdfbksdb-dfshd → MEXICO
    • hij-klm → BRAZIL
    • hij-klm-kbfekbfk → CHILE

Goal

I want to set up Row-Level Security (RLS) so that when a user logs in:

  1. Table A filters the keys based on the assigned user.
  2. Table B should be filtered to include any rows where the key contains a partial match with the keys from Table A.

Example

If USER1 has the key abcd-efg-hij in Table A, then Table B should be filtered to include:

  • abcd-efg-hij-kjfekbk-djbbjf-mnjd → CHINA
  • abcd-efg-hij → AUSTRIA

 

I used `CONTAINSSTRING`, but the `MAX` function restricts the search to a single key at a time, preventing the expected outcome. It worked fine when a user had only one key, but for users with multiple keys, it only considers the maximum value, causing incorrect filtering.

----------------------------------------------------------------------------------------

Filter_Territory_Keys =

VAR _user_terr =
    CALCULATE(
        MAX(TABLE_A[KEY]),
        TABLE_A[EMAIL] = USERPRINCIPALNAME()
    )

VAR _filter_for_str =
    CONTAINSSTRING(
        MAX(TABLE_B[KEY]),
        _user_terr
    )

RETURN
IF( _filter_for_str, MAX(TABLE_B[COUNTRY]), BLANK())
---------------------------------------------------------------------------------------------------------------------

Please suggest any possible solution. 
2 REPLIES 2
Anonymous
Not applicable

Hi @novel ,

 

Pls has your problem been solved? If so, accept the reply as a solution. This will make it easier for the future people to find the answer quickly.
If not, please provide a more detailed description.
Best Regards,
Stephen Tao

 

lbendlin
Super User
Super User

Use GENERATE to iterate dynamically over all strings.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.