Power Query:将列名作为函数参数传递 [英] Power Query: pass column name as function parameter

查看:199
本文介绍了Power Query:将列名作为函数参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将列名传递给幂查询函数 - 如果我在函数调用中将它们作为 [columnname] 传递,它会尝试在函数外实现它们;如果我在函数本身中使用 [parameter] 传递,它会查找列参数"而不是调用中传递的列名.

I'm struggling to pass column names to a power query function - if I pass them as [columnname] within the function call, it tries to implement them outside the function; if I pass using [parameter] within the function itself, it looks for a column "parameter" and not the column name that's passed in the call.

在其他地方,StackExchange 建议使用 Table.Column(table,columnname) 来解决这个问题,但我一次性获得了整个列,而不是能够比较列中的相应条目.

Elsewhere, StackExchange recommends using Table.Column(table,columnname) to get around this, but the I get the whole column in one go, rather than being able to compare corresponding entries within the column.

有人可以帮忙吗?这是代码

Can anyone help? Here's the code

(table,Mt0,Mt1) => let 
    #"Add Yt.1" = Table.AddColumn(table, "placeholder", 
        each if Table.Column(table,Mt0) <= 0 or - Table.Column(table,Mt1) < Table.Column(table,Mt0)
            then Table.FromRecords({[Mt0 = Table.Column(table,Mt0), Mt1 = Table.Column(table,Mt1)]})
        else Table.FromRecords({[Mt0 = 0,Mt1 = Table.Column(table,Mt1) + Table.Column(table,Mt0)]}))/*,
    #"Expand Yt.1" = Table.ExpandTableColumn(Table.RemoveColumns(#"Add Yt.1",{"Mt0", "Mt1"}), "placeholder", {"Mt0","Mt1"})*/
in #"Add Yt.1"

这被存储为 Query1,我正在使用 Query1(tablename,Y1M,Y2M) 调用

This is stored as Query1 and I'm calling using Query1(tablename,Y1M,Y2M)

此版本产生错误:我们不能将运算符<="应用于 List 和 Number 类型(因此,虽然它可能按预期引用 Y1M 列,但它会将整个列(作为列表)与第一个不等式中的0"进行比较,而不是一次一个条目.

This version generates an error: We cannot apply operator "<=" to types List and Number (so while it may be referencing column Y1M as intended, it's comparing the whole column (as a list) to '0' in the first inequality, rather than one entry at a time.

帮助!!

推荐答案

尝试使用 Record.Field(_, Mt0) 而不是 Table.Column

这篇关于Power Query:将列名作为函数参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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