Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
I have a measure that detects the country based on max hours spent there.
But there are some instances where the result has more than one country as the hours spent are matched. so as an example
it could be United States , Canada. this is returned in a measure called max_country
I also have a column called op_country
What I am trying to create is a dax formula first looking to see if the max_country measure result contains a comma
If it does then if country before the comma equals op_country then keep that country
if country after comma equals that country then keep that country
else keep both countries
Solved! Go to Solution.
@Pandadev is Country_Max_Days a column /measure?
If it is a measure, you can write a measure like this
_output =
SWITCH (
TRUE (),
CONTAINSSTRING ( [Country_Max_Days], MAX ( src[Op_Country] ) ), MAX ( src[Op_Country] ),
[Country_Max_Days]
)
@Pandadev Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Country_Max_Days | Op_Country |
Netherlands | Netherlands |
Spain , France | Netherlands |
Netherlands | Netherlands |
Germany , Netherlands | Netherlands |
Netherlands , Germany | Netherlands |
Netherlands | Netherlands |
Netherlands , Germany | Netherlands |
Netherlands | Netherlands |
Netherlands | Netherlands |
Netherlands | Netherlands |
Netherlands , Germany | Netherlands |
Netherlands | Netherlands |
Netherlands | Netherlands |
Netherlands , Germany | Netherlands |
So if Country_Max_Days contains a comma , example Netherlands , Germany , then I would need a dax formula to look at first country before comma , Netherlands and if that matches the Op_Country value then return that country. If not then check the second country and see if that matches. The desired output would be
Country Max Days | Op_Country | Output |
Netherlands | Netherlands | Netherlands |
Spain , France | Netherlands | Spain , France |
Netherlands | Netherlands | Netherlands |
Germany , Netherlands | Netherlands | Netherlands |
Netherlands , Germany | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands , Germany | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands , Germany | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands | Netherlands | Netherlands |
Netherlands , Germany | Netherlands | Netherlands |
@Pandadev is Country_Max_Days a column /measure?
If it is a measure, you can write a measure like this
_output =
SWITCH (
TRUE (),
CONTAINSSTRING ( [Country_Max_Days], MAX ( src[Op_Country] ) ), MAX ( src[Op_Country] ),
[Country_Max_Days]
)
Thanks , but I needed to know if it was the first country or 2nd country , as I also need to know which city to select , as I also have a measure that provides the city name.
So if the country combo was Netherlands , Germany , I would also need to get the correct city , so that measure would show , Amsterdam , Cologne. So as the first country was the match , I would want the first city
@Pandadev my answer was geared towards your original question. If there was an aspect you did not mention, provide a sample pbix that is representaive of the issue.
Country_Max_Days is a measure , and Op_Country is a column dax formula
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
91 | |
87 | |
80 | |
69 | |
69 |
User | Count |
---|---|
226 | |
129 | |
119 | |
83 | |
77 |