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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Can we retrieve logged in user name in Power BI Query editor and passed as a parameter sql query

Can we retrieve logged in user name in Power BI Query editor and passed as a parameter to dynamic sql query.

We are trying to retrieve data from a table dynamically based on the logged in user in Power BI. Is there a way to accomplish the same. Any feedback would be appreciated

1 ACCEPTED SOLUTION
Kalpavruksh
Resolver I
Resolver I

Hi Rinky,

 

Currently, there is no way to retrieve the logged in username. DAX function Username() can be helpful to return the username that the person is sign in using its Power BI credentials.

 

Kalpavruksh Technologies | Microsoft Gold Partner
Denmark | USA | India | Germany

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

View solution in original post

8 REPLIES 8
Sergiy
Resolver II
Resolver II

Kalpavruksh
Resolver I
Resolver I

Hi Rinky,

 

Currently, there is no way to retrieve the logged in username. DAX function Username() can be helpful to return the username that the person is sign in using its Power BI credentials.

 

Kalpavruksh Technologies | Microsoft Gold Partner
Denmark | USA | India | Germany

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

ImkeF
Super User
Super User

Unfortunately there is no native function in Power Query that does that. 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Nolock
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

as @ImkeF said, it is not possible in PowerQuery.

But you didn't describe your scenario. Maybe Row-level security will help. And theoretically, if you used a DirectQuery and DAX (USERNAME) you'd be able to send an SQL query containing the current user directly to an SQL Server.

Anonymous
Not applicable

  I want apply userprincipal function(logged in user name) in custom parametrer and then custom parameter in sql query. How can i do it. Please help me.

Hi @Nolock , could you please give more hint on how to pass USERNAME DAX Function in a SQL Query using direct query ?
I'm aware of how to pass a parameter to a query, but I don't see any way of passing the currently pbi logged user (or any DAX / measure formula).
Any help would be greatly appreciated. Cheers

Nolock
Resident Rockstar
Resident Rockstar

Hello @hai_pbi,

if you use RLS, then PBI will send an SQL query like that. You see there is a where clause with the email address of the current user. More info: Row-level security (RLS) with Power BI - Power BI | Microsoft Docs

SELECT 
TOP (1000001) [t0].[C3]
FROM 
(
(
select [$Table].[C1] as [C1],
    [$Table].[C2] as [C2],
    [$Table].[C3] as [C3]
from [dbo].[taxi] as [$Table]
)
)
 AS [t0]
WHERE 
([t0].[C3] = N'your@email.com')

GROUP BY [t0].[C3]

Thanks a lot for this (very) rapid answer.
I see what you mean, if RLS is set with a filter applied on a table (that has a username column) with DirectQuery mode, the query sent to SQL server already filter the table correctly. Thanks.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors
Top Kudoed Authors