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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

Filter All Pages using Users Domain using "Measure" feature

Hi,

I would like to Filter BI-Reports using the Users Domain.

I am able to grab the User using Measure = Username()
I would have thought it simple to drag this Measure accross to Filter On All Pages and then add a simple if contains "DomainName" Filter my Table by Column  [ClientName].  My [ClientName] includes the Clients Domain.

I dont need or require ROW level Security, just the ability to Filter using a Viewers Domain.

 

Thank You Kindly,

Jonathan

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JonathanDavey1 ,

 

I have created a data sample and include the actual domain for "C".

 

Please try to create a measure, and apply it to visual-filter pane, set as "is 1":

Domain measure = 
var _pos=FIND("\", USERNAME())
var _domain=LEFT(USERNAME(),_pos-1)
return IF(CONTAINSSTRING(MAX('Table'[Include domains]),_domain),1,0)

Output:

Eyelyn9_1-1649300892853.png

 

Best Regards,
Eyelyn Qin
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

5 REPLIES 5
Anonymous
Not applicable

Hi @JonathanDavey1 ,

 

This error is because USERNAME() show different formats in Power BI Desktop and Power BI service:

You can use username() within this expression. Be aware that username() has the format of DOMAIN\username within Power BI Desktop. Within the Power BI service and Power BI Report Server, it's in the format of the user's User Principal Name (UPN). Alternatively, you can use userprincipalname(), which always returns the user in the format of their user principal name, username@contoso.com.
 
So if you want to publish the report to service, I'd suggest you use USERPRINCIPLE() instead:
Measure =
var _remove=SUBSTITUTE(USERPRINCIPALNAME(),".com","")
var _address=FIND("@", _remove)
var _domain=Right(_remove,LEN(_remove)-_address)
return IF(CONTAINSSTRING(MAX('Table'[Include domains]),_domain),1,0)

 

Refer to:

https://docs.microsoft.com/en-us/power-bi/enterprise/service-admin-rls

 

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

Anonymous
Not applicable

Hi @JonathanDavey1 ,

 

I have created a data sample and include the actual domain for "C".

 

Please try to create a measure, and apply it to visual-filter pane, set as "is 1":

Domain measure = 
var _pos=FIND("\", USERNAME())
var _domain=LEFT(USERNAME(),_pos-1)
return IF(CONTAINSSTRING(MAX('Table'[Include domains]),_domain),1,0)

Output:

Eyelyn9_1-1649300892853.png

 

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

Hi @Anonymous 

 

Thank you really appreciate your help! I managed to enable the Domain Measure in the BI-Desktop and it worked in principle (USERNAME doesnt return domain only LOCAL account), so I published to BI-Online, now the filtered visual throws an error.

 

Screenshot 2022-04-07 162851.jpg

Yours appreciatively

Jonathan

 

 

 

Pragati11
Super User
Super User

HI @JonathanDavey1 ,

 

Can you kindly add more details to your question like screenshots on what is the issue and what is expected?

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi, let me try again.


I would like to Filter my Table using the Users Logged in Domain.

 

Using "Measure = USERNAME"  I am able to 'get' the User's name & domain.

 

Then I want to FILTER a Table using the Filters Contains Function. 

 

The Table includes a Column containing the DOMAINs

 

Many Thanks

Jonathan

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.