Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

power query

 Bonjour  J'ai un probleme a le code M je ne suis pas doué pour les Expression de language M ,mais  de base le code est sencé faire et remplacé ma formule dans la colonne E Celule E2 a E40  SI.CON...
  • BA_Pete's avatar
    3 years ago

    Hi Anonymous ,

     

    In M code, it would be something like this:

    if Text.Start(Text.Lower([Emplacement]), 3) = "sol" then "SOL"
    else if Text.Start(Text.Lower([Emplacement]), 3) = "pap" then "PAP"
    else if Number.From([Emplacement]) > 0 then "GARE"
    else [Emplacement]

     

    Note that M is completely case sensitive, so I've used "Text.Lower" functions to correct this before the evaluation of these conditions.

     

    Pete

  • BA_Pete's avatar
    BA_Pete
    3 years ago

    Hi Anonymous ,

     

    Try this instead:

    try
        if Text.Contains([Emplacement], Character.FromNumber(38)) then "GARE"  //38 is "&" Unicode character
        else if Text.Start(Text.Lower([Emplacement]), 3) = "sol" then "SOL"
        else if Text.Start(Text.Lower([Emplacement]), 3) = "pap" then "PAP"
        else if Number.From([Emplacement]) > 0 then "GARE"
        else [Emplacement]
    otherwise [Emplacement]

     

    The Character.FromNumber(38) picks out any values that contain "&", and the try...otherwise block escapes any further errors.

     

    Pete