in this post google app script i have a question how to count a duplicate values
I want to enter a numeral in G2:G3 (source sheet) and want to show a unique count values in B2:B4 (destination sheet) what i have to do https://docs.google.com/spreadsheets/d/1HN0XCLrEzlRkInIv6xFnhCFnhZabu7Y-Tz1dvYvsGQM/edit?usp=sharing
In your situation, how about the following sample script?
function myFunction() {
const srcSheetName = "source"; // Please set the source sheet name.
const dstSheetName = "des"; // Please set the destination sheet name.
// Retrieve source and destination sheets.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const [srcSheet, dstSheet] = [srcSheetName, dstSheetName].map(s => ss.getSheetByName(s));
// Retrieve source values and create an object for putting to the destination sheet.
const srcValues1 = srcSheet.getRange("A1:C" + srcSheet.getLastRow()).getValues();
const obj1 = srcValues1[0].map((_, c) => srcValues1.map(r => r[c])).reduce((o, [h, ...v]) => (o[h] = v, o), {});
const srcValues2 = srcSheet.getRange("F2:G" + srcSheet.getLastRow()).getValues();
srcValues2.forEach(([f, g]) => {
if (g > 1) {
for (let i = 0; i < g - 1; i++) {
obj1[f] = [...obj1[f], ...obj1[f]];
}
}
});
const obj2 = Object.values(obj1).flat().reduce((o, a) => (o[a] = o[a] ? o[a] + 1 : 1, o), {});
// Retrieve the values of column "A" from the destination sheet and create an array for putting to Spreadsheet.
const dstRange = dstSheet.getRange("A2:A" + dstSheet.getLastRow());
const dstValues = dstRange.getDisplayValues().map(([a]) => [obj2[a] || 0]);
// Put the result values to the column "B" of the destination sheet.
dstRange.offset(0, 1).setValues(dstValues);
}
source and des. Please modify this for your actual situation.1, 2, 3) is calculated. And, the result values are put in column "B" of the destination sheet.