How to count values and summarize a values on all items

Describe the problem/error/question

I am trying to build a report which sum all the values on a specific field and create a counter of that.
kind of Group by and count in MySql.
for example

[
  {
    "recommendation": "CHALLENGE"
  },
  {
    "recommendation": "DENY"
  },
  {
    "recommendation": "DENY"
  }
]

the node will generate the following output

{
  "DENY": 2,
  "CHALLENGE": 1
}

what would be the easiest way to do it?

Information on your n8n setup

  • **n8n version:1.25.0
  • **Database (default: SQLite):Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • Operating system:

hello @mtubul

you can do that with the Summarize and Code nodes

1 Like

You can use summarize node like this without any additional code

That’s why the code node is needed :slight_smile:

The data outputs in the different format than requested

[
  {
    "recommendation": "CHALLENGE",
    "count_recommendation": 1
  },
  {
    "recommendation": "DENY",
    "count_recommendation": 2
  }
]
1 Like

Thank you very much, working like a charm

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.