KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

True count and avg in grouping process #1640

Open Thomas opened this topic on on Oct 1, 2020 - 3 comments

Thomas commented on Oct 1, 2020

I have the following table and want the average and the count of each column. Unfortunately the group process takes the empty fields (empty and null) into account and gives me the wrong result.

E.g. the first column has a sum=16 and a number-count=5, so it should be 16/5=3,2 but the result ist 2,6666.

My goal is to have the following data "average of only the answered fields", "count of answered (not empty) fields", "count of not answered (empty) fields"

$survey_data_group_2
        ->pipe(new Filter(array(
            array("lastpage","=","5")
        )))
        ->pipe(new Transpose2())
        
        ->pipe(new Filter(array(
            array("c0","endWith","a")
        )))
        ->pipe(new Transpose2())
        ->pipe(new RemoveColumn(array(
            "c0"
        )))
        ->pipe(new Group(array(
            "avg"=>$columnNames,
            
        )))
        ->pipe($this->dataStore('data3'));

Is it possible to define the grouping process? Or what would be an alternative solution?

David Winterburn commented on Oct 1, 2020

Hi Thomas,

Please try the Cube process:

https://www.koolreport.com/docs/cube/cube_process/

Just don't include "row" property, it should work like Group. Please see if it give the end result you want. Thanks!

Thomas commented on Oct 6, 2020

I am using the Aggregated Methods in the view and making a new array through a loop. That way I can filter the results first and than process them further.

Can I transform an array back into a KoolReport object (DataStore)? So the opposite of toArray().

David Winterburn commented on Oct 6, 2020

Hi Thomas,

You could create a DataStore from arrays of data and metadata like this:

    $ds = new \koolreport\core\DataStore($arrData, $arrMeta);

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None