KoolReport's Forum

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

Count Rows by group if column has data #1242

Open Andrew Guattery opened this topic on on Jan 2, 2020 - 1 comments

Andrew Guattery commented on Jan 2, 2020

Well the topic says it all: I know when can count rows in a group like so:

"{count}"=>array("count","COL_NAM")

What I am trying to do is count the row only if the column has a value. Something like:

"{count}"=>array("count","COL_NAM" <>"")

or

"{count}"=>array("count","COL_NAM" > 0)

Is this possible?

KoolReport commented on Jan 3, 2020

It is possible, you can use your own calculation like this:

Table::create(array(
    "grouping"=>array(
        "year"=>array(
            "calculate"=>array(
                "{countAvailable}"=>function($store){
                    return $store->filter("COL_NAME",">",0)->count();
                }
            ),
            "top"=>"<b>Count COL_NAME {countAvailable}</b>",
        )
    )
    ...
));

Here is the documentation of Table Grouping Calculate and DataStore's Filter Method.

Hope that helps.

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