# How to sum 2 msg coming in asynchronously?

**URL:** <https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612>\
**Category:** General\
**Created:** [26 October 2022 11:25 UTC](https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612 "2022-10-26T11:25:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parowek](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@Parowek](https://discourse.nodered.org/u/Parowek)\
**Post date:** [26 October 2022 11:25 UTC](https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612/1 "2022-10-26T11:25:57Z")

</div>

Hello  
Im fairly new to Node Red so the solution may seem obvious, but i just got stuck and can't figure it ou  
I want to get a sum of 2 messages - first one comes from a date picker, the second one comes from a dropdown (it let's you choose an hour). I want to sum them to get the exact time of the reading i want to export from a CSV file. Of course the messages come asynchronously so how do i add them after they both change (or when a button is pressed? idk)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 October 2022 11:39 UTC](https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612/2 "2022-10-26T11:39:07Z")

</div>

### Option 1 - Join

Use a join node: See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

##### Flow 1...

`input1` --\> change-node (set topic "input1") ---+---\> `join` node (set to 3 parts) --\>  
`input2` --\> change-node (set topic "input2") ---↑  
`button` --\> change-node (set topic "button") ---↑

### Option 2 - Context store / retrieve later

Store the values in `flow` or `global` context & re-read them when the button is pressed

##### Flow 1...

`input1` --\> `change` node (save payload to `flow.input1`)

##### Flow 2...

`input2` --\> `change` node (save payload to `flow.input2`)

##### Flow 3...

`button` --\> change-node (set `msg.input1` to value of `flow.input1` & set `msg.input2` to value of `flow.input2`) - now both values are in one message

---

<div class="post-metadata">

**Author:** ![Parowek](https://avatars.discourse-cdn.com/v4/letter/p/6de8d8/32.png) [@Parowek](https://discourse.nodered.org/u/Parowek)\
**Post date:** [26 October 2022 11:59 UTC](https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612/4 "2022-10-26T11:59:52Z")

</div>

Okay, I'd like to do the option with the button, but the datepicker and dropdown menu sends a message only when changed. So when I won't change one of them (date or dropdwn because it's already going to be the time want) it will give me an error because the "next" function won't have a message input right? How do i solve that then?

---

<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:** [9 November 2022 12:00 UTC](https://discourse.nodered.org/t/how-to-sum-2-msg-coming-in-asynchronously/69612/5 "2022-11-09T12:00:25Z")

</div>

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