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
LD1
Helper III
Helper III

Translate query in M language : "if not contains"

Hi, 

 

I would like to tranform this requete in M language but i don't get it because i didn't find "if not contains" or "exclude" in this way. 

 

Here this is the formula:

 

IF [Marque]="AAAAAA" THEN IF NOT [Pôle] in ("POLE 1","POLE 2","POLE 3") THEN 1

ELSE 0 END

ELSEIF [Marque]="BBBBBB " THEN

IF NOT [Pôle] in ("POLE 1","POLE 4","POLE 5",) THEN 1

ELSE 0 END

 

Can you help me to resolve it? 

Thank you in advance,

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @LD1 

 

You can add a custom column with below M code. List.Contains

if [Marque] = "AAAAAA" then ( if not List.Contains( {"POLE 1","POLE 2","POLE 3"}, [Pôle]) then 1 else 0 ) else if [Marque] = "BBBBBB" then ( if not List.Contains( {"POLE 1","POLE 4","POLE 5"}, [Pôle]) then 1 else 0 ) else null

vjingzhang_0-1658473710379.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @LD1 

 

You can add a custom column with below M code. List.Contains

if [Marque] = "AAAAAA" then ( if not List.Contains( {"POLE 1","POLE 2","POLE 3"}, [Pôle]) then 1 else 0 ) else if [Marque] = "BBBBBB" then ( if not List.Contains( {"POLE 1","POLE 4","POLE 5"}, [Pôle]) then 1 else 0 ) else null

vjingzhang_0-1658473710379.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

otravers
Community Champion
Community Champion

If you use the filtering UI it will generate the M code for you:

otravers_0-1658243233819.png

 

You can start by adding a single filter then edit the Filter step (cogwheel icon) and switch to Advanced mode to add your sequence of conditions:

otravers_1-1658243402065.png

 

 

You'll see the M code for "does not contain" is: not Text.Contains

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

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.