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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.