dynamic rls
11 TopicsDynamic RLS and using DirectQuery
speedramps again thank you very much for your help. Really appreciate your time and help for trying to solve this issue. I hope I've explained my issue as clear as possible. Goal Set up flexible (dynamic) Row-Level Security (RLS) in Power BI using a UserSecurity table that filters a FactTable. When a user logs in, the UserSecurity table should filter to that user, which in turn should filter the FactTable to only show data the user is allowed to see. Requirements All tables in the data model use DirectQuery. The UserSecurity table must support wildcards to indicate full access, in this case I use 0. The reaon for this is that I want to avoid that the table will get extremely large. Example: If a user has access to all ResourceGroups within a Subscription, the ResourceGroup field should be 0. A key use case to support is (please see attached Excel file (UserSecurity) for the full overview: User 16 has access to: All ResourceGroups in Subscription 17 Only ResourceGroup 15348 in Subscription 25 Limitations Because I’m using DirectQuery, I cannot use functions like CALCULATE or COUNTROWS in Manage Roles for RLS (they are disabled). If a relationship between the tables is needed, a many-to-many relationship is needed between UserSecurity and the FactTable because: Multiple users in UserSecurity Each user can have multiple different access rules (some full access via wildcard, some partial) However, many-to-many relationships are problematic with DirectQuery What I've Tried It works perfectly in Import Mode (use Test 1 as Role), but I must use DirectQuery. Please see attached PBI how it should work. I’m stuck translating the logic into a DAX approach that works in DirectQuery mode with these constraints. Ask How can I implement this kind of dynamic RLS with wildcard support in DirectQuery mode? I've attached 2 Excel files and a PowerBI file that can be used. Sorry, I don't know how to share a DirectQuery model because of privacy concerns. I hope this Excel files gives enough context. Link to download files: https://we.tl/t-PONAaflP8Q Many thanks again, and appreciate the help! Kind regards, NielsSolved2.9KViews0likes8CommentsDynamic RLS by using a UserSecurity table
Hi! In PowerBI, we have a data model and want to apply a quite flexible data security that includes all possible scenario's. To achieve this we are thinking about using a UserSecurity table, which has all the permissions per user. See below a short example of a scenario: _ID CLIENTID USERID SUBSCRIPTIONID RESOURCEGROUPID 201 3 16 25 15348 301 3 16 17 null In this case, user 16 can have access to subscription 25 but only to ResourceGroup 15348 within subscription 25. At the same time, user 16 can see everything in Subscription 17. We want to use null (wildcard) because otherwise the UserSecurityTable can get too large. I tried to use relationships to the dimension tables, but in the above mentioned scenario, the null value overrides it. Therefore, our idea now is to filter the fact table instead since all the id's are already in there (probably will get performance issues, but will solve that later). Further there won't be a relationship between the tables since we have to create multiple relationships between the 2 tables. So, we need a DAX query to solve this in Manage Roles but my DAX is so far not good enough to make it work. In SQL, we would use the following query to achieve this: from FactTable1 fact join UserSecurity usc on ( (fact.subscriptionid = usc.subscriptionid or usc.subscriptionid is null) and (fact.resourcegroupid = usc.resourcegroupid or usc.resourcegroupid is null) ) where usc.userid = 16 Could someone please help me with translating this SQL query to DAX? And I'm happy to receive some other idea's on how to set this data security up! Many thanks! Kind regards, NielsSolved1.5KViews0likes6CommentsDynamic RLS - DAX help needed
Hi! In PowerBI, we have a data model and want to apply a quite flexible data security that includes all possible scenario's. To achieve this we are thinking about using a UserSecurity table, which has all the permissions per user. See below a short example of a scenario: In this case, user 16 can have access to subscription 25 but only to ResourceGroup 15348 within subscription 25. At the same time, user 16 can see everything in Subscription 17. We want to use null (wildcard) because otherwise the UserSecurityTable can get too large. I tried to use relationships to the dimension tables, but in the above mentioned scenario, the null value overrides it. Therefore, our idea now is to filter the fact table instead since all the id's are already in there (probably will get performance issues, but will solve that later). Further there won't be a relationship between the tables since we have to create multiple relationships between the 2 tables. So, we need a DAX query to solve this in Manage Roles but my DAX is so far not good enough to make it work. In SQL, we would use the following query to achieve this: from FactTable1 fact join UserSecurity usc on ( (fact.subscriptionid = usc.subscriptionid or usc.subscriptionid is null) and (fact.resourcegroupid = usc.resourcegroupid or usc.resourcegroupid is null) ) where usc.userid = 16 Could someone please help me with translating this SQL query to DAX? And I'm happy to receive some other idea's on how to set this data security up! Many thanks! Kind regards, NielsSolved718Views0likes3CommentsRLS based on 3 columns (All possible combinations)
Hi All, Looking to implement RLS that is based on 3 columns. So all possible combinations must be taken in to account while filtering. Consider the below table, the user could fall in either: - None of the columns, OR - Any 1 column, OR - Any 2 columns, OR - All 3 columns I am using an excel to capture the role against email IDs but can't crack the DAX yet in Manage Roles, any leads with the DAX will be really helpful.479Views0likes2CommentsRLS DAX to provide dynamic BETWEEN where a user can have multiple rows
Hi, I'm trying to wrap my head around a complex RLS rule, where we need to filter the a column of a table to all the values between a start and an end point in the RLS table, however the complication is, a user can have multiple rows in the RLS table, and therefore multiple start and end values. The RLS table is in the strutcture below: username territory_code time_grain start_tgd_key end_tgd_key [email protected] AU Week 11200249 11299901 [email protected] AU Period 12200249 12299901 [email protected] AU Quarter 13200249 13299901 [email protected] IE Week 41200249 41299901 [email protected] IE Period 42200249 42299901 [email protected] IE Quarter 43200249 43299901 [email protected] NZ Week 91200849 91299901 [email protected] NZ Period 92200849 92299901 [email protected] NZ Quarter 93200849 93299901 [email protected] UK Week 111199801 111299901 [email protected] UK Period 112199801 112299901 [email protected] UK Quarter 113199801 113299901 And the table that the rule will be imposed upon like below: Stat_week territory_code time_grain tgd_key 199801 UK Week 111199801 199801 UK Period 112199801 199801 UK Quarter 113199801 200249 AU Week 11200249 200249 AU Period 12200249 200249 AU Quarter 13200249 200249 IE Week 41200249 200249 IE Period 42200249 200249 IE Quarter 43200249 200849 NZ Week 91200849 200849 NZ Period 92200849 200849 NZ Quarter 93200849 The rule needs to match the territory_code & time_grain values between tables, and then filter to all the values in tgd_key that are between the start_tgd_key and end_tgd_key. My starting point is the code below, which worked until we had to make it mulitple rows per user. VAR Start_filter = CALCULATETABLE ( VALUES ( 'rls account_calendar_meta'[start_tgd_key] ), 'rls account_calendar_meta'[username] = USERPRINCIPALNAME () ) VAR End_filter = CALCULATETABLE ( VALUES ( 'rls account_calendar_meta'[end_tgd_key] ), 'rls account_calendar_meta'[username] = USERPRINCIPALNAME () ) RETURN AND ( [tgd_key] >= Start_filter, [tgd_key] <= End_filter ) Grateful for any assistance that can be provided!! Thanks, MarkSolved515Views0likes2CommentsHelp on RLS in Power BI
Hi Team - We have tabular model (screenshot below) and enabled RLS on the "DimSubsidiary" table, which is applying security filter to the "FactSales" tables. However, we have a requirement to show sales different when slicer is placed on Geography. Example: As per Sample Data below, User A is allowed to see US and UK Subsidiary Data For User A: Total Sales (Subsidiary=US) = 100 + 600 ( Row 1 + Row 2) . This is working as expected. Total Sales (For Geo=US) = 100 ( because of RLS user A can see Row 1 and Row 2) and For US, it's 100. but User A has access to US subsidary , they should be able to see Revenue for US Geography i.e they should see sales as ( 100 (Row1) + 500 (Row 3) + 700 (Row 5) Beacuse of RLS in place this will not work Can you please suggest how to proceed further in order to show 1300 as sales for User A when we select Geo="US" ? Do I need to create any bridge table based of Fact? Data Model Thanks, Abhiram610Views0likes2CommentsOption to Disable/Bypass the RLS on active relationship
Hi Team - We have tabular model (screenshot below) and enabled RLS on the "DimCustomer" table, which is currently security applying the filter to both the "FactSales" and "FactCompute" tables. However, we have a requirement to disable RLS between the "DimCustomer" and "FactCompute" tables, while still keeping it enabled for the "FactSales" table. Upon reviewing the available solutions, I have come across below approaches, but it has certain disadvantages. Please suggest if there any other alternative options 1) Implement RLS on FactTable Implement RLS on FactSales Table Only Disadvantage: FactSales is very big , it occupies 70 GB in our data model. I think implementing RLS on Fact will slow down the performance. 2) Clone the Customer Table Have two set of Customer Table and enable RLS on One Customer Table. Disadvantage: If we want to show Sales and Cores by customerName in single chart then we will end up with customerName from different tables RLS Code On DimCustomer: VAR CUSTOMERS = CALCULATETABLE ( VALUES ( 'DimUser'[SubsidiaryID] ), 'DimUser'[UserAlias] = USERPRINCIPALNAME () ) RETURN 'DimCustomer'[CustomerID] IN CUSTOMERS Thanks, AbhiramSolved1KViews0likes1CommentRLS DAX Query Optimization
Hi Team, I have implemented RLS on below model but the performance is slow. can some please suggest way to optimize DAX Code. RLS Tables: User Product Sub: A User can have access to atleast one products. ( Each User will have atleast one or more entry in Table) User Product Sub WW : User has access different categories of Products. ( Each User will have single entry in table) Fact Sales: Sales Reported for each Customer. Due to Telemetry, we see null Customer ID in Facts. We want to show sales for products even for null customers only for user who are part of Product Sub WW. Product Table: Product ID and Product Name RLS DAX code on Product Table: VAR PRODUCTS = CALCULATETABLE ( VALUES ( 'User Product Sub'[ProductID] ), 'User Product Sub'[UserAlias] = USERPRINCIPALNAME () && 'User Product Sub'[Is Authorized User] = TRUE() ) VAR WWAccess = MAXX(FILTER('User Product Sub WW', 'User Product Sub WW'[UserAlias] = USERPRINCIPALNAME () && 'User Product Sub WW'[Is Authorized WW User] = TRUE), 1) RETURN 'Product'[ProductID] IN PRODUCTS || ('Product'[ProductID] = BLANK() && WWAccess =1) Please find the attached model with sample data. Sample Data: Thanks, Abhiram714Views0likes3CommentsDynamic RLS using Dataverse tables works until the users try Accessing
Please advise. I set up Dynamic Row Level Security for a report that uses a table from DataVerse as my security table (with email addresses). The email address field is formatted as Email Address in the table. I followed all of the steps in this video as much as they show (https://www.youtube.com/watch?v=Z3oLWtWABfo). I can test in Power BI desktop using the users' email addresses. I also tested the security (test as role) on the Power BI Diamond Workspace (after publishing). Everything worked great until I shared the report with two users who have Viewer access to the workspace. They receive the following message just as if they had no access to the data: "The report can't be viewed because the underlying dataset uses row-level security (RLS)." Here is the code I set up in the Modeling, Manage Roles: [RLS_EmailAddress] = USERPRINCIPALNAME() I've done some searching on forums and saw someone say that USERPRINCIPALNAME() needs to be in double quotes. That breaks this from working in the desktop and web versions. Addl info- I am bringing the data in all tables as a dataset(Import) rather than accessing the data through a DirectQuery connection. Please advise!Solved2.5KViews0likes4CommentsDynamic RLS with complex security module
Hi, I'm trying to create a Dynamic RLS for a complex security module, here are the table structure and relationship: Table 1. Users Username Company Code Role Type Access ID A A S B A A C A R 77 D B B Table 2. Roles Username Access Detail A 12345 A 67891 C 77 D 97 Table 3. Data ID Date Value Company Code Role S Role B Role R 1 01-01-2021 1 A 12345 77 2 01-01-2021 2 A 67891 3 01-05-2021 3 A 77 4 10-01-2021 4 B 97 As it's showing in the above Data Table, User "A" should be able to see the first 2 rows as Role S 12345 & 67891 are linked to user A in Roles Table and user A is in Company "A", User “C” should be able to see row 1 and row 3 as Role R is 77 and 77 is linked to user C and the user is in Company “A”, and finally User “D” should be able to see only row 4 as Role B is 97 and user Company is “B”. User “B” should be able to see everything as Role Type “A” is Admin. So, the relationship here is: Table 1 (Username) -> Table 2 (Username) Table 1 (Company Code) -> Table 3 (Company Code) Table 1 (Role Type) -> Table 3 (Role S, Role B or Role R) Table 2 (Access Detail) -> Table 3 Value of (Role S, B or R) I’ve tried different type of DAX expression but with no luck so far, any ideas that might help in resolving this? Thanks in advance,798Views0likes1Comment