Forum Discussion

PhilippeMuniesa's avatar
PhilippeMuniesa
Icon for Resolver I rankResolver I
5 years ago
Solved

IF then with multiple lines

Hello   Hello, I stumble on the syntax of an If then else with several instructions, what I want to do: if condition then      line instructions1,      line instructions2,      line instruction...
  • AlB's avatar
    5 years ago

    Hi PhilippeMuniesa 

    Try this. You might need to add a comma at the very end depending on what comes next.

    Si_Pas_CP = if Table.RowCount(Supprime_Lignes_Sans_CPart) = 0 then
        let 
            Groupe_compte_Compte_Part = Table.Group(Source, {"CompAuxNum", "CompAuxLib", "CompteNum", "CompteLib"}, {{"Debit", each List.Sum([Debit]), type nullable number}, {"Credit", each List.Sum([Credit]), type nullable number}}),
            CompteNum_texte_pour_filtre = Table.TransformColumnTypes(Groupe_compte_Compte_Part ,{{"CompteNum", type text}}),
            BufferList = List.Buffer(CP_Dans_PCG),
            LenRacine = Text.Length(CP_Dans_PCG {0}),
            Ajoute_Col_racine = Table.AddColumn(CompteNum_texte_pour_filtre, "Racine_CompteNum", each Text.Start([CompteNum],LenRacine )),
            Filtre_Selon_Racines_Selectionnes = Table.SelectRows (Ajoute_Col_racine, each List.Contains (BufferList , [Racine_CompteNum])),
            Compte_Num_Re_Type_Entier = Table.TransformColumnTypes(Filtre_Selon_Racines_Selectionnes,{{"CompteNum", Int64.Type}}),
            Tri_Compte_Num = Table.Sort(Compte_Num_Re_Type_Entier,{{"CompteNum", Order.Ascending}})
        in 
            Tri_Compte_Num
    else
        null

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

  • PhilippeMuniesa's avatar
    PhilippeMuniesa
    5 years ago

    Hello again,

     

    I answer myself to avoid a waste of time to the super users..

     

    After various attempts I just found the syntactic solution

     

    let

           Source,

           step1,

           step2,

           Conditional_Req =  if statement then    // Conditional_Req result is result1 or Result2 at the end of each occurrence of                                      conditional treatment (in)

                let

                     step3,

                     Step4,

                     Step5,

                    Result1

                in 

                   Result1

           else

                let

                   step1b,

                    Step2b,

                    Result2

                in

                     Result2 // if treatments continue, a comma is required at this level, whereas the first in before the                                                other   did not require a comma

     

         Step3c (based on Conditional_Req),  //resume treatments from the name of the conditional requete

         Step4c,

         FinalResult

     

    in

     

    FinalResult

     

     

    I hope to have contributed to this forum by providing a solution to other users or contributors, and to replace the Super Users that set me on the path, and forced me to think about finding the solution

     

    Philippe Muniesa