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
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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors