Daily DAX : Day 402 USEROBJECTID
USEROBJECTID() – Power BI DAX Function
Definition
USEROBJECTID() is a DAX function available in Power BI and Analysis Services Tabular models that returns the Azure Active Directory (Azure AD) Object ID of the currently logged-in user.
| Function | USEROBJECTID() |
|---|---|
| Return Type | Text (GUID string) |
| Category | Security / Row-Level Security (RLS) |
| Availability | Power BI Service, Power BI Report Server (with AAD), Azure Analysis Services |
Common Use Case: Row-Level Security (RLS)
The primary and most powerful use of USEROBJECTID() is to implement dynamic Row-Level Security.
Example Scenario:
A company wants each sales rep to see only their own sales data in a Power BI report.
A company wants each sales rep to see only their own sales data in a Power BI report.
Step-by-step Implementation
- Create a table in your model (e.g.,
UserSecurity) that maps email or User Principal Name to Azure AD Object ID: - In Power BI Desktop, go to Modeling → Manage Roles
- Create a role (e.g., "Sales Rep Role") and add a DAX filter like:
- Or directly filter the Sales table if you have the Object ID stored there:
UserPrincipalName | AzureAD_ObjectID | AllowedRegion
john@contoso.com | a1b2c3d4-5678-90ab-cdef-1234567890ab | Europe
sarah@contoso.com | x9y8z7w6-5432-10fe-dcba-9876543210fe | America
[UserPrincipalName] = USERPRINCIPALNAME()
||
[AzureAD_ObjectID] = USEROBJECTID()
Sales[RepObjectID] = USEROBJECTID()
Related Useful Functions
| Function | Returns |
|---|---|
USERPRINCIPALNAME() | User's email (UPN), e.g., john@contoso.com |
USERNAME() | In Power BI Service = UPN, in Desktop = Windows login |
USEROBJECTID() | Azure AD Object ID (GUID) |
Important Notes
USEROBJECTID()returns blank in Power BI Desktop (no live AAD session)- Works perfectly when the report is published to Power BI Service with Azure AD authentication
- Most reliable for RLS because Object IDs never change (unlike emails that can be renamed)
- Requires users to be in the same Azure AD tenant (or guest users properly mapped)
Best Practice: Store Azure AD Object IDs in your security table and filter using USEROBJECTID = USEROBJECTID() for the most robust RLS solution.
Comments
Post a Comment