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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
guna_knp
Regular Visitor

Unable to implement IF and Text contains in m Query

HI, 

 

I am trying to implement below M query, however gets the error message "Token 'Then' expected", can somebody help me here

 

if Text.Contains([Manager],"On Leave") AND [Grandparent]="" THEN "Error" ELSE"No Error"

2 ACCEPTED SOLUTIONS
collinq
Super User
Super User

Hi @guna_knp ,

 

I beleive that the "then" and the "else" need to be lower case.  Try that and let us know.




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

Proud to be a Datanaut!
Private message me for consulting or training needs.




View solution in original post

shafiz_p
Super User
Super User

@guna_knp M code is case sensitive. For your case, you have to use all lower case for "AND", "THEN", "ELSE".

 

Check here for list of operators 

Hope this help.

If this answered your question, please accept this as a solution!!

View solution in original post

2 REPLIES 2
shafiz_p
Super User
Super User

@guna_knp M code is case sensitive. For your case, you have to use all lower case for "AND", "THEN", "ELSE".

 

Check here for list of operators 

Hope this help.

If this answered your question, please accept this as a solution!!

collinq
Super User
Super User

Hi @guna_knp ,

 

I beleive that the "then" and the "else" need to be lower case.  Try that and let us know.




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

Proud to be a Datanaut!
Private message me for consulting or training needs.




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.