# Creating percentages from responses

**URL:** <https://discourse.nodered.org/t/creating-percentages-from-responses/12097>\
**Category:** General\
**Created:** [12 June 2019 07:52 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097 "2019-06-12T07:52:56Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![graphicsop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/graphicsop/32/8663_2.png) [@graphicsop](https://discourse.nodered.org/u/graphicsop)\
**Post date:** [12 June 2019 14:42 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/22 "2019-06-12T14:42:37Z")

</div>

I've also noticed that this function gives a percentage out of 100 per message...  
Is there a way of collecting up multiple messages and outputting results as an overall percentage?

---

<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:** [12 June 2019 16:08 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/23 "2019-06-12T16:08:37Z")

</div>

> [@graphicsop](#):
>
> Can I separate each result value and pipe into a separate OSC node?

Yes, you can send them individually out of separate outputs on the function node. If you look at the docs for writing functions it tells you how to do that.

---

<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:** [12 June 2019 16:10 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/24 "2019-06-12T16:10:28Z")

</div>

> [@graphicsop](#):
>
> Is there a way of collecting up multiple messages and outputting results as an overall percentage?

I don't know what you mean by that. I think I have previously asked that you give and example showing what you want to see so that we can understand the maths you want to do.  
However first make sure that you understand how the function that you have works. Then you should be able to make an attempt at changing the maths to make it do what you want.

---

<div class="post-metadata">

**Author:** ![graphicsop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/graphicsop/32/8663_2.png) [@graphicsop](https://discourse.nodered.org/u/graphicsop)\
**Post date:** [12 June 2019 17:06 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/25 "2019-06-12T17:06:59Z")

</div>

Great, thanks!

---

<div class="post-metadata">

**Author:** ![graphicsop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/graphicsop/32/8663_2.png) [@graphicsop](https://discourse.nodered.org/u/graphicsop)\
**Post date:** [12 June 2019 17:09 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/26 "2019-06-12T17:09:56Z")

</div>

Sorry, I mean that about 50 people will each be able to select one of the four options so I’d like to be able to accumulate all of their responses and create overall percentages.

Does that make sense?

---

<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:** [12 June 2019 18:16 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/27 "2019-06-12T18:16:34Z")

</div>

As I keep saying provide a concrete example with numbers and show what you want out of it. Words are easily misunderstood, an example with numbers should be clear.

---

<div class="post-metadata">

**Author:** ![graphicsop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/graphicsop/32/8663_2.png) [@graphicsop](https://discourse.nodered.org/u/graphicsop)\
**Post date:** [13 June 2019 11:00 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/28 "2019-06-13T11:00:13Z")

</div>

Hi Colin.

So the project consists of three or four voting questions.  
These are generated from an off-the-shelf event app..

Each question has 4 answers to choose from.  
Around 50 clients can each vote once on each question via the app.

Every time someone votes a message gets sent through via an Ably real-time feed.  
These messages come through as the message format at the top of this thread.

I need to collect up all of the individual votes for A, B, C or D and output a percentage for the overall result.

Below are the results that the app itself generates.  
Unfortunately, I don't have access to these results and have to regenerate them from the individual messages.  
 ![Vote_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/97ccd91d08a41ce0de09b35027368237a9774927.png)

Does that make more sense?

Many thanks  
Patrick

---

<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:** [13 June 2019 13:01 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/29 "2019-06-13T13:01:57Z")

</div>

In that situation I would start by writing the results to a database when they come in, then you can analyse the data as and when required.

---

<div class="post-metadata">

**Author:** ![graphicsop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/graphicsop/32/8663_2.png) [@graphicsop](https://discourse.nodered.org/u/graphicsop)\
**Post date:** [15 June 2019 18:04 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/30 "2019-06-15T18:04:35Z")

</div>

Thanks Colin.  
Do you know of any tutorials for creating databases and analysing data in them?

---

<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:** [15 June 2019 20:23 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/31 "2019-06-15T20:23:04Z")

</div>

Sqlite is probably the easiest to start playing with so you could search for sqlite tutorial. Once you understand how the database works then look at how to use it in node-red. There are sqlite nodes available.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 June 2019 22:35 UTC](https://discourse.nodered.org/t/creating-percentages-from-responses/12097/32 "2019-06-15T22:35:21Z")

</div>

Hi.

I don't like just _butting in_ but I am wanting to help if I can.

Graphicsop....

A `function` node can have multiple outputs.  
When you are editing the code, below that window is a small _selector_ which has the number of outputs. Default 1.

You can increase that to...... Well, more than enough for your needs.

Reading what you are doing, may I suggest a different method?

When the button is pressed, the message is created. Looking at your first post, you have two _fields_: `poll` and `person`.

When the message is sent put a `split` node in and _split_ on the `msg.poll` field.  
if (msg.poll == 31754) output 1  
if (msg.poll == 31755) output 2  
if (msg.poll == 31756) output 3  
(you get it)

Then you can send those off to parts of the code to process them as required.

Though I am not 100% sure what you want to do, that may help you.

[Previous page](https://discourse.nodered.org/t/creating-percentages-from-responses/12097.md?page=1)
