如何将单元格的值偏移到另一列?

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

我的目标是在一定条件下将单元格的值拖动到另一列中的相应行。

我有下表:

第1栏 第2栏
35
27欧元
13

如果 Column1 中的单元格包含“€”,则应清空该单元格并将值带到 Column2。

输出应该是:

第1栏 第2栏
35
27欧元
13

条件非常简单,但我不熟悉查询编辑器的逻辑以及如何表达输出。

(我知道这可以在 Excel 或 VBA 上轻松完成,但我想知道如何直接使用 Query 执行这些类型的任务)。

excel powerquery data-analysis data-cleaning m
4个回答
0
投票

最简单的方法是创建两个新列,然后删除原来的两个列。例如

添加列-自定义列:


0
投票

您的电量查询代码应如下所示

let
    Source = [YourSourceHere], // Replace this with your actual source step
    AddedCustom2 = Table.AddColumn(Source, "New Column2", each if Text.Contains([Column1], "€") then null else [Column1]),
    AddedCustom1 = Table.AddColumn(AddedCustom2, "New Column1", each if Text.Contains([Column1], "€") then [Column1] else null),
    RemovedOriginals = Table.RemoveColumns(AddedCustom1, {"Column1", "Column2"}),
    RenamedColumns = Table.RenameColumns(RemovedOriginals, {{"New Column1", "Column1"}, {"New Column2", "Column2"}})
in
    RenamedColumns

0
投票

这是另一种不添加列的方法,使用

Table.TransformRows
函数:

let

//Change next line to reflect actual data source
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type any}}),
    
    #"Move €" = Table.FromRecords(
                    Table.TransformRows(#"Changed Type", (r)=>
                        Record.TransformFields(r,  {
                            {"Column1", each if Text.EndsWith(_,"€") then null else _},
                            {"Column2", each if Text.EndsWith(r[Column1],"€") then r[Column1] else _}
                                                    }
                            )
                        )
                    )
in
    #"Move €"


0
投票

假设源单元格是文本,则预先附加一个 |然后拆分该角色

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddSplit = Table.TransformColumns(Source,{{"Column1", each if Text.Contains(_,"€") then "|"&_ else _, type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(AddSplit, "Column1", Splitter.SplitTextByEachDelimiter({"|"}, QuoteStyle.Csv, false), {"Column1.1", "Column1.2"})
in  #"Split Column by Delimiter"

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.