UI TABLE - AVG for column

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}]

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

[{"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

$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
```

I need it in a table

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.

1 Like

I'm not English speaking, hence the understatements

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. 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.

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.

[{"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}]

I found a solution
it is simple
import examples

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

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