Forum Discussion

kyrpav's avatar
kyrpav
Helper V
1 year ago

Multiple RLS filters in different tables and OR condition

How is it possible to have two tables and apply Or condition filter between these two tables. This means that i want to  filter table A for some record OR at the same time table B to be filter based on something else. Since the tables are connected (i am very very simplifying the structure) to get the Cross Join of filtered A and filtered B

3 Replies

  • saud968's avatar
    saud968
    Memorable Member

    Define Roles: Create a role in Power BI Desktop.
    Use DAX for RLS: Write DAX expressions to define the filters for each table.
    For example, let's say you have two tables, TableA and TableB, and you want to filter TableA based on Column1 and TableB based on Column2. You can use the following DAX expression:

    [Column1] = "Value1" || RELATED(TableB[Column2]) = "Value2"
    This expression filters TableA where Column1 equals "Value1" OR TableB where Column2 equals "Value2". The RELATED function is used to access columns from related tables.

    Apply the Role: Assign the role to the relevant users.
    Example
    Assume TableA and TableB are related through a common key. Here's a more concrete example:

    TableA has columns ID, Name, Column1
    TableB has columns ID, Description, Column2
    The relationship is based on the ID column. The DAX expression for the RLS role might look like this:

    [Column1] = "Value1" || RELATED(TableB[Column2]) = "Value2"
    This will ensure that the filter is applied to both tables with an OR condition.

    Testing
    After setting up the RLS, you can test it by using the "View as Role" feature in Power BI Desktop to ensure the filters are working as expected.

    Best Regards
    Saud Ansari
    If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

  • Hi kyrpav - For RLS with OR conditions:

    1. Go to the "Manage Roles" feature in Power BI Desktop.

    2. Define roles using DAX expressions that include an OR condition

    Eg :

     [Column A] = "Condition A" ||
    RELATED('Table B'[Column B]) = "Condition B"

     

    Hope this helps

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi kyrpav ,

    Has your problem been resolved? If so, could you please mark the helpful reply as Answered? This will assist others in the community who may encounter a similar issue. Thank you.

     

    Otherwise, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards