将列表传递给Table.RemoveColumns。

huangapple go评论68阅读模式
英文:

Pass list to Table.RemoveColumns

问题

我正在寻找一种方法将列表传递给 Power Query 中的 Table.RemoveColumns() 步骤。

设置概述,两个表作为数据源,一个是配置表,包含第二个数据源的所有列名,并使用简单的 'yes' 和 'no' 选择器来标识应保留/删除哪些列。该表用作数据源,通过 'no' 进行过滤,并展开为一个列表,如下所示:

我正在寻找一种方法将该列表传递给我的 'data' 源中的一个步骤来删除列:

因此,删除列的步骤:

= Table.RemoveColumns(Source,{"InvoiceDate", "T/S Start Date", "TotalBreakMinutes"})

将变为:

= Table.RemoveColumns(Source,{cols})

然而,你不能将一个列表传递给一个期望文本的参数。我尝试了一些解决方法,比如给每个列表项添加前缀 " 和后缀 ",然后使用 Text.Combine 和逗号分隔符,但是 Table.RemoveColumns 步骤将字符串视为单个列。

是否有一种方法可以将该列表传递为 Table.RemoveColumns() 的可识别条件?

英文:

I am looking for a way to pass a list to the Table.RemoveColumns() step in Power Query.

Overview of the set up, two tables as data sources, one is a config table with all the column names of the second data source with simple 'yes' 'no' selectors identifying which columns should be kept/removed. This table is used as a data source, filtered by 'no', and drilled down as a list like so:
将列表传递给Table.RemoveColumns。

I am looking for a way to pass that list to a step to remove columns in my 'data' source:

So the step to remove columns:

= Table.RemoveColumns(Source,{"InvoiceDate", "T/S Start Date", "TotalBreakMinutes"})

Would become:

= Table.RemoveColumns(Source,{cols})

However you can't pass a list to an argument that expects text. I tried a few work arounds like adding a prefix " and suffix " to each list item and using Text.Combine with a comma separator however Table.RemoveColumns step handles the string as a single column

将列表传递给Table.RemoveColumns。

Is there a way to pass that list as a recognisable condition for Table.RemoveColumns()?

答案1

得分: 3

= Table.RemoveColumns(Source, cols) 其中 cols 是一个列名列表

示例代码

let Source = #table({"Column1", "Column2","Column3","Column4"},{{"A","B","C","D"}}),
removetable = #table({"Column1"},{{"Column1"},{"Column2"}}),
removelist = removetable[Column1],
#"移除的列" = Table.RemoveColumns(Source,removelist)
in #"移除的列"

英文:

= Table.RemoveColumns(Source,cols) where cols is a list of column names

sample code

let Source = #table({"Column1", "Column2","Column3","Column4"},{{"A","B","C","D"}}),
removetable = #table({"Column1"},{{"Column1"},{"Column2"}}),
removelist = removetable[Column1],
#"Removed Columns" = Table.RemoveColumns(Source,removelist)
in #"Removed Columns"

huangapple
  • 本文由 发表于 2023年6月1日 23:29:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定