cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Prodigy
Post Prodigy

Pass username as filter or parameter in query using DirectQuery to SQL?

Is there anyway to pass UserName() or userPrincipalName() as a query parameter when doing direct query?

 

For example, if I want to direct query on today's sales I can handle queries like getting today's date, but I also want to filter on the sales person running the direct query.

 

Our sales table has the sale's person's userPrincipalName as a column but I want it to filter on that by passing a value as opposed to having to return all the values for today and then do a slicer filter on the report.

10 REPLIES 10
Highlighted
Super User IV
Super User IV

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

UserName is DAX function and I don;t think you can pass this as query parameter. You can filter the records on USERNAME() once records are loaded.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Highlighted
Post Prodigy
Post Prodigy

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

I was hoping to find a way to pass it into SQL as a parameter, I looked at using M but I didn't see any options for passing usernames that way (rather I didn't see a username function for M).

 

Ideally, I would be able to do a SELECT Col1, Col2, Col3 FROM Table1 WHERE Table1.Username=username()

(from PBI of course) however, I don't see anyway to pass system variables/parameters into queries.

 

 

I wanted to filter them BEFORE they are loaded, so if my table had 1 million records, I would much rather return only the records that matched UserName() instead of the entire table.

 

Highlighted
Super User IV
Super User IV

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

Well as mentioned before, unfortunately I'm not aware of that you can pass username() value to power query, it is going to be filter after table is loaded.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Highlighted
Community Support
Community Support

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

@OneWithQuestion,

 

Row-level security (RLS) with Power BI can be used to restrict data access for given users. You may have a look.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Frequent Visitor

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

Is it possible to pass userbname to stored procedure in mcode? If So how can i do that? 

Thanks

Highlighted
Frequent Visitor

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

Is it possible to pass userbname to stored procedure in mcode? If So how can i do that? 

Thanks

Highlighted
Post Prodigy
Post Prodigy

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

No good in this case.

 

We want to filter by department defaults, so that if we are viewing sales by region or department the page loads with that specific region/department filtered first.

 

However, we don't want to prevent them from viewing other department/region data.

 

Basically we have SPO sites with various department landing pages and want a link back to PBI to take viewers directly to the PBI dashboard with the linking department filtered.

Highlighted
Helper II
Helper II

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

Is there anywhere I can vote for this enhancement? I have 100 million rows in a table. I can't refresh 25GB every day just so 10 people can access 100,000 rows

Highlighted
Frequent Visitor

Re: Pass username as filter or parameter in query using DirectQuery to SQL?

Hi

Did you find the answer for this? I have exactly the same issue.

 

thanks.

 

A.

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors
Top Kudoed Authors