英文:
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""
英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论