# Add two payloads, enforcing both values arriving before summing them - help needed

**URL:** <https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006>\
**Category:** General\
**Created:** [22 July 2023 09:33 UTC](https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006 "2023-07-22T09:33:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [22 July 2023 09:33 UTC](https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006/1 "2023-07-22T09:33:41Z")

</div>

I am injecting two separate values into a SUM node, but it sums each time a value arrives.

Can I somehow enforce that the values are summed only after BOTH values have arrived ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [22 July 2023 09:58 UTC](https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006/2 "2023-07-22T09:58:02Z")

</div>

I don't use the sum node, as this is simple using standard nodes.

You could just join the messages with a count of 2 and sum the output.  
e.g.

```auto
[{"id":"0cc20c51c1ace4cc","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":250,"y":3240,"wires":[["6b9889410da54e8a"]]},{"id":"6b9889410da54e8a","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":410,"y":3280,"wires":[["fdf5a6f8604ae63a"]]},{"id":"dd315fd99c28b588","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":250,"y":3300,"wires":[["6b9889410da54e8a"]]},{"id":"fdf5a6f8604ae63a","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3280,"wires":[["66f3a8506ea55dae"]]},{"id":"66f3a8506ea55dae","type":"debug","z":"b9860b4b9de8c8da","name":"debug 323","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3360,"wires":[]},{"id":"6cae1f885c77843c","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"1","payloadType":"num","x":270,"y":3400,"wires":[["1e9887e8adb81ad0"]]},{"id":"2939305b63cc607e","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"2","payloadType":"num","x":270,"y":3460,"wires":[["1e9887e8adb81ad0"]]},{"id":"1e9887e8adb81ad0","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":3440,"wires":[["eb9ef62a851a3979"]]},{"id":"eb9ef62a851a3979","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload.*)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":3440,"wires":[["58eccebb1445e16e"]]},{"id":"58eccebb1445e16e","type":"debug","z":"b9860b4b9de8c8da","name":"debug 324","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":3520,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)\
**Post date:** [22 July 2023 21:07 UTC](https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006/3 "2023-07-22T21:07:56Z")

</div>

Absolutely perfect and a great learning example

Thank you for that, hugely appreciated

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 September 2023 21:08 UTC](https://discourse.nodered.org/t/add-two-payloads-enforcing-both-values-arriving-before-summing-them-help-needed/80006/4 "2023-09-20T21:08:01Z")

</div>

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