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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Pandadev
Post Prodigy
Post Prodigy

Identify correct country from measure when two countries are returned in result

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

 

1 ACCEPTED 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]
)

 

 

smpa01_0-1640888285951.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

@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.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Country_Max_DaysOp_Country
NetherlandsNetherlands
Spain , FranceNetherlands
NetherlandsNetherlands
Germany , NetherlandsNetherlands
Netherlands , GermanyNetherlands
NetherlandsNetherlands
Netherlands , GermanyNetherlands
NetherlandsNetherlands
NetherlandsNetherlands
NetherlandsNetherlands
Netherlands , GermanyNetherlands
NetherlandsNetherlands
NetherlandsNetherlands
Netherlands , GermanyNetherlands

 

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 DaysOp_CountryOutput
NetherlandsNetherlandsNetherlands
Spain , FranceNetherlandsSpain , France
NetherlandsNetherlandsNetherlands
Germany , NetherlandsNetherlandsNetherlands
Netherlands , GermanyNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
Netherlands , GermanyNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
Netherlands , GermanyNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
NetherlandsNetherlandsNetherlands
Netherlands , GermanyNetherlandsNetherlands

@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]
)

 

 

smpa01_0-1640888285951.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Country_Max_Days is a measure , and Op_Country is a column dax formula

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.