在电源查询中使用文本(sub)字符串查找某些代码组合

发布于 2025-01-20 04:05:11 字数 1052 浏览 0 评论 0原文

我有类似的问题(下面的链接),但它只是让我对我在路上发现的问题说“附加”。

查找使用文本字符串的所有代码组合Power Query

我需要的是使用子字符串作为查找来提取一个字符串中的精确匹配项(或者我会说 Power Query 中的模糊匹配项)。

(请忽略屏幕截图和数据中的 T1 和 T2)

正如您在表 3 中看到的(T3)是主字符串,T4 中是标记略有不同的子字符串(例如 JH 而不是 JH0 或否则..)这正是我所需要的,按原样使用子字符串,但过滤掉主字符串并获取 T5 中的结果。

我在 Power Query 中使用模糊匹配尝试了运气,但问题是之后当我有更多实例的不同子字符串时,我的查询由于“列不存在等等......它必须是动态的”而失败。

我想在 Power Query 中找到解决方案!

https://docs.google.com/spreadsheets/d/1Ji1kyV7UsD2YBRJgWUY5zisyL3ySPGwW/edit?usp=sharing&ouid=101738555398870704584&rtpof=true&sd=true

在此处输入图像描述

I had similar question (link below), but it just lets say "add-on" to my issue that I found on the way.

Find all code combinations using text string in Power Query

What I need is to extract exact matches (or I would say fuzzy matches in Power Query) that are in one string using substring as lookup.

(Please ignore T1 and T2 in the screenshot and data)

As you can see in Table 3 (T3) is a main string, and in T4 is substring with slightly different markings (like JH instead of JH0 or else..) Thats exactly what I need, to use substring as it is but to filter out main string and get results as they are in T5.

I tried my luck using Fuzzy matching in Power Query but the problem is afterwards when I have different substring with more instances, my query is failing due to "column doesn't exist and so on...it has to be dynamic.

I would like to have solution in Power Query!

https://docs.google.com/spreadsheets/d/1Ji1kyV7UsD2YBRJgWUY5zisyL3ySPGwW/edit?usp=sharing&ouid=101738555398870704584&rtpof=true&sd=true

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↙厌世 2025-01-27 04:05:11
let Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
FindList = Text.Split(Table.ReplaceValue(Table3,",","_",Replacer.ReplaceText,{"String"})[String]{0},"_"),
FindList2 = List.Transform(FindList, each Text.Remove(_,{"0".."9"})),
Newlist=Text.Split(Source[Substring]{0},"_"),
Newlist2=Text.Combine(List.Transform(Newlist, each try FindList{List.PositionOf(FindList2,_)} otherwise "missing"),"_")
in Newlist2

它在做什么 (a) 在 a 或 _ 处将 table3 拆分为一个列表 (b) 复制 A 中的列表并删除所有数字 (c) 在每个 _ 处将 table4 拆分为一个列表 (d) 将 c 中的每个值与b.如果存在匹配,则使用该位置编号从 a 中提取值,否则输入“missing”(e) 将结果用逗号分隔放回一起

在此处输入图像描述

根据评论,备用版本适用于来自的多个匹配表3:

Newlist2=Text.Combine(List.Transform(Newlist, each try
if List.Count(List.PositionOf(FindList2,_,20))=0 then "missing" else
Text.Combine( List.Transform(List.PositionOf(FindList2,_,20), each FindList{_}),"_")  otherwise "missing"),"_")
let Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
FindList = Text.Split(Table.ReplaceValue(Table3,",","_",Replacer.ReplaceText,{"String"})[String]{0},"_"),
FindList2 = List.Transform(FindList, each Text.Remove(_,{"0".."9"})),
Newlist=Text.Split(Source[Substring]{0},"_"),
Newlist2=Text.Combine(List.Transform(Newlist, each try FindList{List.PositionOf(FindList2,_)} otherwise "missing"),"_")
in Newlist2

what it is doing (a) split table3 into a list at either a , or _ (b) duplicate the list from A and remove all numbers (c) split table4 into a list at each _ (d) match each value from c against b. If there is a match, use that position number to pull the value from a, otherwise put "missing" (e) put the results back together with a comma separation

enter image description here

Per comments, alternate version that works for multiple matches from Table3:

Newlist2=Text.Combine(List.Transform(Newlist, each try
if List.Count(List.PositionOf(FindList2,_,20))=0 then "missing" else
Text.Combine( List.Transform(List.PositionOf(FindList2,_,20), each FindList{_}),"_")  otherwise "missing"),"_")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文