# \[n8n\] summarize certain amounts

**URL:** <https://community.n8n.io/t/n8n-summarize-certain-amounts/44487>\
**Category:** Questions\
**Created:** [17 أبريل 2024، 12:57م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487 "2024-04-17T12:57:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [17 أبريل 2024، 12:57م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/1 "2024-04-17T12:57:46Z")

</div>

Hello,  
as a beginner, i need your help for the problem hereafter :

I would like to summarize those 2 amounts only (-630000 + 221000). Nothing else to do.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/0/d/0d1057094ae0bd760bcd22380859356b6005a046.png)

What is the error message (if any) ? No error message

Workflow :

```auto
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

```

Output returned by the last node :

Information on your n8n setup

- n8n version: 1.36.1
- Database : SQLite
- EXECUTIONS\_PROCESS setting : by default
- Running n8n via : Docker
- Operating system: windows 11

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/196425_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [17 أبريل 2024، 12:57م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/2 "2024-04-17T12:57:47Z")

</div>

It looks like your topic is missing some important information. Could you provide the following if applicable.

- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![Ludwig](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ludwig/32/58969_2.png) [@Ludwig](https://community.n8n.io/u/Ludwig)\
**Post date:** [18 أبريل 2024، 7:06ص UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/3 "2024-04-18T07:06:42Z")

</div>

Hey @sebcbon thanks for reaching out and being a part of the community! I’ve added triple backticks around your JSON so that everyone can better see your workflows.

---

<div class="post-metadata">

**Author:** ![Ludwig](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ludwig/32/58969_2.png) [@Ludwig](https://community.n8n.io/u/Ludwig)\
**Post date:** [18 أبريل 2024، 7:19ص UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/4 "2024-04-18T07:19:25Z")

</div>

Hi @sebcbon! Thanks for reaching out and being part of the community! There are many ways you could go about doing simple math in nodes.

We have the [Summarize node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.summarize/) but there are also a number of other ways to do simple mathematics in nodes.

[http://community.n8n.io/t/math-how-to-in-a-node/28706/2](http://community.n8n.io/t/math-how-to-in-a-node/28706/2)

> [@Simple math without js](http://community.n8n.io/t/simple-math-without-js/6598/2):
>
> Welcome to the community @Arjan_den_Ouden If you provide an example of the input and the desired output, I can help you with the function node.

For your specific case, have you tried using a single Edit Fields (Set) node instead of that branching if statement and doing the math there with a conditional set in the same expression? Then you can also remove the Merge node.

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [19 أبريل 2024، 2:05م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/5 "2024-04-19T14:05:48Z")

</div>

> [@Ludwig](#):
>
> For your specific case, have you tried using a single Edit Fields (Set) node instead of that branching if statement and doing the math there with a conditional set in the same expression? Then you can also remove the Merge node

Thank you very much for your response.  
Given that I am a beginner and unable to write a single line of code, I don’t know how to perform this sum in this specific case precisely. If you could assist me, that would be great. Best regards.

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [22 أبريل 2024، 12:09م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/6 "2024-04-22T12:09:23Z")

</div>

Hello Ludwig,

to provide further clarification regarding my previous messages, I am attempting to sum the two amounts in this column (to obtain their total), while retaining the other amounts that are also present in the same column (appended\_SubRed\_Amount). Is it clearer now ?

Thank you again for your assistance.

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [14 مايو 2024، 3:08م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/7 "2024-05-14T15:08:54Z")

</div>

I need your help ; If someone would help me to resolve my problem… By advance thank you.  
Best Regards

---

<div class="post-metadata">

**Author:** ![EmeraldHerald](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/emeraldherald/32/35355_2.png) [@EmeraldHerald](https://community.n8n.io/u/EmeraldHerald)\
**Post date:** [21 مايو 2024، 2:40م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/8 "2024-05-21T14:40:35Z")

</div>

Hi @sebcbon 👋 Happy to jump in here 🙂

If you could provide some sample data in JSON format, it’d be easier for me to help you out if this doesn’t get you on the right track (as I obviously wouldn’t have access to your file), but I think what Ludwig was trying to say here was that you can use the Set node to do something like:

That would give you the sum no matter the amount of items in your array 🙂

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [22 مايو 2024، 8:12ص UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/9 "2024-05-22T08:12:01Z")

</div>

Good morning EmeraldHerald,

First of all, a big thank you for your feedback and assistance.  
I am attaching the test file and my latest workflow on the next message

What I am trying to achieve is:

1] Transform the TypeOpe amounts into negatives if they are in ROD.  
2] Subtract (regardless of the amounts) the amounts with the same currency for each client (in this example: for client ‘CUST1,’ subtract -630000 $ (ROD) from 221000 $ (SOD) = -409000 $ (ROD). Please note that the actual amounts will vary each time.

I hope I have provided clear instructions, but feel free to ask if anything is unclear.

Best regards

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [22 مايو 2024، 8:12ص UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/10 "2024-05-22T08:12:36Z")

</div>



---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [22 مايو 2024، 8:13ص UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/11 "2024-05-22T08:13:41Z")

</div>

```auto
  {
    "Name": "cust2",
    "code Name": "YYYB12",
    "Code Part": "C",
    "TypeOpe": "ROD",
    "SubRed Amount": -135000,
    "CCY": "USD",
    "date NAV": "20240318",
    "$json": {
      "SubRed Amount": 135000
    }
  },
  {
    "Name": "cust1",
    "code Name": "XXXXH34",
    "Code Part": "HH",
    "TypeOpe": "ROD",
    "SubRed Amount": -630000,
    "CCY": "USD",
    "date NAV": "20240318",
    "$json": {
      "SubRed Amount": 630000
    }
  },
  {
    "Name": "cust1",
    "code Name": "XXXXH34",
    "Code Part": "HH",
    "TypeOpe": "SOD",
    "SubRed Amount": "221000",
    "CCY": "USD",
    "date NAV": "20240318",
    "$json": {
      "SubRed Amount": 221000
    }
  },
  {
    "Name": "cust1",
    "code Name": "XXXXH34",
    "Code Part": "D",
    "TypeOpe": "SOD",
    "SubRed Amount": "1310000",
    "CCY": "JPY",
    "date NAV": "20240317",
    "$json": {
      "SubRed Amount": 1310000
    }
  },
  {
    "Name": "cust2",
    "code Name": "YYYB12",
    "Code Part": "K",
    "TypeOpe": "SOD",
    "SubRed Amount": "1230000",
    "CCY": "JPY",
    "date NAV": "20240318",
    "$json": {
      "SubRed Amount": 1230000
    }
  }
]

```

---

<div class="post-metadata">

**Author:** ![EmeraldHerald](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/emeraldherald/32/35355_2.png) [@EmeraldHerald](https://community.n8n.io/u/EmeraldHerald)\
**Post date:** [22 مايو 2024، 4:03م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/12 "2024-05-22T16:03:48Z")

</div>

@sebcbon I might be misunderstanding, but are you looking for something like this code?

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [23 مايو 2024، 12:22م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/13 "2024-05-23T12:22:06Z")

</div>

Hello EmeraldHerald,

thank you so much, after tests it works well as I wanted it.  
I just have an additional question: how i could make the other columns appears (Code Part, TypeOpe, etc) ? Because in this example at the end, only the columns “name”, “CCY” and “amount” appears and I need to have them all.

Thank you again for your precious help.

Best regards

---

<div class="post-metadata">

**Author:** ![EmeraldHerald](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/emeraldherald/32/35355_2.png) [@EmeraldHerald](https://community.n8n.io/u/EmeraldHerald)\
**Post date:** [23 مايو 2024، 12:58م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/14 "2024-05-23T12:58:04Z")

</div>

ah, sorry about that @sebcbon🙂 Will this do?

---

<div class="post-metadata">

**Author:** ![sebcbon](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@sebcbon](https://community.n8n.io/u/sebcbon)\
**Post date:** [23 مايو 2024، 1:40م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/15 "2024-05-23T13:40:55Z")

</div>

Thank you EmeraldHerald,

you are a Genius for me, everything is Ok now !

Have a nice day

Best regards

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [30 مايو 2024، 1:41م UTC](https://community.n8n.io/t/n8n-summarize-certain-amounts/44487/16 "2024-05-30T13:41:29Z")

</div>

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