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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
RafaelKnuth
Advocate I
Advocate I

M-Language: "else" vs. "otherwise" statement usage

When am I supposed to use which of both statements?

I was wrongly assuming that I can use both interexchangeably.

Thanks in advance for a clarification.

 

On a separate note: What's the correct terminology here?

I am borrowing "statement" from Python terminology, I am not sure though if the same jargon applies here (I am new to coding, Python was the first language I learned, M is becoming my second).

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

To the best of my knowledge, M does not use "otherwise", here is a good article on IF statement in M:

 

https://www.excelguru.ca/blog/2014/08/27/the-if-function-in-power-query/

 

and here is a great article by @ImkeF on an M switch  statement:

 

http://www.thebiccountant.com/


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Yes! & to sum Gregs @Greg_Deckler hints up:

 

1) else goes with if for conditions

2) otherwise goes with try for error handling

 

Cheers, Imke

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
ricardocamargos
Continued Contributor
Continued Contributor

Greg_Deckler
Super User
Super User

To the best of my knowledge, M does not use "otherwise", here is a good article on IF statement in M:

 

https://www.excelguru.ca/blog/2014/08/27/the-if-function-in-power-query/

 

and here is a great article by @ImkeF on an M switch  statement:

 

http://www.thebiccountant.com/


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Looked up a few solutions and was able to use try .... otherwise in M code just now, saw your answer and wanted to encourage you to to try it!

I ran into the "else" and "otherwise" statements in Miguel Escobar's book "M is for (Data) Monkey".  Thanks for sharing!

Also, if you want THE definitive guide to M you can download the language specification here:

 

https://msdn.microsoft.com/en-us/library/mt807488.aspx

 

It's a bit dry but you'll learn a lot.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Now that I am thinking about it, I believe you actually do use "otherwise" in "try" statements, so something like:

 

let
    Source = Web.Contents("http://localhost:5001/foo"),
    Parsed = try Json.Document(Source) otherwise error "Update credentials please"
in
    Parsed

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Yes! & to sum Gregs @Greg_Deckler hints up:

 

1) else goes with if for conditions

2) otherwise goes with try for error handling

 

Cheers, Imke

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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