Forum Discussion
Pass measure to SQL Query in Power BI
Hello Power BI Experts
I have the below SQL Query
select * from table1 where (field1 like (select field1 from users where (UserName=@CurrentLoginUser)) + '%')
I added the above query in Power BI, I would like to set this SQL parameter "@CurrentLoginUser" with the current user who browses the report.
- Is it possible to do that in Power BI?
- Is it possible to pass a measure with UserName() function to SQL Query?
If the answer is No so How can achieve that in Power BI
BTW, I have tried Manage roles that no help me in this scenario
Any help would be appreciated!
5 Replies
- kmcallisterFrequent Visitor
One solution we found for RLS is to bring in another table with the correct parameters( IE. Username, RegionKey). In our case, we used Username (AD Username) and then embedded the dashboard in our sharepoint site. We then used Sharepoint to pass the URL with the username. This allowed us to display the correct dashboard to the correct user.
Below is the URL we are using to filter the dashboard. Add this after the dashboard path
?rs:Embed=true&filter=TableName%2FPARAMETER%20eq%20%27USERNAME%27
So in your exact case, you'd want something like
(qualified server path)?rs:Embed=true&filter=table1%2Ffield1%20eq%20%27UserName%27
Hope this helps.
Kevin
- mqassasNew Member
Thank you for your reply!
- Is RLS is available for Power BI Report Server?!
- Also, I don't think it's double to add the username in the URL, I need to automatically detect the current user!
- davidm5Helper I
If you're connecting to SQL Server, you might try using SYSTEM_USER as described here: