【问题标题】:I want to identify duplicates and keep the most recent one and delete the other in Google Sheets我想在 Google 表格中识别重复项并保留最新的并删除另一个
【发布时间】:2023-04-10 19:37:02
【问题描述】:

我想要识别我的数据中的重复项。获得这些数据后,我想按日期对重复项进行排序并保留最新的。

由于里面的敏感信息,我不能不提供我的工作表的副本。

【问题讨论】:

标签: sorting google-sheets duplicates google-sheets-formula google-sheets-query


【解决方案1】:

这样做:

=ARRAYFORMULA(IFERROR(VLOOKUP(UNIQUE(B:B), 
 QUERY({A:B}, "select Col2,Col1 
               order by toDate(Col1) desc
               format Col1 'dd/mm/yyyy' ", 0), {2, 1}, 0)))


=ARRAYFORMULA(QUERY(IFERROR(VLOOKUP(UNIQUE(QUERY({Data!A:H}, 
 "select Col3
  where toDate(Col5) >= date '"&TEXT(A1, "yyyy-mm-dd")&"' 
    and toDate(Col5) <= date '"&TEXT(B1, "yyyy-mm-dd")&"'
  order by toDate(Col1) desc ", 0)), 
 QUERY({Data!A:H}, 
 "select Col3,Col1,Col2,Col4,Col5,Col6,Col7 
  where toDate(Col5) >= date '"&TEXT(A1, "yyyy-mm-dd")&"' 
    and toDate(Col5) <= date '"&TEXT(B1, "yyyy-mm-dd")&"'
  order by toDate(Col1) desc
  format Col5 'mm/dd/yyyy' ", 0), {2,3,1,4,5,6,7}, 0)),
 "format Col1 'yyyy-nn-dd hh:mm:ss', Col5 'mm/dd/yyyy'"))


=ARRAYFORMULA(QUERY(IFERROR(VLOOKUP(UNIQUE(QUERY({Data!A:H}, 
 "select Col2
  where toDate(Col5) >= date '"&TEXT(A1, "yyyy-mm-dd")&"' 
    and toDate(Col5) <= date '"&TEXT(B1, "yyyy-mm-dd")&"'
  order by toDate(Col1) desc ", 0)), 
 QUERY({Data!A:H}, 
 "select Col2,Col1,Col3,Col4,Col5,Col6,Col7 
  where toDate(Col5) >= date '"&TEXT(A1, "yyyy-mm-dd")&"' 
    and toDate(Col5) <= date '"&TEXT(B1, "yyyy-mm-dd")&"'
  order by toDate(Col1) desc
  format Col5 'mm/dd/yyyy' ", 0), {2,1,3,4,5,6,7}, 0)),
 "format Col1 'yyyy-mm-dd hh:mm:ss', Col5 'mm/dd/yyyy'"))

【讨论】:

  • 数据正在从数据表中提取并导入到 Sheet2 并按第 1 行中列出的日期过滤掉。正在导入的数据,我删除了重复项,但保留了最新日期。查看电子表格:docs.google.com/spreadsheets/d/…
  • QUERY(All!A:Z, "选择 A, B, C, D, E, F, G, H where toDate(E) >= date '"&TEXT(A1, "yyyy- mm-dd")&"' and toDate(E)
  • “(FILTER(A:Z,TRUE)”的目的是什么?
  • 过滤器的目的是只显示不重复的项目。此公式仅显示重复项。
猜你喜欢
  • 1970-01-01
  • 2013-07-10
  • 1970-01-01
  • 2019-11-19
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多