简体   繁体   English

Power BI 查询:需要 Select 表 1 中的列基于表 2 中的列名列表

[英]Power BI Query: Need to Select Columns in Table 1 based on list of column names in Table 2

I have merged data from two tables (Table#1 and Table #2) into single master data table (Table #3) using power query.我使用电源查询将两个表(表#1 和表#2)中的数据合并到单个主数据表(表#3)中。 Table #4 and Table #5 contain list of column names from Table #1 and Table #2, respectively, that I want to include in Table #3.表#4 和表#5 分别包含表#1 和表#2 中的列名列表,我想将它们包含在表#3 中。 I have inserted both these tables into power query as "connection only tables".我已将这两个表作为“仅连接表”插入到电源查询中。

Instead of doing this manually each time I want my power query to be updated dynamically each time Table #4 and/or Table #5 are updated.而不是每次我希望每次更新表#4和/或表#5时动态更新电源查询时手动执行此操作。

I am trying to do this Table #4 and Table #5 queries within the Table.SelectColumns function in the advanced query editor to do this.我正在尝试在高级查询编辑器中的 Table.SelectColumns function 中执行此表 #4 和表 #5 查询来执行此操作。 If so, please help and share the solution code.如果是这样,请帮助并分享解决方案代码。

Thanks in advance.提前致谢。

Not 100% sure I understand what you need but I have given it a try.不是 100% 确定我了解您的需求,但我已经尝试过了。

Let's say your Table_4 looks like this:假设您的Table_4如下所示:

Column_name
Row_Update
Row_ID

Click on Convert to List inside Power Query, Table_4 will now be a list [Row_update, Row_ID] .单击 Power Query 中的转换为列表Table_4现在将是一个列表[Row_update, Row_ID]

Table_1 looks like this: Table_1如下所示:

Name  Value  Row_Update  Row_ID
'a'   10     2019        1
..    ..     ..          ..

Inside the query for Table_1 you can now use this list inside the SelectColumns, something like this:Table_1的查询中,您现在可以在 SelectColumns 中使用此列表,如下所示:

let
    Source = Sql.Databases("localhost"),
    my_db = Source{[Name="my_db"]}[Data],
    Table_1 = my_db{[Schema="my_schema",Item="Table_1"]}[Data],
    // have manually modified the code Remove Other Columns created
    // replacing the selected columns with a reference to the list
    #"Remove Other Columns" = Table.SelectColumns(Table_1,#"Table_4")
in
    #"Remove Other Columns"

And now Table_1 will look like this:现在Table_1将如下所示:

Row_Update  Row_ID
2019        1
..          ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM