Forum Discussion
Extract Multiple Occurrences of Text Between Delimiters
- 3 years ago
- List.Accumulate to create each delimited substring
- Count the number of delimiters
- Create a list and extract every other number (the start index of each delimiter pair
- Note that my data comes from an Excel table. Change the Source= line to reflect your actual data source.
let Source = Excel.CurrentWorkbook(){[Name="Table26"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}), Delim = "~~", Extract = Table.AddColumn(#"Changed Type", "Text Between ~~", each Text.Combine( List.Accumulate( List.Alternate(List.Numbers(0, List.Count(Text.Split([Column1], "~~"))-1),1,1,1), {}, (state, current)=> state & {Text.BetweenDelimiters([Column1],Delim,Delim,current)}),"; "), type text) in Extract - List.Accumulate to create each delimited substring
This is very close but I am not only extracting single words every time. I am also extracting whole phrases so I think splitting the text at each space is causing errors for me.
Here is a new example that shows how both words and phrases need to be extracted. How can we change your code to fix this?
- List.Accumulate to create each delimited substring
- Count the number of delimiters
- Create a list and extract every other number (the start index of each delimiter pair
- Note that my data comes from an Excel table. Change the Source= line to reflect your actual data source.
let
Source = Excel.CurrentWorkbook(){[Name="Table26"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
Delim = "~~",
Extract = Table.AddColumn(#"Changed Type", "Text Between ~~", each
Text.Combine(
List.Accumulate(
List.Alternate(List.Numbers(0, List.Count(Text.Split([Column1], "~~"))-1),1,1,1),
{},
(state, current)=>
state & {Text.BetweenDelimiters([Column1],Delim,Delim,current)}),"; "), type text)
in
Extract
- daveseibert2 years agoNew Member
Hi All,
This is much easier:
List.RemoveFirstN(List.Transform(Text.Split(YOUR_TEXT_VARIABLE, "START_DELIM"), each Text.BeforeDelimiter(_, "END_DELIM")), 1)- fox2522 years agoFrequent Visitor
This does seem much simplier. One issue is it captures the first value infront of the start delimiter. Any suggestions?
Goal: Capture all numeric values, sum and convert to decimal (not present in code yet)
Code:
Table.AddColumn(#"Removed Other Columns1", "Custom", each List.Transform(Text.Split([#"FTE`s required"], "["), each Text.BeforeDelimiter(_, "%")))
Field Value:AUTO1[100%],MOT1[100%],MOT2[25%],OPS1[25%] Desired Result:
{100,100,25,25}
Current Result
{Auto1,100,100,25,25}
End state desired result - Attempting to use List.Sum with additional LEN logic to insert decimal but can't get there until text value is removed.
2.50
- AlienSx2 years ago
Super User
List.Alternate( Splitter.SplitTextByAnyDelimiter({"[", "%]"})(value), 1, 1 )to get the list or even
let value = "AUTO1[100%],MOT1[100%],MOT2[25%],OPS1[25%]", summm = List.Sum( Record.FieldValues( Expression.Evaluate( "[" & Text.Combine( List.ReplaceMatchingItems( Text.ToList(value), {{"[", "="}, {"]", ""}, {"%", ""}} ), "" ) & "]" ) ) ) in summmto get sum of values 😁
- Anonymous3 years agoNot applicable
ronrsnfld Thank you so much! This worked perfectly!
- JustSayJoe2 years ago
Advocate IV
How do we accomplish this from a calculated table column?
- ronrsnfld2 years ago
Super User
That's a different question. Suggest you post it as such so as to attract some DAX experts.