我得到了一個只有重復值和相關日期的串列。我想得到一個結果列,重復項中只有一個值,但有關聯的日期。這是我想要的最早日期。
請看下面的例子(歐洲日期)??:

我想我想太多了,因為我嘗試了我知道的大多數公式,但我無法弄清楚。
uj5u.com熱心網友回復:
嘗試
=query(A:B,"select A,min(B) where A is not null group by A",1)
要么
=query(A:B;"select A,min(B) where A is not null group by A";1)

uj5u.com熱心網友回復:
最早日期
function earliestDateForEachValue() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet0');
const rg = sh.getRange(2,1,sh.getLastRow() - 1,sh.getLastColumn());
const vs = rg.getValues();
let obj = {pA:[]};
vs.forEach((r,i) => {
if(!obj.hasOwnProperty(r[0])) {
obj[r[0]] = [];
obj[r[0]].push(new Date(r[1]).valueOf());
obj.pA.push(r[0]);
} else {
obj[r[0]].push(new Date(r[1]).valueOf())
}
});
let o = [];
obj.pA.forEach(p => {
obj[p].sort((a,b) => {
return a - b;
});
o.push([p,Utilities.formatDate(new Date(obj[p][0]),Session.getScriptTimeZone(),"dd.MM.yyyy")])
});
Logger.log(JSON.stringify(o));
}
Execution log
11:44:47 AM Notice Execution started
11:44:47 AM Info [["Value1","01.01.2022"],["Value2","02.01.2022"],["Value3","03.01.2022"]]
11:44:48 AM Notice Execution completed
資料:
| 價值觀 | 日期 |
|---|---|
| 價值1 | 01.01.2022 |
| 價值2 | 02.01.2022 |
| 價值3 | 03.01.2022 |
| 價值1 | 04.01.2022 |
| 價值2 | 05.01.2022 |
| 價值3 | 06.01.2022 |
| 價值1 | 07.01.2022 |
| 價值2 | 08.01.2022 |
| 價值3 | 09.01.2022 |
| 價值1 | 2022 年 1 月 10 日 |
| 價值2 | 2022 年 1 月 11 日 |
| 價值3 | 2022 年 1 月 12 日 |
| 價值1 | 2022 年 1 月 13 日 |
| 價值2 | 2022 年 1 月 14 日 |
| 價值3 | 2022 年 1 月 15 日 |
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/450583.html
