Powerbi Power BI查询-将分隔符之间的文本提取到新列

Powerbi Power BI查询-将分隔符之间的文本提取到新列,powerbi,powerquery,Powerbi,Powerquery,我有一个表,其中包含以下格式的文本列: 随机文本[ABC-]其他随机文本 对于包含[ABC]的所有行,我想将ABC提取到一个新列,其中至少有4个随机数,但可以更多 这就是我迄今为止的工作成果: = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([TextColumn], "[ABC") then "FOUND" else "NotFound") 但是我不能用数字来提取子字符串 有人能帮我吗? 非常感谢。 dk使

我有一个表,其中包含以下格式的文本列:

随机文本[ABC-]其他随机文本

对于包含[ABC]的所有行,我想将ABC提取到一个新列,其中至少有4个随机数,但可以更多

这就是我迄今为止的工作成果:

= Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([TextColumn], "[ABC") then "FOUND" else "NotFound")
但是我不能用数字来提取子字符串

有人能帮我吗? 非常感谢。 dk

使用以下方法解决:

= Table.AddColumn(#"Changed Type", "Custom", each 
if Text.Contains([TextColumn], "[ABC-") then
(Text.Range((Text.Range([TextColumn], (Text.PositionOf([TextColumn], "[ABC-", Occurrence.First))+1, 14)), 0, (Text.PositionOf((Text.Range([TextColumn], (Text.PositionOf([TextColumn], "[ABC-", Occurrence.First))+1, 14)), "]", Occurrence.First))))
else "None")
正如评论中所建议的那样

 Text.PositionOf
会导致速度更快

谢谢

不太复杂的版本 应该是这样的
一些澄清问题:方括号是任何字符串的一部分吗?任何可能的字符串是否包含ABC-哪个regexp与任何源字符串匹配?^\w+[ABC-\d{4,}]\w+$,^.*[ABC-\d{4,}].*$,^.[[a-cA-C]-\d{4,}\].$谢谢。我用以下公式解决了:每个if Text.Contains[TextColumn],[ABC-然后Text.RangeText.Range[TextColumn],Text.PositionOf[TextColumn],[ABC-,发生率.First+1,14,0,Text.PositionOfText.Range[TextColumn],Text.PositionOf[TextColumn],[ABC-,发生率.First+1,14,0],发生率。首先,它可能看不到最佳解决方案,但它正在工作,可能有计算更好的解决方案。我不需要提取[]但是只有ABC和字符,直到下面]。@d82k你的答案看起来很棒!建议在StackOverflow上,如果你找到问题的答案,自己添加答案。顺便说一句,如果速度很重要,也许你可以避免使用Text.Contains函数,只需调用Text.PositionOf[TextColumn],[ABC-一次;如果未找到子字符串,PositionOf将返回-1。
let
    tbl = #table({"TextColumn"}, {
        {"qwer"},
        {"qwer [ABC-1234] asdf"},
        {"qwer [ABC-1234]"},
        {"[ABC-1234] asdf"}
    }),
    AddColumn = Table.AddColumn(tbl, "ExtractedNumber", each try Splitter.SplitTextByEachDelimiter({"[ABC-","]"})([TextColumn]){1} otherwise "None")
in
    AddColumn