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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sativagate
Regular Visitor

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.CONDITIONS(GAUCHE($D2;3)="sol";"SOL";GAUCHE($D2;3)="PAP";"PAP";$D2>0;"GARE");"")

dans un exemple de donné comme suite. sachant que la colonne Emplacemnt est variable.

Emplacement résultat
9GARE
sol15SOL
BOUILLEBOUILLE

 

Le langage suivant comporte une erreur, je ne sais pas sur quel paramètre 

 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.CONDITIONS(GAUCHE($D2;3)="sol";"SOL";GAUCHE($D2;3)="PAP";"PAP";$D2>0;"GARE");"")

dans un exemple de donné comme suite. 

 

unbcD : Emploi E:résultat
   9GARE
   sol15SOL
   BOUILLEBOUILLE

 

 

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @sativagate ,

 

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



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

Hi @sativagate ,

 

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



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
sativagate
Regular Visitor

Bonjour  BA_Pete 

Merci beaucoup de votre réponse j'aime cette solution très simple .

Vous est admirable , et sa fonctionne super bien sauf pour les deux 

par contre quand j'ai une ligne comme exemple si dessous :

8 et 9 = erreur 

8 & 9 = erreur

sinon si Text.Contains ([GARE]) = "&" then "GARE"

sativagate_0-1661465506051.png

Merci encor de votre générosité et de votre aide.

cordialement 

 

 

Hi @sativagate ,

 

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



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Bonjour  BA_Pete

Merci encore, mais malheureusement cela ne fonctionne pas.

Cette ligne me donne une erreur de DataFormat.Error.

if Text.Contains([GARE],Character.FromNumber(38)) then "GARE"

Alors j'ai contourné le problème en utilisant la correction d'erreur.

#"Erreurs prolongées" = Table.ReplaceErrorValues(#"Lignes filtrées", {{"gareN", "GARE"}})
in
#"Erreurs prolongées"

Je vous remercie beaucoup pour m'avoir aidé.

 

 

APERÇU
 
 
 
BA_Pete
Super User
Super User

Hi @sativagate ,

 

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



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.