[n8n] summarize certain amounts

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.

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

Workflow :

(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

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:

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.

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 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

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.

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.

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

Hi @sebcbon :wave: Happy to jump in here :slight_smile:

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 :slight_smile:

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

  {
    "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
    }
  }
]

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

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

ah, sorry about that @sebcbon :slight_smile: Will this do?

Thank you EmeraldHerald,

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

Have a nice day

Best regards