如何在Excel数据模型中使用通配符复制索引/匹配查找?

发布于 2025-02-13 18:09:59 字数 1811 浏览 0 评论 0原文

tl; dr:标题说明了一切:是否有任何方法可以使用通配符在数据模型中查找excel索引匹配,

我试图重新组织一个使用PowerQuery来导入和导入和导入和导入和将数据从外部来源转换为数据模型。然后,该数据用于生成几个枢轴表并提取特定数据。 我需要在数据模型中添加计算出的列,该列相对容易使用普通的Excel公式进行计算,但我找不到在数据模型中进行任何方法。 问题在于,数据模型非常擅长替换Vlookup,但不支持通配符,这在这种情况下是必不可少的。 当然,以下是一个玩具示例来说明问题:

我有一个事实表 tblfact ,看起来像这样:

“事实表“

这个想法是添加列,根据列 country,model和Salesman 的列显示消息,并具有以下逻辑:

  • if model 是A1,无论其他
  • 如何
  • 列 列,显示“哦,是的”
  • 在原始文件中显示字符串“默认消息”

这是通过添加嵌套的,如果这样的:

=IF([@Model]="A1";"Sold an A1";IF([@SalesMan]="Mario";"ITSAME";IF([@Country]="US";"OH YEAH";"Default message")))

在任何其他情况下, 需要经常进行更新,很难曼坦。 我想到了添加一张查找桌子,并利用了索引和匹配允许通配符的事实。

以下公式将复制嵌套IF的行为: = index(tblookup [message]; match(1; match(tblookup [lukey]; [@luvalue]; 0); 0); 0)) 查找更容易搭载,并添加特定情况。

现在如果我被迫使用数据模型的事实,这将有效:

  • 真实文件包含更多比一百万行和大约50列,我不能将所有内容都转储到表格中,并添加一列与索引匹配的公式匹配
  • 某些需要查找的列,只有在数据模型中可用,因为来自相关表数据模型。好像推销员被计算为=相关的(尚可使用[推销员]),

我尝试了LookupValue功能,但它不支持通配符,我也尝试了各种过滤器和搜索组合返回错误。

其他相关注意事项:

  • 我知道索引匹配查找对查找表的顺序很敏感,但是我可以输入外部检查
  • 事实表中形成luvalue的一些列,可以包含任何东西,无法输入在查找表中所有可能的情况。
  • 我宁愿在数据模型中找到DAX中的解决方案,但是如果不可能,从理论上讲,我可以使用Power查询来计算所有TBLFACT的所有列,并尝试在Power Query中查找。问题在于,Power查询的合并不支持通配符。

TL;DR: The title says it all: is there any way to reproduce an excel INDEX-MATCH look up in the data model with wildcards

I am trying to reorganize an Excel file that uses PowerQuery to import and transform data from external sourced and load it to the data model. This data is then used to produce several pivot tables and extract specific data.
I have the need to add a calculated column in the data model that would be relatively easy to calculate with a plain Excel formula but I cannot find any way to make it in the data model.
The problem is that the data model is great at replacing vlookups but it does not support wildcards, which are essential in this use scenario.
The following is of course a toy example to illustrate the issue:

I have a fact table tblFact that looks like this:

Fact table

The idea is to add column that display a message depending on columns Country, Model and SalesMan, with the following logic:

  • If Model is A1, regardless of the other columns, display "Sold an A1"
  • If SalesMan is Mario, regardless of the other columns, display "ITSAME"
  • If Country is US, regardless of the other columns, display "OH YEAH"
  • In any other case display the string "Default message"

In the original file this was done by adding a nested IF, like this:

=IF([@Model]="A1";"Sold an A1";IF([@SalesMan]="Mario";"ITSAME";IF([@Country]="US";"OH YEAH";"Default message")))

But, since in the real case there are many more cases, with more complex conditions and they need to be updated fairly often, it was very hard to mantain.
I thought of adding a look up table and take advantage of the fact that INDEX and MATCH allow for wildcards.

look up table

The following formula would replicate the behaviour of the nested IFs:
=INDEX(tblLookUp[Message];MATCH(1;MATCH(tblLookUp[LUKey];[@LUValue];0);0))
And the lookup is much easier to mantain and add specific cases.

look up result

Now this would work if not for the fact that I am forced to use the data model:

  • The real file contains more than a million rows and about 50 columns, I cannot dump everything in a table and add a column to use the formula with INDEX MATCH
  • Some of the columns that need to be looked up are only available in the data model as come from related tables in the data model. As if Salesman were calculated as =RELATED(yetAnotherTable[SalesMan])

I have tried the LOOKUPVALUE function but it does not support wildcards, I have also tried various combinations of FILTER and SEARCH but I couldn't even get a formula that doesn't return an error.

Other relevant notes:

  • I am aware that the index match lookup is sensitive to the order of the lookup table but I can enter an external check
  • Some of the columns that form LUValue in the fact table can contain litterally anything, it is not possible to enter in the look up table all possible cases.
  • I'd rather find a solution in DAX to be used in the data model, but if it is not possible I could, in theory, have power query calculate all columns of tblFact, and try to make a look up in power query. Problem is at that point that Power Query's merge does not support wildcards.

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

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

发布评论

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

评论(1

无敌元气妹 2025-02-20 18:09:59

尝试此计算的列:

=
PATHITEM(
    CONCATENATEX(
        FILTER( tblLookUp, SEARCH( tblLookUp[LUKey], MainTable[LUValue],, 0 ) ),
        tblLookUp[Message],
        "|"
    ),
    1
)

搜索支持通配符。

Try this Calculated Column:

=
PATHITEM(
    CONCATENATEX(
        FILTER( tblLookUp, SEARCH( tblLookUp[LUKey], MainTable[LUValue],, 0 ) ),
        tblLookUp[Message],
        "|"
    ),
    1
)

SEARCH supports wildcards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文