I have a spreadsheet that pulls in data from a 3rd party source. The new data is added and appended to the same sheet everyday. I have set up a trigger onChange with the script below:
function removeDuplicates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A:Z");
range.removeDuplicates([1,2]);
}
E.g. column A is date, column B is Name.
For example, my sheet looks like this when new data is added.
Name | Date | Value |
---|---|---|
John | 3-Feb-21 | 100 |
Tom | 3-Feb-21 | 200 |
Sam | 3-Feb-21 | 300 |
John | 4-Feb-21 | 100 |
Tom | 4-Feb-21 | 200 |
Sam | 4-Feb-21 | 300 |
Tom | 4-Feb-21 | 201 |
Sam | 4-Feb-21 | 301 |
The last two rows are the new entries, which will deleted if I run my current script. Is there a way to make sure that it only removes the older entries? e.g.
Name | Date | Value |
---|---|---|
Tom | 4-Feb-21 | 200 |
Sam | 4-Feb-21 | 300 |
The desired result should be:
Name | Date | Value |
---|---|---|
John | 3-Feb-21 | 100 |
Tom | 3-Feb-21 | 200 |
Sam | 3-Feb-21 | 300 |
John | 4-Feb-21 | 100 |
Tom | 4-Feb-21 | 201 |
Sam | 4-Feb-21 | 301 |