KoolReport's Forum

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

Count column values on footer band with conditions #280

Open Jose opened this topic on on May 11, 2018 - 1 comments

Jose commented on May 11, 2018

I'm using the Table Component. I need to count only the values at a certain column that are not null (or zero).

KoolReport commented on May 12, 2018

We have not had default count null or non-null for column yet so here is a solution:

<?php
$count_mycolumn = 0;
$this->dataStore("mystore")->popStart();
while($row = $this->dataStore("mystore")->pop())
{
    if($row["mycolumn"]!=null)
    {
        $count_mycolumn++;
    }
}
Table::create(array(
    "dataSource"=>$this->dataStore("mystore"),
    "showFooter"=>"bottom",
    "columns"=>array(
        "mycolumn"=>array(
            "footerText"=>"$count_mycolumn";
        )
    ),
    ...
));
?>

As you can see, the above code will read dataStore and count the non-null in mycolumn. Then it show at footerText of that column. You can use number_format() to format the count number as you wish.

Hope that helps.

Please let us know if you need further assistance.

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
None yet

None