Forum Discussion

mqassas's avatar
mqassas
New Member
8 years ago

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

  • kmcallister's avatar
    kmcallister
    Frequent 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