cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CloudMonkey Post Patron
Post Patron

Power Query M code equivalent to "iferror" function

Hi,

 

Please can you tell me the Power Query M code equivalent for the "iferror" function in excel?

 

Thanks,

 

CM

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ChrisHaas Solution Sage
Solution Sage

Re: Power Query M code equivalent to "iferror" function

use "try....otherwise".

 

try <some code hear that may result in an error> otherwise  <run this code in case of error>

 

note that try and otherwise are NOT capitalized.  Also, no commas are needed.

View solution in original post

6 REPLIES 6
Highlighted
ChrisHaas Solution Sage
Solution Sage

Re: Power Query M code equivalent to "iferror" function

use "try....otherwise".

 

try <some code hear that may result in an error> otherwise  <run this code in case of error>

 

note that try and otherwise are NOT capitalized.  Also, no commas are needed.

View solution in original post

Microsoft v-jiascu-msft
Microsoft

Re: Power Query M code equivalent to "iferror" function

Hi @CloudMonkey,

 

Related documentations: https://msdn.microsoft.com/en-us/library/mt186368.aspx  and  https://msdn.microsoft.com/en-US/library/mt267542.aspx.

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Microsoft v-jiascu-msft
Microsoft

Re: Power Query M code equivalent to "iferror" function

Hi @CloudMonkey,

 


Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_AT
Regular Visitor

Re: Power Query M code equivalent to "iferror" function

Hi all,

unfortunately this doesn't solve my issue.

  1. There's a textfield, with e.g. 01.02.2019 - 28.02.2019
  2. I divide this column into column A (startdate): 01.02.2019 and column B (enddate): 28.02.2019
  3. Now it can happen, that there is 01.02.2019 - 30.02.2019 written
  4. Due 30.02.2019 definitively an error occurs

If something like (4) happens, in column B must be written 31.12.2030 (e.g) and in a third column "check supplydate".

 

How can I fix this?

Maybe iferror / try.....otherwise is the wrong idea?

 

Thx in advance for your help.

BekahLoSurdo Resolver IV
Resolver IV

Re: Power Query M code equivalent to "iferror" function

@Greg_AT  try this:

 

let
    Source = Table.FromList({[TextField ="02.01.2019 - 02.28.2019"],[TextField ="02.01.2019 - 02.30.2019"]},Record.FieldValues, {"TextField"}),
    #"Added StartDate" = Table.AddColumn(Source, "StartDate", each try Date.FromText(Text.BeforeDelimiter([TextField], " ")) otherwise Date.FromText("12/31/2030")),
    #"Added EndDate" = Table.AddColumn(#"Added StartDate", "EndDate", each try Date.FromText(Text.AfterDelimiter([TextField], " ", 1)) otherwise Date.FromText("12/31/2030")),
    #"Added Action" = Table.AddColumn(#"Added EndDate", "Action", each if [StartDate] = Date.FromText("12/31/2030") or [EndDate] = Date.FromText("12/31/2030") then "check supplydate" else "")
in
    #"Added Action"

DateCheck.PNG

 

 

Greg_AT
Regular Visitor

Re: Power Query M code equivalent to "iferror" function

Hi Bekah,
this works perfect - thank you very much...

Best wishes

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors