简体   繁体   English

将 Power Query 应用于所有列

[英]Apply Power Query to all columns

I have a Power query that finds and replaces values listed in a table that I work through from here Bulk Find And Replace In Power Query我有一个 Power 查询,它查找和替换我从这里处理的表中列出的值Bulk Find And Replace In Power Query

But I need to apply it to All columns.但我需要将其应用于所有列。

How to do this without listing all the columns as they are dynamic and keep changing如何在不列出所有列的情况下执行此操作,因为它们是动态的并且不断变化

Thanks谢谢

What I have so far到目前为止我所拥有的

let
    Source = Excel.CurrentWorkbook(){[Name="MyData"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Job Title", type text}}),
    BulkReplaceStep = fBulkReplace(#"Changed Type", MyFindReplace, {"Job Title","Job Title2"})
in
    BulkReplaceStep

The find/replace data table查找/替换数据表

let
    Source = Excel.CurrentWorkbook(){[Name="MyFindReplace"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Find", type text}, {"Replace", type text}})
in
    #"Changed Type

Bulkreplace批量替换

let BulkReplace = (DataTable as table, FindReplaceTable as table, DataTableColumn as list) =>
    let
        //Convert the FindReplaceTable to a list using the Table.ToRows function
        //so we can reference the list with an index number
        FindReplaceList = Table.ToRows(FindReplaceTable),
        //Count number of rows in the FindReplaceTable to determine
        //how many iterations are needed
        Counter = Table.RowCount(FindReplaceTable),
        //Define a function to iterate over our list 
        //with the Table.ReplaceValue function
        BulkReplaceValues = (DataTableTemp, n) => 
        let 
            //Replace values using nth item in FindReplaceList
            ReplaceTable = Table.ReplaceValue(
                DataTableTemp,
                //replace null with empty string
                if FindReplaceList{n}{0} = null then "" else FindReplaceList{n}{0},
                if FindReplaceList{n}{1} = null then "" else FindReplaceList{n}{1},
                Replacer.ReplaceText,
                DataTableColumn
                )
        in
            //if we are not at the end of the FindReplaceList
            //then iterate through Table.ReplaceValue again
            if n = Counter - 1 
                then ReplaceTable
                else @BulkReplaceValues(ReplaceTable, n + 1),
        //Evaluate the sub-function at the first row
        Output = BulkReplaceValues(DataTable, 0)   
    in
        Output
in
    BulkReplace

在此处输入图像描述

This works这有效

Change this:改变这个:

BulkReplaceStep = fBulkReplace(#"Changed Type", MyFindReplace, {"Job Title","Job Title2"})

To This:对此:

BulkReplaceStep = fBulkReplace(#"Changed Type", MyFindReplace, Table.ColumnNames(#"Changed Type"))

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

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