KoolReport's Forum

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

Set Column Name in Pivot Table #474

Closed Dimitry opened this topic on on Sep 19, 2018 - 13 comments

Dimitry commented on Sep 19, 2018

Dear support, I am trying to name the aggregate columns in pivot table, but can`t find solution, can you please help?

This is my setup: $this->src('deptdata')

        ->query($sql)
        ->params($params)
        ->pipe(new ColumnMeta(array(
            "init_balance" => array(
                'label' => 'Balance',
                'type'  => 'float',
            ),
            "income" => array(
                'label' => 'Income',
                'type'  => 'float',
            ),
        )))
        ->pipe(new Pivot(array(
            "dimensions" => array(
                "column" => "",
                "row" => "client, currency, agreement_type, agreement, date",
            ),
            "aggregates" => array(
                "sum" => "init_balance, income, outcome, final_balance",
            ),
        )))
        ->pipe($this->dataStore('deptreport'));

This is my view: PivotTable::create(array(

        "dataStore"=>$this->dataStore('deptreport'),
        'headerMap' => array(
            'init_balance - sum' => 'Initial Ballance',
            'income - sum' => 'Income',
            'outcome - sum' => 'Outcome',
            'final_balance - sum' => 'Final Ballance',
        ),
    ));

Where can I add names for aggregate columns ('Initial Balance', 'Income', 'Outcome', 'Final Balance'?

Dimitry commented on Sep 19, 2018

I think there is simple solution, but I can`t find in documentation.

Can you please help?

David Winterburn commented on Sep 20, 2018

Hi Dimitry,

I don't fully understand your point. In the pivot table, pivot matrix widgets you could use the headerMap to change names of the headers ('Income', 'Outcome', etc). Can you elaborate what you meant by "name the aggregate columns in pivot table"? Thanks!

Dimitry commented on Sep 20, 2018

Hi David,

Sorry for confusing you I had to be more specific.

My boss want me to name "Total" columns like that:

I was trying to find some examples on your forum, but couldn't.

I am using "headerMap" but it is working only on the left top corner (as you can see).

David Winterburn commented on Sep 20, 2018

Hi Dimitry,

At the moment Pivot Table hasn't had an option for adding a row of aggregated columns to the data part like that (KoolPHP.net's KoolPivotTable does have it though). We would consider adding this option to the interface of both Pivot Table and Pivot Matrix.

Please wait for some time, maybe several weeks. Thanks for your feedback!

Dimitry commented on Sep 20, 2018

Dear David,

That`s good news. Thanks, will wait for new release.

Dimitry commented on Nov 15, 2018

Dear Koolreport team. You did it, it really work in v.3

Thank you. You are the best! :)

Dimitry commented on Nov 15, 2018

The only thing I face is that I can`t give aliases to more then 4 columns. Can you pls take a look if I did some thing wrong.

    PivotTable::create(array(
        "dataStore"=>$this->dataStore('ofstoreport'),
        'headerMap' => array(
            'init_count_balance - sum' => 'Initial count balance',
            'count_income - sum' => 'Count Income',
            'count_outcome - sum' => 'Count Outcome',
            'final_count_balance - sum' => 'Final count balance',
            'init_summ_balance - sum' => 'Initial summ balance',
            'summ_income - sum' => 'Summ Income',
            'summ_outcome - sum' => 'Summ Outcome',
            'final_summ_balance - sum' => 'Final summ balance'
        ),
        'hideSubtotalRow' => true,
        'hideSubtotalColumn' => true,
        'showDataHeaders' => true,
    )); 

but as you can see only 4 of headerMap aliases is ok.

Dimitry commented on Nov 27, 2018

Dear support,

good day,

can you pls help with this issue?

David Winterburn commented on Dec 5, 2018

Hi Dimitry,

Would you please post your report's setup php code where you pipe the Pivot process? Thanks!

Dimitry commented on Dec 5, 2018

Hi David, sure, this is my Pivot process code:

$this->src('ofstordata')

        ->query($sql)
        ->params($params)
        ->pipe(new ColumnMeta(array(
            "init_balance" => array(
                'label' => 'Balance',
                'type'  => 'float',
            ),
            "income" => array(
                'label' => 'Income',
                'type'  => 'float',
            ),
        )))
        ->pipe(new Pivot(array(
            "dimensions" => array(
                "column" => "",
                "row" => "storage, offer, name",
            ),
            "aggregates" => array(
                "sum" => "init_count_balance, count_income, count_outcome, final_count_balance",
                "init_summ_balance, summ_income, summ_outcome, final_summ_balance"
            ),
        )))
        ->pipe($this->dataStore('ofstoreport'));
Dimitry commented on Dec 11, 2018

Dear support. Good day. Is there any chance to get help from you?

David Winterburn commented on Dec 17, 2018

Hi Dimitry,

Sorry for the late reply. After checking your code, I think there's a problem with this part:

            "aggregates" => array(
                "sum" => "init_count_balance, count_income, count_outcome, final_count_balance",
                "init_summ_balance, summ_income, summ_outcome, final_summ_balance"
            ),    

Basically it is equivalent to:

            "aggregates" => array(
                "sum" => "init_count_balance, count_income, count_outcome, final_count_balance",
                0 => "init_summ_balance, summ_income, summ_outcome, final_summ_balance"
            ),

What you want to change to is:

            "aggregates" => array(
                "sum" => "init_count_balance, count_income, count_outcome, final_count_balance, init_summ_balance, summ_income, summ_outcome, final_summ_balance"
            ),

Let us know if this works for you. Thanks!

Dimitry commented on Dec 17, 2018

Hi David,

Thank you for your reply. This was my mistake, I can see it now. Thanks again :)

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
solved

None