How to get a average number from multiple pages?

  • 1
  • Question
  • Updated 3 years ago
So let's say I have a page called The-Parent where I want to average a number-data macro field from 10 children.

On the child pages I have a table and on of the rows has the number-data field called Child-Num-Field. I've been having a lot of trouble figuring out how to set up a reporter such that I can take all ten of these numbers and average them out and display that average on The-Parent.

Any tutorials or suggestions for how to do this?
Photo of Patrick Gray

Patrick Gray

  • 4 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of Chuck Gould

Chuck Gould

  • 93 Posts
  • 2 Reply Likes
Might investigate Stats On Supplier.

Overview

Performs basic statistical analysis on values in a Collection of items.

This supplier takes a quoted keychain which will usually point to a number, date or other 'comparable' value, and processes each item, resulting in a Stats report that lets you access the results, such as the sum, average, min, max, etc. Also see the grouping-reporter for for more complex options.

https://docs.servicerocket.com/display/SUP/Stats+On+Supplier


Photo of Patrick Gray

Patrick Gray

  • 4 Posts
  • 0 Reply Likes
Okay so I have a Report-Info macro on the parent page and its key is: 
page:children > stats-on:"number:Child-Num-Field" > stats:value average
And in this example I have a Number-Data macro on two child pages and these numbers are 100 and 200 but it is returning 0.0. Any idea what is wrong in my key?
Photo of Chuck Gould

Chuck Gould

  • 93 Posts
  • 2 Reply Likes
Patrick,

Another tack that might help and be easier if you want to display the values as well as the average.

Confluence:  5.1.3
Reporting: 4.2.3
Scaffolding: 5.0.14

{report-table}
{local-reporter:page:children}
{report-column:title=Page}
{report-info:page:title|link=true}
{report-column}
{report-column:title=Number|summaryType=average|summaryValue=dataMyNUmber}
{report-info:data:MyNumber}
{report-table}

If you need the average with out reporting the table contents, that is a different challenge and probably will involve the Stats On Supplier I mentioned earlier.

This is the report-info code I used for that:

{report-info:page:children > stats-on:"data:MyNumber" > stats:value average}

When referencing scaffolding data fields regardless of type, typically the format is:

data:<field name> in my experience.

If you are referencing a field called Number on a child page the key reference would be data:Number I think.

The results I got with this code were table first with calculation then stand along report-info with stats on supplier code.  Obviously you can add a format parameter to the output as well.



Does this help?
Photo of Patrick Gray

Patrick Gray

  • 4 Posts
  • 0 Reply Likes
Ah this is great!! Thanks for the thorough response! I just got it to work in a simplified example. Now I have one more complicating factor in the overall issue I am trying to resolve.

What I am actually trying to do it average a set of numbers that have been selected from a list-data marco that is pulling the number options from a different source.

So my code for pulling and displaying the list of numbers is:
{list-data:amount options|required=true|multiple=true}{report-block}{local-reporter:data:amount options|source=LSI:Data Page}<br>{report-body:injected=true}{list-option}%data:amount options%{list-option}{report-body}<br>{report-block}{list-data}

And this correctly displays the numbers and allows me to select one. But I am not able to average those numbers, it has the same issue, it just shows 0.0. Is there some way to enforce the list option being a number and thus allowing it to be averaged?
Photo of Chuck Gould

Chuck Gould

  • 93 Posts
  • 2 Reply Likes
Patrick,

If I report list-option numerics from multiple pages, they are treated as numerics.  What has me stumped is when you report list data that has multiple selections it is returned as a set.  I don't know how to apply math to a set at this time.