Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi,
I am connected to the "Usage Metrics" dataset for a report, and I am trying to show which country each user comes from. In the dataset, there is a "Users[UserPrincipalName]" that contains the email adress.
Since I cannot transform the data (supposedly because it is a connected dataset), my idea was to create a measure that says
I have tried various ways without success.
Any ideas?
Hi @Anonymous ,
Sorry if my question is a bit unclear. Let me try to clarify.
As of now I have not found a solution to my problem. Unfortunately I cannot share the PBIX file as you would not have access to the dataset. It may be that what I want done, cannot be done because it is a connected dataset. But that is what I am trying to find out.
UserPrincipalName | Country/Platform | ViewsCount |
User1@ending.es | Spain | 20 |
User2@ending.es | Spain | 15 |
User3@ending.au | Australia | 10 |
User4@ending.au | Australia | 40 |
Country/Platform | ViewsCount |
Spain | 35 |
Australia | 50 |
Country/Platform | ViewsCount |
Australia | 50 |
I hope that clarifies both my issue, and my final objective a bit. Once again, perhaps this is not possible with a live connnected dataset. It is just that I am so close, but can't take hte final step.
Best,
Benk3i
Hi @benk3i ,
It could not be achieved by using measure, you could add a calculated column for Country instead:
CountryColumn =
VAR _search =
SEARCH ( "@", 'User'[UserPrincipalName], 1, BLANK () )
VAR _left =
IF ( _search > 0, LEFT ( 'User'[UserPrincipalName], _search - 1 ), BLANK () )
VAR _a1 =
IF ( ISERROR ( _left ), BLANK (), _left )
VAR _right =
IF ( LEN ( _a1 ) > 1, RIGHT ( _left, 2 ), BLANK () )
RETURN
SWITCH ( _right, "es", "Spain", "cn", "China", "uk", "UK" )
And we don't need to create another measure, just choose “Sum”(for Value field) and "Show items with no data" (for Country field)
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin
Hi @Anonymous
Got you. Then that is probably the underlying issue. Unfortunately, when I connect the dataset to the Usage Metrics dataset, I am unable to create columns (in my understanding, becuse then i would change the underlying dataset).
So I am guessing there really isnt a solution to this situation then?
Best,
benk3i
Hi @benk3i ,
Sorry for my late reply. But I'm really a little confused about your real needs...
When you get data from Power BI Dateset ,the connection mode is Live Connection which does not support Power Editor.
Could you tell me if your problem previous has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.
Best Regards,
Eyelyn Qin
Hi @benk3i ,
Sorry for my misunderstand and sorry for my incomplete consideration,
From my test, this error will be reported when there is a null value, a very short character, do not exist "@" ,etc
So I improved my data, please try like this:
Measure =
VAR _search =
SEARCH ( "@", MAX ( 'User'[UserPrincipalName] ), 1, BLANK () )
VAR _left =
IF (
_search > 0,
LEFT ( MAX ( 'User'[UserPrincipalName] ), _search - 1 ),
BLANK ()
)
VAR _a1 =
IF ( ISERROR ( _left ), BLANK (), _left )
VAR _right =
IF ( LEN ( _a1 ) > 1, RIGHT ( _left, 2 ), BLANK () )
RETURN
SWITCH ( _right, "es", "Spain", "cn", "China", "uk", "UK" )
Then the output will be right:
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin
Hi @Anonymous ,
You have been super helpful and I have managed to get pretty far with all of your help.
I actually ended up going with something closer to your original suggestion, which was:
Country/Platform =
SWITCH(
RIGHT(
MAX('Users'[UserPrincipalName]),2),
"es","Spain",
"cn","China",
"uk","UK",)
The email adresses I have are all based on the domain ending, so not before the "@" symbol, but I assume that your latest suggestion might work even better in case of complications.
That worked great in the table. However, I am unable to create a table that shows
"Spain: X views"
"China: X views"
"UK: X views".
Similarly to the PBIX file that you attached, if you try to create a table with the measure and values, it just shows "UK: 21" (see the picture below)
What I would like in your example is to show the table as
Measure | Value |
China | 1 |
Spain | 2 |
UK | 3 |
Blank | 15 |
Maybe that is a bit beyond what a measure can do though. Haven't tried something like this before.
Once again, thanks a lot for all the detailed help!
Hi @benk3i ,
It seems like the [UserPrincipalName] is a measure not a column from original data source ,right?
Please change like this:
Measure =
SWITCH (
RIGHT (
LEFT (
[UserPrincipalNameMeasure],
SEARCH ( "@", [UserPrincipalNameMeasure], 1, BLANK () ) - 1
),
2
),
"es", "Spain",
"cn", "China",
"uk", "UK"
)
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin
Hi @Anonymous
Actually the UserPrincipalName is not actually a measure. The fields panel looks like the picture below. The only measure I have there right now is the one from above.
Best,
Benk3i
Hi @benk3i ,
There is a little difference between Column and Measure, please take a look at the following formula:
measure =
SWITCH (
RIGHT (
LEFT (
MAX ( 'User'[UserPrincipalName] ),
SEARCH ( "@", MAX ( 'User'[UserPrincipalName] ), 1, BLANK () ) - 1
),
2
),
"es", "Spain",
"cn", "China",
"uk", "UK"
)
Best Regards,
Eyelyn Qin
Hi @Anonymous
Thanks for the quick reply!
That made it so that I can find the Column, so that's the good news!
Unfortunately I end up the following error when I try (seems to refer to the "Left("
This was when I tried to put the UserPrincipal in the same table with the measure.
I also get no values in the table when I just use the measure.
Best,
Benk3i
Hi @benk3i ,
According to my understand, you just want to know which country each user comes from based on email address, it seems like we do not need Usage Metrics (It is used to see who viewed the report, how many times, etc.)
You could use the following formula to creata a Country column:
Country =
SWITCH (
RIGHT (
LEFT (
'User'[UserPrincipalName],
SEARCH ( "@", 'User'[UserPrincipalName], 1, BLANK () ) - 1
),
2
),
"es", "Spain",
"cn", "China",
"uk", "UK"
)
Then you could apply filter or use Q&A in Desktop to filter Country. Also, URL filter is another effective way when the report is published to service.
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin
Hi @Anonymous ,
Thank you for your response. This absolutely feel like the right solution.
However, I am unable to select the right table/field when I am typing in the measure.
Country =
SWITCH (
RIGHT (
LEFT (
'User'[UserPrincipalName],
The measure will not recognize 'Users'[UsersPrincipalName]. It will suggest existing measures. In the usage metrics there are two measures created with the calculator icon, and it immediately suggests those two, but not the table I am looking for - as seen below
Even if I type it in, the code doesnt work and I get an error (red underline), so it doesnt find the table/field.
Here are the fields
Maybe my problem is extremely basic, but I am confused 🙂
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the September 2025 Power BI update to learn about new features.