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
Anonymous
Not applicable

Delete each occurence of "|" and the four characters before

Hi everyone,

I'm looking for a query that could detect each occurence of | in a column, and then remove this character as well as the four characters before.

I tried multiples things, but either it doesn't work (example of the query: Table.TransformColumns(#"Colonnes supprimées", {"mirakl-sources", each Text.Combine(List.Transform(Text.Split(_, "|"), each if Text.PositionOf(_, "|") > 4 then Text.RemoveRange(_, Text.PositionOf(_, "|") - 4, 5) else _)), type text}) ), or it doesn't suit me.

In fact, as there could be from one occurence of |, to as much as 3 or 4 occurences depending on the initial file (+ other issues with the use of commas, etc) , the method of splitting then combining the columns doesn't work.

Thanks by advance,

Best Regards

1 ACCEPTED SOLUTION

Une version plus simple

let
Source = Votre_Source,
Position = Table.AddColumn(Source, "Position", each Text.PositionOf([#"mirakl-sources"],"|",99)),
Liste_Début = Table.AddColumn(Position, "Début",
each {0}&List.Select(List.Transform([Position], each _ -4), each _>0)),
Texte = Table.AddColumn(Liste_Début, "Texte nettoyé", each
Text.Combine(
List.Transform(
Splitter.SplitTextByPositions([Début])([#"mirakl-sources"]),
each if Text.Contains(_,"|") then Text.AfterDelimiter(_,"|") else _)))
in
Texte

 

On cherche la position des |, on retire 4, on ne prend que les valeurs >0 

on découpe suivant ces positions et on ne prend que les caractères après le |

 

Stéphane

View solution in original post

2 REPLIES 2
slorin
Super User
Super User

Bonjour @Anonymous 

je vais répondre en français, un indice avec #"Colonnes supprimées" 🙂

 

ajouter une colonne pour récupérer la position des |

créer une liste de listes pour déterminer le début et la longueur de chaque partie

on commence par 0, puis position des |+1 et la longueur, position du | suivant moins 4 moins position du |

(j'ai trouvé une formule mais on doit pouvoir simplifier)

dernière étape, utiliser un Splitter.SplitTextByRanges (https://learn.microsoft.com/fr-fr/powerquery-m/splitter-splittextbyranges) pour récupérer les parties voulues du texte initial

 

let
Source = Votre_Source,
Position = Table.AddColumn(Source, "Position", each Text.PositionOfAny([#"mirakl-sources"],{"|"},99)),
Liste_Début_Longueur = Table.AddColumn(Position, "Début_Longueur", each
List.Transform(
List.Zip(
{{0}&List.Transform([Position], each _ +1),
List.Transform([Position], each _ -4)&{Text.Length([#"mirakl-sources"])}}),
each {_{0}, _{1}-_{0}})
),
Texte = Table.AddColumn(Liste_Début_Longueur, "Texte nettoyé", each
Text.Combine(Splitter.SplitTextByRanges([Début_Longueur])([#"mirakl-sources"])))
in
Texte

Stéphane

Une version plus simple

let
Source = Votre_Source,
Position = Table.AddColumn(Source, "Position", each Text.PositionOf([#"mirakl-sources"],"|",99)),
Liste_Début = Table.AddColumn(Position, "Début",
each {0}&List.Select(List.Transform([Position], each _ -4), each _>0)),
Texte = Table.AddColumn(Liste_Début, "Texte nettoyé", each
Text.Combine(
List.Transform(
Splitter.SplitTextByPositions([Début])([#"mirakl-sources"]),
each if Text.Contains(_,"|") then Text.AfterDelimiter(_,"|") else _)))
in
Texte

 

On cherche la position des |, on retire 4, on ne prend que les valeurs >0 

on découpe suivant ces positions et on ne prend que les caractères après le |

 

Stéphane

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.