# Add values from MQTT

**URL:** https://discourse.nodered.org/t/add-values-from-mqtt/12974
**Category:** General
**Created:** [6 July 2019 08:42 UTC](https://discourse.nodered.org/t/add-values-from-mqtt/12974 "2019-07-06T08:42:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![crd](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@crd](https://discourse.nodered.org/u/crd)
#### Post date: [6 July 2019 08:42 UTC](https://discourse.nodered.org/t/add-values-from-mqtt/12974/1 "2019-07-06T08:42:54Z")

</div>

Hi,  
I want to do some calculations with the values i receive from MQTT.  
The "convert functions" converts the string, coming from the MQTT, to a number.

msg.payload = Number(msg.payload);  
return msg;

![mqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/225880be8ca5b9499b437d08ba97086aface76c6.png)

What i want to do is : subtract the number that is coming from MQTT "rem/rechts" with the number that is comming from MQTT "rem/links" this result must be devided by MQTT "rem/links" and multiplied by 100 =\> the result is the difference between MQTT "rem/rechts" and "rem/links" in %.

thanks for your help 😉

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [6 July 2019 08:52 UTC](https://discourse.nodered.org/t/add-values-from-mqtt/12974/2 "2019-07-06T08:52:02Z")

</div>

To do that calculation you need both values in a single message that you then pass to your Function node. This recipe in the cookbook shows how you can do that: [https://cookbook.nodered.org/basic/join-streams](https://cookbook.nodered.org/basic/join-streams)

---

<div class="post-metadata">

### Author: ![crd](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@crd](https://discourse.nodered.org/u/crd)
#### Post date: [23 July 2019 10:08 UTC](https://discourse.nodered.org/t/add-values-from-mqtt/12974/3 "2019-07-23T10:08:48Z")

</div>

Thx knolleary for your answer, ...  
I tried your suggestion to merge (join) both values, but i could't manage to get any message out of the function.  
I did found a solution =\> I used variables instead to store the values.

Thanks and greets 😉
