Forum Discussion

CannoK's avatar
CannoK
New Member
4 years ago
Solved

If one source returns an error use other source

Hi everyone,    I'm fairly new to using M code and this problem is giving me headaches. I have the following code: let Bron = Table.NestedJoin(#"csv rabo", {"Rekening_ID"}, dSleutels, {"Rekening_...
  • BA_Pete's avatar
    BA_Pete
    4 years ago

    Hi CannoK ,

     

    Not sure what you mean by "it's not following up with any of the other steps". Your code doesn't tell PQ to perform any steps if Bron2 is used, except for the AlternativeExpand step.

     

    You will need to restructure your query a bit. It should be something like this:

    let
    
    Bron1 = Bron1source,
    Xforms1 = All transformation steps to do if Bron1 is source,
    Final1 = The final output step using Bron1,
    
    Bron2 = Bron2source,
    Xforms2 = All transformation steps to do if Bron2 is source,
    Final2 = The final output step using Bron2,
    
    TestForError = try Final1,
    Output = if TestForError[HasError] then Final2 else Final1
    
    in
    Output

     

    Pete

  • BA_Pete's avatar
    BA_Pete
    4 years ago

    CannoK ,

     

    Cool, glad it looks like it will work for you.

    I think this can be slightly optimised if you are performing exactly the same transformations whether using Bron1 or Bron2, with a structure like this:

    let
    
    Bron1 = Bron1source,
    Xform1 = First transformation step to do if Bron1 is source,
    
    Bron2 = Bron2source,
    Xform2 = First transformation step to do if Bron2 is source,
    
    TestForError = try Xform1,
    Output = if TestForError[HasError] then Xform2 else Xform1
    
    genericXforms = steps to perform on either source, using Output step as first argument in first function,
    genericFinal = Final step of generic xforms
    
    in
    genericFinal

     

    Pete

  • Anonymous's avatar
    Anonymous
    4 years ago

    You sure can, like

     

    try Bron otherwise try AlternativeBron otherwise try thisOtherSource otherwise LastSource

     

    ---Nate