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!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
I couldn't find a example for how to do this (Removing Repeating Spaces) so I am posting this. It would work for any repeating Characters beyond spaces.
let
Source = "abc ABC DEF ABC",
StringToCleanOfExtraSpaces = Source,
SourceSingleSpaced = Text.Combine(
List.RemoveNulls(
List.Transform(
List.Positions(
Text.ToList(
StringToCleanOfExtraSpaces)), each
if _ = 0 then Text.Range(StringToCleanOfExtraSpaces, _ , 1)
else if Text.Range(StringToCleanOfExtraSpaces, _ -1,1)=" " and Text.Range(StringToCleanOfExtraSpaces, _ ,1)=" " then null
else Text.Range(StringToCleanOfExtraSpaces, _, 1))))
in
SourceSingleSpacedSolved! Go to Solution.
Hi @Anonymous,
There is no stock function to remove repeating spaces. If you only concerned about spaces, the function can be shorter, but not much:
let
Source = "abc ABC DEF ABC",
StringToCleanOfExtraSpaces = Source,
SourceSingleSpaced = Text.Combine(
List.Accumulate(
Text.ToList(StringToCleanOfExtraSpaces), {}, (a, n)=> if n = " " and List.Last(a) = " " then a else a & {n}))
in
SourceSingleSpacedKind regards,
John
Here are a couple of shorter options.
let
StringToClean = " abc ABC DEF ABC ",
SplitText = Text.Split(StringToClean, " "),
RemoveBlanks = List.Select(SplitText, each _ <> ""),
Result = Text.Combine(RemoveBlanks, " ")
in
Result
This is a slightly simplified version of this post (only works for spaces).
let
StringToClean = " abc ABC DEF ABC ",
Result = Text.Combine(Splitter.SplitTextByWhitespace()(Text.Trim(StringToClean)), " ")
in
Result
Credit to Frank Tonsen's comment on this post.
Hi @Anonymous,
There is no stock function to remove repeating spaces. If you only concerned about spaces, the function can be shorter, but not much:
let
Source = "abc ABC DEF ABC",
StringToCleanOfExtraSpaces = Source,
SourceSingleSpaced = Text.Combine(
List.Accumulate(
Text.ToList(StringToCleanOfExtraSpaces), {}, (a, n)=> if n = " " and List.Last(a) = " " then a else a & {n}))
in
SourceSingleSpacedKind regards,
John
Here are a couple of shorter options.
let
StringToClean = " abc ABC DEF ABC ",
SplitText = Text.Split(StringToClean, " "),
RemoveBlanks = List.Select(SplitText, each _ <> ""),
Result = Text.Combine(RemoveBlanks, " ")
in
Result
This is a slightly simplified version of this post (only works for spaces).
let
StringToClean = " abc ABC DEF ABC ",
Result = Text.Combine(Splitter.SplitTextByWhitespace()(Text.Trim(StringToClean)), " ")
in
Result
Credit to Frank Tonsen's comment on this post.
For spaces that last example is slick
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 |
| User | Count |
|---|---|
| 20 | |
| 14 | |
| 11 | |
| 10 | |
| 9 |