Forum Discussion
How to retrieve userprincipalname in Power query editor
- 1 year ago
Hi Harineeeeeeee ,
Thanking for reaching out to fabric community forum.
nilendraFabric Thanks for your prompt response. In additon to that :- You need to retrieve the User Principal Name (UPN) from Active Directory and map it to its corresponding StoreID. This mapping should be stored in a security table within your database. Ensure that this table is updated regularly to keep all user-store associations current.
- Once the data is stored in the security table, you can load it into Power Query for transformations, making it easier to query and analyze the data through a user-friendly interface.
- Next, create a function that retrieves the StoreID based on the provided User Principal Name as a parameter (@parameter). Use this parameter to filter your SQL query.
- However this function would need to be invoked from power query every time you need to query a user.
If our response or a community member’s response addressed your query, please mark it as 'Accept Answer' and click 'Yes' if you found it helpful.
If you have any further questions, feel free to reach out.
Thank you for being a part of the Microsoft Fabric Community Forum!
Hello Harineeeeeeee
Power Query does not have access to runtime user context, you cannot directly retrieve or pass USERPRINCIPALNAME() into your SQL queries from Power Query. The recommended solution is to use DAX—via measures or row-level security—to handle user-specific filtering after data is loaded.
There is no native M function to retrieve the login user’s principal name. This is because Power Query processes data during refresh, independent of the interactive user context in the report
Check this discussion as well
If this is helpful please accept the answer and give kudos
Thanks for reply but unfortunately this doesn't serve my purpose so I have to take the selected user that is userprincipalname and select the store id once I found my store id i ll remove the filters on userprincipalname and based on the found store id i will have to show all the users nilendraFabric
- nilendraFabric1 year ago
Super User
Makes sense. But M language doesn't have userprincipalname concept.