如何通过引用列位置而不是列名来在Power Query编辑器中重新排序列

问题描述 投票:0回答:1

我有一个SQL查询作为数据源,它将一个表插入Power Query。该表中的列具有过去12个月的月标题。因此,每个月刷新数据时,列名都会更改一个月。总的列数仍然相同。

我对Power Query语言还很陌生,所以我不确定如何通过引用列的位置而不是当前的名称来重新排序列

这是我的“重新排序的列”代码当前的外观:

#"Reordered Columns" = Table.ReorderColumns(Source,{"Cat", "Type", "Function", "Organisation", "Locality", "SubOrganisation", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12", "2019-01", "2019-02", "2019-03", "2019-04", "2019-05", "2019-06", "2019-07"})

我不希望在重新排序时指定列名,因为每个月,最后一个月将减少,而新月将被添加。

sql-server powerbi powerquery powerbi-desktop
1个回答
0
投票
Table.ReorderColumns
    (Source,
        {"Cat", "Type", "Function", "Organisation", "Locality", "SubOrganisation"} //List of static columns in order we want
        & //Lists can be appended with this
        List.RemoveItems( //Function that removes a list of items from another list
            {"Cat", "Type", "Function", "Organisation", "Locality", "SubOrganisation"}, //List of static columns (to be removed)
            Table.ColumnNames(Source) //List of all column names
            )
    )

这里正在发生的事情是,首先,我们获取您一直拥有的列的列表,并按照所需的顺序对其进行设置。然后,我们获取列名称的列表[

© www.soinside.com 2019 - 2024. All rights reserved.