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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
a1b1c1
Advocate I
Advocate I

Custom Implemention for RLS using PATH()

Hi,
I've got quite a unique scenario over here involving RLS implementation. 

If you take a look at the sample data, it's the case that for individual users e.g. user1, I have corresponding manager information and I'm able to calculate the heirarchy in Path column using DAX PATH() function. 
The problem lies with the rows where essentially users are merged in form of teams e.g. "user1/user2" and they may have different managers. As a starter, I created Calculated Username to get usernames from individual users (how? long story.)
Now, I need to create a column as portrayed in Calculated Path. 

Sample Data: 

UserUsernameCalculated UsernamePathCalculated Path (Desired column) 
user1user1@company.comuser1@company.comManager1 | user1Manager1 | user1 
user2user2@company.comuser2@company.comManager2 | user2Manager2 | user2 
user1/user2nulluser1@company.com;user2@company.comnullManager1 | user1; Manager 2 | user2 


Furthermore, I found this code by @TomMartens from https://community.powerbi.com/t5/Desktop/DAX-forumula-help-with-comma-separated-values/m-p/534837
//Awesome job on the code btw.


Column =
var stringSelected = FIRSTNONBLANK('Consolidated Sales Rep Table'[Calculated Username],0)
var stringAsPath = SUBSTITUTE(stringSelected,";","|")
var intPathLength = PATHLENGTH(stringAsPath)+0
var tempTable =
          SELECTCOLUMNS(
                ADDCOLUMNS(
                     GENERATESERIES(1,intPathLength)
                     ,"Users",PATHITEM(stringAsPath,''[Value],TEXT)
                 )
           ,"Users", [Users]
         )
return
CONCATENATEX(temp,[New Path],"|")

What this code does is, is that it separates delimeter based strings and creates a temporary table and stores individual strings in rows, pretty neat stuff!

How I am trying to leverage it: 
By adding one more variable to the code:

var PleaseDearGod = FILTER('myTable', 'myTable'[Username] IN {tempTable})
return CONCATENATEX( PleaseDearGod, Path], "|" )
// It would check "user1@company.com" & "user2@company.com" (in form of two rows) and filter the table where they have their individual user data and fetch Path column.


The issue with this approach seems to be the splitting of Calculated Username into two rows, which generates "A table of multiple values was supplied error where a single value was expected."
 
Could you please help me out in this? I'd highly appreciate it.
@TomMartens @parry2k @Greg_Deckler @PhilipTreacy 



1 REPLY 1
v-robertq-msft
Community Support
Community Support

Hi, @a1b1c1 

According to your description and DAX formula, I can not find the real reason and true location that the error occurs. Would you like to post your test pbix file(without sensitive data) and your expected result so that we can help you in advance?

Thanks very much!

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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