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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Add trim after Split

I am using this to Find/Replace a table

 

let
   Repl = Table.Buffer(ReplacementsTable),
   Text = Text,
    Result = Table.AddColumn(Text, "Changed Text Expected",
    each Text.Combine(
    List.Transform(
    Text.Split([Text], "|"),
    each
    try Repl[Replace With]{List.PositionOf(Repl[Word To Replace], _)}
    otherwise _
    ),
    "|" )
)
[[Changed Text Expected]]
in
Result

 

I am splitting a column on a pipe delimiter

Is it possible to add trim at this point?

Text.Split([Text], “|”),

I have strings that look like

the|cat sat |on the mat

find replace
cat sat >> bear

does not get replaced because of the space after the "sat" in “the|cat sat |on the mat”

 

Thanks

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use below in place of Text.Split([Text], "|")

Text.Split(Text.Replace(Text.Replace([Text]," |","|"),"| ","|") "|")

 

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

You can replace 

Text.Split([Text], "|")

with

List.Transform(Text.Split([Text], "|"), Text.Trim)

to trim each string after separating by "|".

 

Here's another implementation that uses List.ReplaceMatchingItems:

let
  Repl = Table.Buffer(ReplacementsTable), 
  Text = Text, 
  Result = Table.AddColumn(
    Text, 
    "Changed Text Expected", 
    each Text.Combine(
      List.ReplaceMatchingItems(
        List.Transform(Text.Split([Text], "|"), Text.Trim), 
        List.Zip({Repl[Word To Replace], Repl[Replace With]})
      ), 
      "|"
    )
  )
in
  Result
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use below in place of Text.Split([Text], "|")

Text.Split(Text.Replace(Text.Replace([Text]," |","|"),"| ","|") "|")

 

Anonymous
Not applicable

Thank you. This worked great!

AnkitKukreja
Super User
Super User

@Anonymous 

 

Do you have limited scenarios then maybe try replacing value, else could you please share some sample data (5-10) rows and the expected output.

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.