Hey all, based on the example data from the original post my suggestion would look like so:
The example code I am using first extracts all unique values in the Audience
and Status
fields.
It then creates a response object for each audience and then adds a field for each status. The value of this field will be a count of how many occurrences there are matching both audience and status:
const unique_audiences = [...new Set(items.map(item => item.json.Audience))];
const unique_statuses = [...new Set(items.map(item => item.json.Status))];
let results = [];
unique_audiences.forEach(audience => {
let result = {
json: {
audience: audience
}
};
unique_statuses.forEach(status => {
result.json[status] = items.filter(item => item.json.Audience == audience && item.json.Status == status).length;
})
results.push(result);
});
return results;
This leaves you with a result like this:
Is this what you had in mind @fischera?