我有一个Excel公式,看起来像这样 =if(OR([@person]&[@month]]=A1&C1,[@person]&[@month]]=A3&C3), "重复",0)
[@person] 在 A 列,[@month] 在 C 列
Excel公式的工作原理是,它会查看当前行中的人物和月份的组合,并检查上一行或下一行的组合值是否相同。如果相同则返回“Duplicate”,否则返回0。
我不知道如何完成这项任务,将这个想法转化为强大的查询。我不知道如何编写一个列公式,它可以像 Excel 中那样简单地引用上方和下方一行的人员和月份公式。
提前致谢
我尝试应用索引列来帮助创建公式,但我不太确定如何应用它。然后我尝试使用 chatgpt 创建公式,但它不起作用。想尝试以正确的方式学习它。
我假设您的两列名为 Person 和 Month。最简单的方法是,
添加列...索引列
添加列...带有公式的自定义列
= 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
单击选择这两个新列,右键单击并合并它们
您添加索引列的做法是正确的。 假设您的两列分别命名为人和月。
第 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