需要帮助将 Excel 公式转换为 Power Query,以检查上下一行的 2 列组合中的重复项

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

我有一个Excel公式,看起来像这样 =if(OR([@person]&[@month]]=A1&C1,[@person]&[@month]]=A3&C3), "重复",0)

[@person] 在 A 列,[@month] 在 C 列

Excel公式的工作原理是,它会查看当前行中的人物和月份的组合,并检查上一行或下一行的组合值是否相同。如果相同则返回“Duplicate”,否则返回0。

我不知道如何完成这项任务,将这个想法转化为强大的查询。我不知道如何编写一个列公式,它可以像 Excel 中那样简单地引用上方和下方一行的人员和月份公式。

提前致谢

我尝试应用索引列来帮助创建公式,但我不太确定如何应用它。然后我尝试使用 chatgpt 创建公式,但它不起作用。想尝试以正确的方式学习它。

duplicates powerquery
2个回答
1
投票

我假设您的两列名为 PersonMonth。最简单的方法是,

添加列...索引列

添加列...带有公式的自定义列

= try if [Person]&[Month] = #"Added Index"{[Index]-1}[Person]&#"Added Index"{[Index]-1}[Month] then "duplicate" else null otherwise null

添加列...带有公式的自定义列

= try if [Person]&[Month] = #"Added Index"{[Index]+1}[Person]&#"Added Index"{[Index]+1}[Month] then "duplicate" else null otherwise null

单击选择这两个新列,右键单击并合并它们


0
投票

您添加索引列的做法是正确的。 假设您的两列分别命名为人和月。

第 1 步:添加索引列。

第 2 步:添加自定义列并输入此自定义公式(将“Table1”替换为您的表名称)

let
    currentIndex = [Index],
    currentCombination = [person] & [month],
    prevCombination = if currentIndex > 0 then Table1{currentIndex - 1}[person] & Table1{currentIndex - 1}[month] else null,
    nextCombination = if currentIndex < Table.RowCount(Table1) - 1 then Table1{currentIndex + 1}[person] & Table1{currentIndex + 1}[month] else null
in
    if currentCombination = prevCombination or currentCombination = nextCombination then "Duplicate" else 0
© www.soinside.com 2019 - 2024. All rights reserved.