KoolReport's Forum

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

Can I add CalculatedColumns to Pivots? How to reference Pivot aggregate columns? #650

Open Keith Burke opened this topic on on Feb 5, 2019 - 5 comments

Keith Burke commented on Feb 5, 2019

Is it possible to use processes like CalculatedColumn or DifferenceColumn on Pivots? If so, how to reference pivot columns?

For example, I have rows based on Site, subdivided into Annual / Monthly members. I then have columns based on membership status, sub grouped into gender.

I want to add a CalculatedColumn to tell me, for example, the percentage of Active Females of Total Active members. How do I reference aggregated columns? For reference, I've added the Pivot below too.

    public function setup()
    {
        $this->src('query_source')
        ->query("Select * "
                . "From v_active_subscription vas  "
                . "     Inner Join ff_members m on vas.member_id = m.id "
                . "     Inner Join ff_genders g on g.id = m.gender_id "
                . "      Where subscription_type not like 'Flex%' "
                . "      and subscription_status not like 'Suspended%' "
                . "Group By concat(lpad(vas.gym_id,2,'0'), ' - ', gym_name), subscription_status, subscription_type, g.gender_name "
                . "Order By concat(lpad(vas.gym_id,2,'0'), ' - ', gym_name), subscription_status, subscription_type, g.gender_name;")
        ->pipe(new Pivot(array(
            'dimensions'=>array(
                'column'=>'Status,Gender',
                'row'=>'Gym,Product'
            ),
            'aggregates'=>array(
                'sum'=>'Members'
            )
        )))
        ->pipe($this->dataStore('active_members_query_result'));
    }
Keith Burke commented on Feb 7, 2019

Any update on this?

KoolReport commented on Feb 7, 2019

We are currently on holiday for few days, I will get you the Pivot developer to answer your questions on Monday.

Keith Burke commented on Feb 7, 2019

Sure, no problem. Thanks.

David Winterburn commented on Feb 12, 2019

Hi Keith,

What you described is very interesting but I haven't found a solution to achieve that with our current version of the Pivot package. But given its potential we are exploring ways to make it possible with Pivot package. Please wait for a few weeks. I'll let you know when there's a solution. Thanks!

Keith Burke commented on Feb 12, 2019

Thanks David.

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

Pivot