Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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
Solved! Go to 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
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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |