KoolReport's Forum

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

Pivot Matrix changing calculated columns does not work properly #2007

Open Aljaz Ketis opened this topic on on Apr 1 - 7 comments

Aljaz Ketis commented on Apr 1

I have 5 calculated columns that can be displayed inside PivotMatrix 3 that count the rows and 2 that sum one of the property, when you load its init columns and formation it works perfectly. But when you change the position of columns and switch order, the data either gets completely changed or only the text of the columns changes and not the values.

Sebastian Morales commented on Apr 2

Pls post your setup and view codes and screenshots if possible. Tks,

Aljaz Ketis commented on Apr 2

We have some important data, that i cannot share. But i can provide you my test Report with some array dummy data. View (TestReport.view.php):

<?php

use koolreport\pivot\widgets\PivotMatrix;

?>
<div class="report-content">
    <form class="form-inline" method="post">
        <?php
        PivotMatrix::create(
            array(
                "name"            => 'test',
                "dataStore"      => $this->dataStore("example_data"),
                'showDataHeaders' => true,
                "scope"           => array(
                    "_token" => csrf_token(),
                ),
                'width'           => '100%',
                'template'        => 'PivotMatrix-Bun',
                'totalName'       => 'Total',
                'waitingFields'   => array(
                    'room - count'            => 'data',
                    'seconds_can_spend - sum' => 'data',
                    'seconds_can_spend - avg' => 'data',
                    'seconds - sum'           => 'data',
                    'month'                   => 'label',
                    'day'                     => 'label',
                ),
                'paging'          => array(
                    'size'              => 5,
                    'maxDisplayedPages' => 5,
                    'sizeSelect'        => array(5, 10, 20, 50, 100),
                ),
            ),
        );
        ?>
    </form>
</div>

Report class (TestReport.php): - don't bother the BaseReport class that it is derrived from, it is ot used here, it automatically reads dynamic titles, inputs and adds them. Not used inside this one.

<?php

use koolreport\pivot\widgets\PivotMatrix;

?>
<div class="report-content">
    <form class="form-inline" method="post">
        <?php
        PivotMatrix::create(
            array(
                "name"            => 'test',
                "dataStore"      => $this->dataStore("example_data"),
                'showDataHeaders' => true,
                "scope"           => array(
                    "_token" => csrf_token(),
                ),
                'width'           => '100%',
                'template'        => 'PivotMatrix-Bun',
                'totalName'       => 'Total',
                'waitingFields'   => array(
                    'room - count'            => 'data',
                    'seconds_can_spend - sum' => 'data',
                    'seconds_can_spend - avg' => 'data',
                    'seconds - sum'           => 'data',
                    'month'                   => 'label',
                    'day'                     => 'label',
                ),
                'paging'          => array(
                    'size'              => 5,
                    'maxDisplayedPages' => 5,
                    'sizeSelect'        => array(5, 10, 20, 50, 100),
                ),
            ),
        );
        ?>
    </form>
</div>

Sebastian Morales commented on Apr 5

Pls post your TestReport.php's content again instead of duplicated TestReport.view.php's content. Give us a specific example how the result is as you expected. Tks,

Aljaz Ketis commented on Apr 5

Oh sorry, here is the TestReport.php:

<?php

namespace App\Reports;

use koolreport\amazing\Theme;
use koolreport\KoolReport;
use koolreport\pivot\processes\Pivot;
use koolreport\processes\CalculatedColumn;
use koolreport\processes\DateTimeFormat;

class TestReport extends BaseReport
{

    use Theme;

    public function settings()
    {
        return array(
            "dataSources" => array(
                "example" => array(
                    "class"      => '\koolreport\datasources\ArrayDataSource',
                    "data"       => array(
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '21',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "1",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '44',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "2",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '53',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "3",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '54',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "4",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '21',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "5",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '20',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "6",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '15',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "7",
                        ),
                        array(
                            "user"              => "User1",
                            "room"              => 'Room1',
                            "seconds"           => '76',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "8",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '88',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "1",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '12',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "2",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '40',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "3",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '35',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "4",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '76',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "5",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '53',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "6",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room2',
                            "seconds"           => '12',
                            "seconds_can_spend" => '60',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "7",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '87',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "1",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '40',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "2",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '85',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "3",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '63',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "4",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '34',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "5",
                        ),
                        array(
                            "user"              => "User2",
                            "room"              => 'Room3',
                            "seconds"           => '26',
                            "seconds_can_spend" => '40',
                            "year"              => "2021",
                            "month"             => "1",
                            "day"               => "6",
                        ),
                    ),
                    "dataFormat" => "associate",
                ),
            ),
        );
    }

    function setup()
    {
        parent::setup();

        $this->src('example')->pipe(
            new Pivot(
                array(
                    "dimensions" => array(
                        "column" => "year",
                        "row"    => "user",
                    ),
                    "aggregates" => array(
                        "avg" => "seconds",
                    ),
                )
            )
        )
            ->pipe($this->dataStore("example_data"));
    }
}
Sebastian Morales commented on Apr 6

What is the specific problem with pivot table's result? How did the result differ from what you expected? Tks,

Aljaz Ketis commented on Apr 6

As i said, inside PivotMatrix you can drag and drop values, and labels(rows, columns). Now init state stays the same, but when you drag and drop select all the values ( 'room - count, seconds_can_spend - sum, seconds_can_spend - avg, seconds - sum) and try to change its order,the results starts changing, seconds_can_spend - avg for example does not calcucalte the average of field seconds_can_spend, but for the column that id positioned before it, samo goes for count and everything else

Sebastian Morales commented on Apr 6

It's best if you can print some screenshots with before and after results and indicators of where you see as not valid. Tks,

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
bug

Pivot