简体   繁体   English

向 Power Query Excel 中的现有列添加值

[英]Adding a value to an existing column in Power Query Excel

How do I add a value "UTU" to the current column "List of Depot" with this logic: If there is the value "UTU" in the List of Depot column show it in the List of Depot but if there is no "UTU" in the List of Depot then still show "UTU" with value zero.如何使用此逻辑将值“UTU”添加到当前列“仓库列表”:如果仓库列表列中有值“UTU”,则将其显示在仓库列表中,但如果没有“UTU” " 在 Depot 列表中,然后仍然显示值为零的 "UTU"。

I am using power query to connect to the data source and append query to append the multiple queries together, then I connect the pivot table in Excel to the Append query to build the report. I am using power query to connect to the data source and append query to append the multiple queries together, then I connect the pivot table in Excel to the Append query to build the report. How do I go about this, I have tried conditional column but without success.我该怎么做 go 关于这个,我试过条件列但没有成功。

Current Output:当前 Output:

在此处输入图像描述

Desired Output:所需的 Output:

在此处输入图像描述

You merely need to add a conditional clause at the end of your M code.您只需要在 M 代码的末尾添加一个条件子句。

This has to be done in the Advanced Editor, and you'll need to extend the added record that I show to cover all of your columns.这必须在高级编辑器中完成,并且您需要扩展我显示的添加记录以涵盖您的所有列。

M Code M代码

let
    Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{
        {"Depot", type text}, {"Report 1", Int64.Type}, {"Report 2", Int64.Type}}),

    //if number of columns is stable, this will work OK
    //if the number of columns might vary, or be named differently, we will have to make some changes    
    utuRow = if List.Contains(#"Changed Type"[Depot],"UTU")
                then #"Changed Type"
                else Table.InsertRows(#"Changed Type",
                                Table.RowCount(#"Changed Type"),
                                {[Depot="UTU",Report 1=0,Report 2=0]})
in
    utuRow

在此处输入图像描述

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

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