# I would like to multiply two numeric payloads and use the result on a dashboard

**URL:** <https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172>\
**Category:** Dashboard\
**Created:** [6 March 2023 11:56 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172 "2023-03-06T11:56:51Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 11:56 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/1 "2023-03-06T11:56:51Z")

</div>

I have two payloads, both are in numeric format.  
I would like to multiply the two numbers and use the product on a dashboard as text and in a gauge.

This is the flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/baaec53fa1326496d23750964041dd6a99032b6c.png)

My attempt:-

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/968b54d005053ef40bfc9006e08dd890c7db83c9.png)

Any pointers will be appreciated very much

Kind Regards

Frits

---

<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:** [6 March 2023 12:22 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/2 "2023-03-06T12:22:49Z")

</div>

A key point all node-red users must understand is that messages travel down each wire separately. In otherwords, the 2 wires feeding into function "West DC Watts" will NEVER arrive at the same time.

With that in mind, there are a couple of ways to solve this, but ultimately, you need both values in the same msg.

I will show you 1 (join node) others may provide an alternative method (context)

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

Once you can see obth values in a single msg, you can access them in a function like this...

```auto
msg.payload = msg.payload.property1 * msg.payload.property2
return msg;

```

where property1 and property1 match the topics you gave them in the above cookbook example.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 13:59 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/3 "2023-03-06T13:59:02Z")

</div>

Show us what is coming out of the MQTT node please.

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:11 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/4 "2023-03-06T14:11:55Z")

</div>

> [@Steve-Mcl](#):
>
> single msg, you can access them in a function like this

## `3/6/2023, 4:10:01 PMnode: SBF-Spot sbfspot/2130438358 : msg.payload : Object object Timestamp: "06/03/2023 16:10:02" SunRise: "06/03/2023 06:06:00" SunSet: "06/03/2023 18:31:00" InvSerial: 2130438358 InvName: "SB 4000TL-21 358 Regs" InvTime: "06/03/2023 16:10:00" InvStatus: "Ok" InvTemperature: 38.53 InvGridRelay: "Closed" EToday: 14.204 ETotal: 33229.644 PACTot: 196 UDC1: 223.59 UDC2: 251.94 IDC1: 0.504 IDC2: 0.416 PDC1: 112 PDC2: 104`

3/6/2023, 4:10:01 PM[node: SBF-Spot](http://192.168.1.110:1880/#)sbfspot/2130438358 : msg.payload : Object

object  
Timestamp: "06/03/2023 16:10:02"  
SunRise: "06/03/2023 06:06:00"  
SunSet: "06/03/2023 18:31:00"  
InvSerial: 2130438358  
InvName: "SB 4000TL-21 358 Regs"  
InvTime: "06/03/2023 16:10:00"  
InvStatus: "Ok"  
InvTemperature: 38.53  
InvGridRelay: "Closed"  
EToday: 14.204  
ETotal: 33229.644  
PACTot: 196  
UDC1: 223.59  
UDC2: 251.94  
IDC1: 0.504  
IDC2: 0.416  
PDC1: 112  
PDC2: 104

---

<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:** [6 March 2023 14:22 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/5 "2023-03-06T14:22:48Z")

</div>

It looks like both values are already in the same payload so you should be able to just use them as I explained above...

```auto
msg.payload = msg.payload.UDC2* msg.payload.IDC2
return msg;

```

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:28 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/6 "2023-03-06T14:28:36Z")

</div>

You are correct. They are in the same payload:

Let me try the formula then:

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:32 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/7 "2023-03-06T14:32:29Z")

</div>

Thanks @Steve-Mcl ,  
I got it to work now.

What do I add to that formula to only show two digits after the dot

```auto
msg.payload = msg.payload.UDC2* msg.payload.IDC2
return msg;

```

```auto
3/6/2023, 4:30:02 PM[node: West DC Watts](http://192.168.1.110:1880/#)sbfspot/2130438358 : msg.payload : number

100.07844

3/6/2023, 4:30:02 PM[node: East DC Watts](http://192.168.1.110:1880/#)sbfspot/2130438358 : msg.payload : number

85.60538999999999

```

---

<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:** [6 March 2023 14:36 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/8 "2023-03-06T14:36:57Z")

</div>

> [@fritserasmus](#):
>
> What do I add to that formula to only show two digits after the dot

it depends what you are doing with it.

Typically, you leave the number as is (for accuracy) but then trim it down when displaying it on a dashboard or spreadsheet.

On a dashboard item (like ui-label) you would use [angular decimal pipe](https://angular.io/api/common/DecimalPipe) `{{msg.payload|number:2}}` to limit the display on a dashboard item.

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:39 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/9 "2023-03-06T14:39:48Z")

</div>

like this?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/760e69412e5027c2a66eb406bef650030a2c1fc7.png)

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:41 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/10 "2023-03-06T14:41:40Z")

</div>

Oh Oh:-  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/2692851169cbe2ecdeef8862d11c3215c902e3d6.png)

not correct

---

<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:** [6 March 2023 14:43 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/11 "2023-03-06T14:43:40Z")

</div>

No, like this on a dashboard UI Text (or other dashboard item)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/62b9e52e47e0b05e1a43900b3e0d472da4bcfe4e.png)

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 14:44 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/12 "2023-03-06T14:44:54Z")

</div>

Thanks Steve. Now I understand the part:

> Typically, you leave the number as is (for accuracy) but then trim it down when displaying it on a dashboard or spreadsheet.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2023 14:57 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/13 "2023-03-06T14:57:22Z")

</div>

For the future, one of the golden rules is not to send a message down two different paths at the same time unless you need to, and particularly don't send it down different paths and then try to join them back together.

Several of the dashboard nodes allow you to specify where in the message the data resides, so in a gauge, for example, you can specify, in the Value Format field something like `{{msg.payload.InvTemperature|number: 2}}`, which can avoid the need for moving data into msg.payload.

---

<div class="post-metadata">

**Author:** ![fritserasmus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fritserasmus/32/274_2.png) [@fritserasmus](https://discourse.nodered.org/u/fritserasmus)\
**Post date:** [6 March 2023 15:03 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/14 "2023-03-06T15:03:15Z")

</div>

Thanks Colin.  
It makes sense.

Thanks for the kind help gents. I really appreciate it

---

<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:** [5 April 2023 15:03 UTC](https://discourse.nodered.org/t/i-would-like-to-multiply-two-numeric-payloads-and-use-the-result-on-a-dashboard/76172/15 "2023-04-05T15:03:34Z")

</div>

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