Excel Power Query:在列值上使用List.MatchAny [英] Excel Power Query: Using List.MatchAny on a column value

查看:584
本文介绍了Excel Power Query:在列值上使用List.MatchAny的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel Power Query中,我有一张表。列A有单个数字。我想标记列A值与列表匹配的记录。问题的一个截止版本是:

In Excel Power Query, I have a table. Column A has single numbers. I want to mark those records where the Column A value matches a list. A cutdown version of the problem is:

let
    TableA = Table.FromColumns({{1,2,4}}, {"A"}),
    ListB = {4,5,6 },
    DPart = Table.AddColumn(TableA, "IsInB", 
            List.MatchesAny(ListB, each _ = [A]))
in
    DPart

DPart行中的错误

I get an error in the DPart line

Expression.Error: We cannot apply field access to the type Number.
Details:
  Value=4
  Key=A

显然,代码试图访问列表的[A]列,而不是TableA的[A]列。

Apparently, the code is trying to access the [A] column of elements of the list, instead of the [A] column of TableA.

完成此操作的正确语法是什么?

What's the correct syntax to accomplish this?

推荐答案

这样做:

let
    TableA = Table.FromColumns({{1,2,4}}, {"A"}),
    ListB = {4,5,6 },
    DPart = Table.AddColumn(TableA, "IsInB", 
            (x) => List.MatchesAny(ListB, each _ = x[A]))
in
    DPart

但我宁愿:

let
    TableA = Table.FromColumns({{1,2,4}}, {"A"}),
    ListB = {4,5,6 },
    DPart = Table.AddColumn(TableA, "IsInB", 
            each List.Contains(ListB, _[A]))
in
    DPart

这篇关于Excel Power Query:在列值上使用List.MatchAny的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆