函数从表中返回查找值

时间:2019-01-07 18:15:45

标签: powerbi powerquery

我正在尝试构建一个Power Query函数,该函数将从基于输入参数查找的表中返回一个值。例如

Table:
Name    Team
George  Server
June    DBA

现在,我想向函数提供Name并返回位置。源表是在同一Excel工作簿中定义的表。我从那开始,但是不确定我哪里失败了:

(EmployeeName as text) =>

let 
    Source = Excel.CurrentWorkbook(){[Name="Employees"]}[Content],
    EmployeeRow = Table.SelectRows(Source, each ([Name] = EmployeeName)),    
    Result = Record.Field(EmployeeRow, [Team])
in
    Result

1 个答案:

答案 0 :(得分:0)

更正的功能是:

(EmployeeName as text) =>

let 
    Source = Excel.CurrentWorkbook(){[Name="Employees"]}[Content],
    EmployeeRow = Table.SelectRows(Source, each Text.Contains([Name],EmployeeName)),
    EmployeeRecord = Table.SingleRow(EmployeeRow),
    Result = Record.Field(EmployeeRecord, "Team")
in
    Result

问题是我需要在双引号中引用列,而不是在Record.Field()函数中使用方括号。