# UI TABLE - AVG for column

**URL:** <https://discourse.nodered.org/t/ui-table-avg-for-column/72062>\
**Category:** Dashboard\
**Created:** [12 December 2022 10:27 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062 "2022-12-12T10:27:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Misiek](https://discourse.nodered.org/u/Misiek)\
**Post date:** [12 December 2022 10:27 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/1 "2022-12-12T10:27:39Z")

</div>

How to calculate the mean for a column AGE

[{"id":"fc017255.0ba51","type":"inject","z":"5f148060.7dc86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{"Name":"Kazuhito Yokoi","Age":"35","Favourite Color":"red","Date Of Birth":"12/09/1983"},{"Name":"Oli Bob","Age":"12","Favourite Color":"cyan","Date Of Birth":"12/08/2017"},{"Name":"Oli Bobee","Age":"28","Favourite Color":"yellow","Date Of Birth":"12/08/2017"}]","payloadType":"json","x":390,"y":1440,"wires":[["65269531.385bdc"]]},{"id":"65269531.385bdc","type":"ui\_table","z":"5f148060.7dc86","group":"b648849d.e9ced8","name":"","order":1,"width":0,"height":0,"columns":,"outputs":0,"cts":false,"x":550,"y":1440,"wires":},{"id":"b648849d.e9ced8","type":"ui\_group","name":"Default","tab":"ed4b4ded.00d09","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"ed4b4ded.00d09","type":"ui\_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

---

<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:** [12 December 2022 12:05 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/2 "2022-12-12T12:05:53Z")

</div>

You can use a change node and a JSONata expression  
e.g.

```auto
[{"id":"fc017255.0ba51","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Name\":\"Kazuhito Yokoi\",\"Age\":\"35\",\"Favourite Color\":\"red\",\"Date Of Birth\":\"12/09/1983\"},{\"Name\":\"Oli Bob\",\"Age\":\"12\",\"Favourite Color\":\"cyan\",\"Date Of Birth\":\"12/08/2017\"},{\"Name\":\"Oli Bobee\",\"Age\":\"28\",\"Favourite Color\":\"yellow\",\"Date Of Birth\":\"12/08/2017\"}]","payloadType":"json","x":130,"y":4560,"wires":[["65269531.385bdc","3dd3488244c70cd8"]]},{"id":"65269531.385bdc","type":"ui_table","z":"452103ea51141731","group":"b648849d.e9ced8","name":"","order":1,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":290,"y":4560,"wires":[]},{"id":"3dd3488244c70cd8","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$average($$.payload.Age.$number($))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":4600,"wires":[["5d489f5399f56b56"]]},{"id":"5d489f5399f56b56","type":"debug","z":"452103ea51141731","name":"debug 113","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":4600,"wires":[]},{"id":"b648849d.e9ced8","type":"ui_group","name":"Default","tab":"ed4b4ded.00d09","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"ed4b4ded.00d09","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

Expression

```auto
$average($$.payload.Age.$number($))

```

p.s. please format your flow example correctly. Use the \</\> button and paste between the triple backticks. As you flow is corrupt due to forum formatting.  
e.g.  
```  
paste code  
```

---

<div class="post-metadata">

**Author:** ![Misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Misiek](https://discourse.nodered.org/u/Misiek)\
**Post date:** [12 December 2022 16:04 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/3 "2022-12-12T16:04:05Z")

</div>

I need it in a table

---

<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:** [12 December 2022 16:21 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/4 "2022-12-12T16:21:37Z")

</div>

> [@Misiek](#):
>
> How to calculate the mean for a column AGE

Then you should have asked for it in the table, and also shown were you wanted it displayed. The people who help here do not read minds.

---

<div class="post-metadata">

**Author:** ![Misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Misiek](https://discourse.nodered.org/u/Misiek)\
**Post date:** [12 December 2022 16:54 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/5 "2022-12-12T16:54:33Z")

</div>

I'm not English speaking, hence the understatements

---

<div class="post-metadata">

**Author:** ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)\
**Post date:** [12 December 2022 17:27 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/6 "2022-12-12T17:27:16Z")

</div>

Hey Misiek. You'll find that ui-table is a bit underpowered in terms of what it can do and what it can't. It's based on Tabulator 4.2, which is very outdated. You can find the documentation for that version [here](https://tabulator.info/docs/4.2/column-calcs). While I don't know how the ui-table wrapper passes in commands or things like that, anything related to what it can do would be found in that documentation.

One thing I've been suggesting to people is if they need advanced functionality that ui-table can't provide, take a look at using Tabulator directly. It's a bit of a learning curve and if you have a lot of tables you're using, it will take some time to adopt. But once adopted, you have full control and you can use the newly updated source instead of an old outdated copy.

It's up to you on how you want to do it. If you need that average and don't want to adopt Tabulator fully, you could easily use a function node to calculate the average of all the ages and send it in with a "Name" value of "Average" and an "Age" value that is the average age. It's not a pretty solution, but it's effective and it will work.

---

<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:** [12 December 2022 17:48 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/7 "2022-12-12T17:48:40Z")

</div>

Use Google Translate.

A good description and examples goes a long way.

You can shoehorn it at the end, But I don't know where you want it, as you fail to say.

```auto
[{"id":"fc017255.0ba51","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Name\":\"Kazuhito Yokoi\",\"Age\":\"35\",\"Favourite Color\":\"red\",\"Date Of Birth\":\"12/09/1983\"},{\"Name\":\"Oli Bob\",\"Age\":\"12\",\"Favourite Color\":\"cyan\",\"Date Of Birth\":\"12/08/2017\"},{\"Name\":\"Oli Bobee\",\"Age\":\"28\",\"Favourite Color\":\"yellow\",\"Date Of Birth\":\"12/08/2017\"}]","payloadType":"json","x":130,"y":4560,"wires":[["3dd3488244c70cd8"]]},{"id":"3dd3488244c70cd8","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"length","pt":"msg","to":"$count($$.payload)","tot":"jsonata"},{"t":"set","p":"payload[msg.length].Age","pt":"msg","to":"$average($$.payload.Age.$number($))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":4600,"wires":[["5d489f5399f56b56","65269531.385bdc"]]},{"id":"5d489f5399f56b56","type":"debug","z":"452103ea51141731","name":"debug 113","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":4600,"wires":[]},{"id":"65269531.385bdc","type":"ui_table","z":"452103ea51141731","group":"b648849d.e9ced8","name":"","order":1,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":450,"y":4520,"wires":[]},{"id":"b648849d.e9ced8","type":"ui_group","name":"Default","tab":"ed4b4ded.00d09","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"ed4b4ded.00d09","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Misiek](https://discourse.nodered.org/u/Misiek)\
**Post date:** [12 December 2022 19:40 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/8 "2022-12-12T19:40:21Z")

</div>

I found a solution  
it is simple  
import examples

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

---

<div class="post-metadata">

**Author:** ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)\
**Post date:** [12 December 2022 21:03 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/9 "2022-12-12T21:03:03Z")

</div>

Glad you were able to find a good solution. Enjoy!

---

<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:** [10 February 2023 21:03 UTC](https://discourse.nodered.org/t/ui-table-avg-for-column/72062/10 "2023-02-10T21:03:27Z")

</div>

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