KoolReport's Forum

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

Pivot table and pivot process in Dashboard #3186

Open John opened this topic on on Nov 4, 2023 - 2 comments

John commented on Nov 4, 2023

I have a pivot table in Dashboard and i want to add a column where i'll show the difference between current and previous period. Is this possible? Do i have to use pivot2D process like your example below or something else? https://www.koolreport.com/docs/pivot/pivot2D_process/

John commented on Nov 4, 2023

For example i have tried the code below but it doesn't work.

class myPivot extends PivotTable
{
    protected function process()
    {
        return [
,,,
            "computations" => array(
				"yearlyDifference" => "{2023-10} - {2023-09}",
				"monthlyDifference" => function($aggRow) {
				return ($aggRow['2023 -||- 11 -||- Amount - sum'] ) - ($aggRow['2023-10 -||- Amount - sum'] ?? 0);
				},
....

I also tried this code without success:

    protected function display()
    {
        return [
...
            'map' => array(
        "{value}" => function($row) {
            $row["2023 -||- 11 -||- percentage change"] = 
                100 * $row["2023 -||- 11 -||- Amount - sum"] / $row["2023 -||- 10 -||- Amount - sum"];
            return $row;
        }
Sebastian Morales commented on Nov 6, 2023

Oh, I guess there's a bug with Pivot's computations in the latest version. We will release a fix soon for you to try it again. Rgds,

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

Dashboard