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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
navin_Learning
Frequent Visitor

DAX expression in creating role

Dear All,

 

So, i have two table

 

Policy table

PolicyRO CodeSO codeSum insured
1232102000
1243203000
1256304000

 

User table

UserRO CodeSO code
abc@loggedin210
def@loggedin320
ghi@loggedin630

 

Now i am still learning, so please bear with me.

 

Question: What i want is to create a dax in manage role, which will fetch who is logged in power bi service and will filter the data/report based on his/her RO code & SO code.

 

Output: As in a sample data above,

if abc@loggedin is logged in power bi server,

then he should only see data/report related to RO code - 2 & SO code - 10

 

Thank you!

 

Regards,

Navin

2 ACCEPTED SOLUTIONS

Hi @navin_Learning,

 

I have created a simple solution that will take care of your requirement using CALCULATETABLE function, which unfortunately will not work with Direct Query models.

 

As long as you are going to use the import option (from any source), this method will work fine.

 

As per sample data provide by you, the unfiltered table will look as below:

UNFILTERED DATA.JPG

As per your condition, user PQR@XYZ.COM can see only one record (ROCD=100, SOCD=20) and that happens.

FILTERED DATA 2.JPG

Another sample for user MNO is also shown below.

FILTERED DATA 1.JPG

You can see the same results for MNT also since his combination is also 101-30.

 

I hope this is what you have described as your requirement and you can see it happening. 

 

You can download the Excel and PBIX files from this link, if you want:

RLS2-06-06-2023

 

Please consider accepting this as a SOLUTION so that others can make a note of this and check when needed.  Your Kudos are also welcome.

 

Best Regards,

 

C.S.N. Raja

 

 

View solution in original post

1. In the source data you can type ALL for either ROCD or SOCD columns or for both the columns as the case may be.

 

 

SOURCE DATA.JPG

2. Scenario-1:  ROCD ALL BUT SOCD IS LIMITED TO 75

S1-ROCD IS ALL.JPG

3. Scenario-2: ROCD IS LIMITED TO 100 BUT SOCD IS ALL

S1-SOCD IS ALL.JPG

 

4. Scenario-3: ROCD = ALL & SOCD = ALL - Now all the records will be displayed

S3-ALL FOR BOTH.JPG

 

5. Modified DAX code:

NEW CODE.JPG

 

6. Please note - both the tables are not connected. The ROCD & SOCD columns are converted into text, since I am using the "ALL" string in them.

 

Hope this helps.

 

Regards,

 

C.S.N. Raja, MCT

Power BI Trainer & Consultant

View solution in original post

7 REPLIES 7
navin_Learning
Frequent Visitor

Dear Raja,

 

This worked perfectly fine, however just one more requirement has been added and that is out of the user list some should have full access.

 

So how to flag them?

 

Thank you for your valuable time

1. In the source data you can type ALL for either ROCD or SOCD columns or for both the columns as the case may be.

 

 

SOURCE DATA.JPG

2. Scenario-1:  ROCD ALL BUT SOCD IS LIMITED TO 75

S1-ROCD IS ALL.JPG

3. Scenario-2: ROCD IS LIMITED TO 100 BUT SOCD IS ALL

S1-SOCD IS ALL.JPG

 

4. Scenario-3: ROCD = ALL & SOCD = ALL - Now all the records will be displayed

S3-ALL FOR BOTH.JPG

 

5. Modified DAX code:

NEW CODE.JPG

 

6. Please note - both the tables are not connected. The ROCD & SOCD columns are converted into text, since I am using the "ALL" string in them.

 

Hope this helps.

 

Regards,

 

C.S.N. Raja, MCT

Power BI Trainer & Consultant

navin_Learning
Frequent Visitor

Thank you so much for your showing interest in my requirement.

Here is the attached sample data in .XLS format, again thank you for your time & attention

 

Policy data.

PolicyROCDSOCDSum
1234100102000
5678100102000
91011100203000
121314101304000
151617101305000
15161813375600
15161713375800
151615144529000
151617144521222

  

User data

UserROCDSOCD
abc@xyz.com10010
def@xyz.com10010
pqr@xyz.com10020
mno@xyz.com10130
mnt@xyz.com10130

 

Sorry i could find how to attached the xls file or i guess its restricated from my company

Hi @navin_Learning,

 

I have created a simple solution that will take care of your requirement using CALCULATETABLE function, which unfortunately will not work with Direct Query models.

 

As long as you are going to use the import option (from any source), this method will work fine.

 

As per sample data provide by you, the unfiltered table will look as below:

UNFILTERED DATA.JPG

As per your condition, user PQR@XYZ.COM can see only one record (ROCD=100, SOCD=20) and that happens.

FILTERED DATA 2.JPG

Another sample for user MNO is also shown below.

FILTERED DATA 1.JPG

You can see the same results for MNT also since his combination is also 101-30.

 

I hope this is what you have described as your requirement and you can see it happening. 

 

You can download the Excel and PBIX files from this link, if you want:

RLS2-06-06-2023

 

Please consider accepting this as a SOLUTION so that others can make a note of this and check when needed.  Your Kudos are also welcome.

 

Best Regards,

 

C.S.N. Raja

 

 

RajaCSN
Helper III
Helper III

Hi,

You need to use the DAX function USERPRINCIPALNAME() to achieve this ROW LEVEL SECURITY (RLS). 

RLS should be created in PowerBI Desktop and should also be implemented in PowerBI Services.
I have simulated your data and here is sample image. When abc@xyz.com is logged-in, the user can see only relevant data.

 

UPN IMAGE.JPG

The actual table will show all the data (for the creator) as in this image:

other table.JPG

If you want to see the file in which I have simulated this, please download it from here:

RLS SAMPLE.pbix

 

If this explanation is helpful, please consider accepting this a solution. Your kudos are welcome too.

 

Best, 

 

C.S.N. Raja

Thank you dear Raja for your response, much appreciated!

I see that you have created relationship betweek ROCD and created role to filter the user.

 

Sorry not to mention it earlier, this is more complex

RO Code has multiple SO code, hence user should see data combining the RO & SO code.

Multiple user should see the same RO & SO code data

 

RO - regional code

SO - state code

So one state will have multiple people looking after the same data.

 

I  hope am able to explain my requirement, thank you for your help!

Creating RLS in complex scenarios is really interesting. Your requirement is pretty much possible to be implemented. 

 

Assume that I have a report similar to this image:

unf-1.JPG

And a set of dynamic roles similar to this image:

ROLE1.JPG

I can limit the results as per combination of various fields (columns) for a given user. An example is shown below:  (All states, all categories but only consumer segment)

filt1.JPG

 

Sorry, unable to post my Excel, PBIX files here since they need to be santized before posting in a public domain. If you provide with me a skeleton dataset with your requirements, I shall create the roles and then share it with you.

 

Best Regards,

 

C.S.N. Raja

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.