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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Custom Column with 'M' ('and' with double 'or' condition) Help Needed

Hi All!

 

3 month lurker, first time poster.  Needing a little help with a buildout of a custom column used as a market identifier to separate work streams. 

 

I feel like I'm super close, but I'm going round and round trying to get a proper result and can't seem to lock it in.

 

The solution is this:

Mark '1' for any county in the Charlotte, Philly, or VB metros.  Also mark '1' for any county in the Atlanta metro, with the exception of dekalb and fulton.

 

The M I've got looks like this:

 

m_example.PNG

 

...but I'm not getting the expected result. It seems to be ignoring the county identifier altogether and defaulting ALL Atlanta counties to '1':

 

example_both.PNG

 

If I yank either side of the 'or' however... (in this case "fulton")

 

m_one_county.PNG

 

...it does perform as expected and removes the dekalb entries.

 

example_cobb.PNG

 

Can anyone identify what I'm overlooking in the M syntax to put this to rest?  Am I backwards somehow on the order of operations?

 

Appreciate the insight!

1 ACCEPTED SOLUTION

@Anonymous 

What if you split the first test into two and reverse them like so:

if 
	[Metro] = "Atlanta" and [county_name] = "dekalb" then 0
else if 
	[Metro] = "Atlanta" and [county_name] = "fulton" then 0
else if
	[Metro] = "Atlanta" or
	[Metro]	= "Charlotte" or
	[Metro]	= "Philadelphia" or
	[Metro]	= "Virginia Beach"
then
	1
else
	0

Does that work?

View solution in original post

9 REPLIES 9
Nathaniel_C
Super User
Super User

@Anonymous ,

Nicely laid out issue! Not sure of the answer, but from a pure testing point of view, maybe try if Atlanta and not dekalb, or if atlanta and not fulton. Change the order of the test. Or if you have time, give the results different numbers for testing.

 

If this solves it great, if not, maybe reach out to imkeF.  She is a magician with m.

 

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@Nathaniel_C 

 

Thanks for the follow-up! 

 

Sadly, yes, that combination has been tried along with any other order I could think of that made sense programmatically.

 

Appreciate the referral, I'll definitely reach out while I keep digging.

@Anonymous 

What if you split the first test into two and reverse them like so:

if 
	[Metro] = "Atlanta" and [county_name] = "dekalb" then 0
else if 
	[Metro] = "Atlanta" and [county_name] = "fulton" then 0
else if
	[Metro] = "Atlanta" or
	[Metro]	= "Charlotte" or
	[Metro]	= "Philadelphia" or
	[Metro]	= "Virginia Beach"
then
	1
else
	0

Does that work?

Anonymous
Not applicable

Hey @jdbuchanan71 !

 

I believe that's one of the combos I've tried...same result:

 

new_test.PNG

 

It's becoming comical at this point 🙂

@Anonymous 

Reverse the test to [county_name] = "dekalb" then 0.

In your example, every county not "dekalb" (including "fulton") would get a 1.

Could this also be a problem with the case?  Would you be better off using [county upper]?

Anonymous
Not applicable

@jdbuchanan71   yep, just saw your updated test:

 

Here's the result:

 

with 0's.PNG

 

...so, consistency in the results returned...just not the correct ones.... ha!

 

I haven't run the logic against the UPPER modified column, I'll give that a shot too

@Anonymous 

You need to change <> to = then return 0

changtoequal.jpg

Anonymous
Not applicable

@jdbuchanan71   @Nathaniel_C 

 

Duuuuuuuuuuuuuuuuude.

 

solved.PNG

 

We got there!  Appreciate the assistance guys.

I am always trying to solve, if for some reason the m language has a glitch, then how about intermediate columns for part of the logic, and then gather up the results in this column?

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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