从长字符串中提取文本使用 Power Query

huangapple go评论101阅读模式
英文:

Extract text from long string with power query

问题

有没有办法提取文本,并在长字符串中包含特定文本时创建新列。例如,如果我有一个长的逗号分隔字符串,有时其中包含“蓝牙”,有时没有,但我想在长字符串中包含蓝牙时创建一个新列。您能在Power Query中实现这个吗?

我知道我可以将长字符串以逗号分隔,但其中有一部分应该包含逗号。

英文:

Is there a way where you can extract a text and create a new column if a specific text is in the long string. Like if I have this long comma separated string where sometimes Bluetooth is in it and sometimes not but I want to create a new column with Bluetooth if it's in the long string. Is there a way you can do it in power query?

I know I can comma separate the long string but there some of it that is supposed to have commas.

答案1

得分: 0

以下是翻译好的部分:

"你没有具体说明,但通常有两种方法。一种是在文本中查找短语,另一种是在逗号分隔的每个文本集合中查找短语。

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom1", each if Text.Contains([Column1],"bluetooth") then [Column1] else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each Text.Combine(try List.RemoveNulls(List.Transform(Text.Split([Custom1],","), each if Text.Contains(_,"bluetooth") then _ else null)) otherwise {},",") )
in #"Added Custom1""

从长字符串中提取文本使用 Power Query

英文:

You didn't specify but in general here is two ways. One looks for a phrase anywhere in text, one for a phrase within each separate set of comma-separated text

let  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom1", each if Text.Contains([Column1],"bluetooth") then [Column1] else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each Text.Combine(try List.RemoveNulls(List.Transform(Text.Split([Custom1],","), each if Text.Contains(_,"bluetooth") then _ else null)) otherwise {},",")    )
in  #"Added Custom1"

从长字符串中提取文本使用 Power Query

huangapple
  • 本文由 发表于 2023年7月20日 20:11:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定