cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoshT
Advocate I
Advocate I

Dependency inversion for DAX for RLS purposes

Does anyone know if there's any way of treating DAX functions like mocked functions so they can spit out different values during testing? In particular it would be useful to specify the value returned by USERPRINCIPALNAME/USERNAME in desktop when you don't want to see 'your own' row limited set.

 

I'd imagine this would be a broadly useful feature, since USERPRINCIPALNAME is used in the overwhelming majority of RLS cases, and I would have thought it's quite a common scenario where a dataset developer doesn't exist in a business dataset (because they work in a separate function). When this happens the developer gets no rows back when ideally they would want to see a typical use case.

 

At the moment, the workaround is to comment out calls to the USERPRINCIPALNAME function and put a line below with a hard coded string. This isn't ideal given that the DAX editor in the manage roles dialogue isn't very good (can't indent, narrow space so you get a lot of visually confusing text wraps), and this could lead to testing code ending up in production.

2 REPLIES 2
JoshT
Advocate I
Advocate I

Hi Stephen,

No, I'm looking to find a way of testing datasets by imitating a role member when the USERPRINCIPALNAME function is used in the RLS formula. Since USERPRINCIPALNAME only returns the current user we would need a way of mocking it so that the RLS 'view as' feature shows what a business user would see, when we as the developers don't exist in the dataset.

 

The only other options I can see are a) put dummy data into the dataset with the developer's username (not an option in all circumstances without changing the ingestion logic and risk putting that into production) or b) commenting out the call to USERPRINCIPALNAME as outlined in my OP, again risking that getting into production. Seems like there should be some way of achieving this, otherwise the 'view as' feature would be redundant in the majority of use cases.

v-stephen-msft
Community Support
Community Support

Hi @JoshT ,

 

You want show the alternative value when there's no data because of RLS, right?

Please kindly refer to

Solved: alternative text to the visual object "Card" - Microsoft Power BI Community

Solved: Alternatives to RLS and dynamic RLS when there are... - Microsoft Power BI Community

Solved: Show text visual when user not in RLS - Microsoft Power BI Community

 

 

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors