KoolReport's Forum

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

Display text value as part of cube or pivot data cell #697

Open Daniel Amamoo-Otchere opened this topic on on Feb 20, 2019 - 17 comments

Daniel Amamoo-Otchere commented on Feb 20, 2019

Hello, I will like to build the following where the data-cell is a text rather than an aggregated value. Please see snapshot below. Can this be accomplished ?

Daniel Amamoo-Otchere commented on Feb 20, 2019

Hello Kool Team, Any help with this reported issue?

Daniel Amamoo-Otchere commented on Feb 21, 2019

Hello Team, Any help with this?

David Winterburn commented on Feb 22, 2019

Hi Daniel,

Can you please describe how do you get the text values to put in the cells? Thanks!

Daniel Amamoo-Otchere commented on Feb 22, 2019

Hello David, This is a pivot chart The code below gives the template for what I want to achieve. Instead of sum or count under aggregates, I want to replace with the event value. I hope the example is clear.

Table

Mon        Day            Event
1                1                Meeting with Nana
1                5                Community Meeting with Toton
2                10               Departmental Meeting
protected function setup()
{
    $this->src('pace')
    ->query("
        
    SELECT 
	month,	day,       Event
        FROM  events 
    ")
   ->pipe(
       new Pivot(
        array(  
                "dimensions"=>array(
                    "column"=>"day",  
                    "row"=>"month",
                ),
          __  "aggregates"=>array(
                 "value"=>array(
                       "formatValue"=>function($value,$row)
                    {
                        return $row[$event];
                    }        __
                ),
            )
        )))
Daniel Amamoo-Otchere commented on Feb 22, 2019

Hello, Any update on my issue please.

Daniel Amamoo-Otchere commented on Feb 23, 2019

Hello David Winterburn, Any feedback to this issue. I have lots of report to generate like that and some quick assistance will be greatly appreciated.

The idea is to return the exact value rather than performing an aggregate in the cross tab or pivot table

David Winterburn commented on Feb 25, 2019

Hi Daniel,

I think at the moment the Pivot process hasn't had ability to do custom aggregation like what you described. We will think of an API to let use defined their custom aggregating function for the pivot process in the future. In the meantime, you could try it yourself with some code like this:

->pipe(new Pivot(array(
            "dimensions" => array(
                "column" => "Month",
                "row" => "Year",
            ),
            "aggregates" => array(
                "myAgg" => "event",
            ),
        )))

Then open the file packages/pivot/processes/pivot.php and edit the function aggValue($operator, $value1, $value2 = null) to allow for your myAgg aggregation. Thanks!

Daniel Amamoo-Otchere commented on Mar 9, 2019

Helllo David, I tried it and got the following result

The code for the pivot section I modified. Please note it is string and not a number.

 private function aggValue($operator, $value1, $value2 = null)
    {
        switch ($operator) {
            case 'myAgg':  
               return $value1;
            case 'min':
                return min($value1, $value2);
            case 'max':
                return max($value1, $value2);
            case 'count':
            case 'count percent':
                return $value1 + 1;
            case 'avg':
            case 'sum':
            case 'sum percent':
            
            default:
                return (float) $value1 + (float) $value2;
        }
    }

Can you come online and check for me please ?

Daniel Amamoo-Otchere commented on Mar 11, 2019

Hello Any help for me?

David Winterburn commented on Mar 12, 2019

Hi Daniel,

Please edit the following method as well for your custom aggregation:

private function initValue($operator)
{
...
}

If the initial value is empty (blank space or null) you might want to use later non empty value in function aggValue. Let us know if you have any difficulty. Thanks!

Daniel Amamoo-Otchere commented on Mar 14, 2019

Hello David, Tried it but It is still not working. Yes, I am having difficulty.

Can you come online and assist?.

Daniel Amamoo-Otchere commented on Mar 15, 2019

Hi, Any update for me on this. It still did not work. Need it to finalise a report. Will appreciate some solution to it.

Daniel Amamoo-Otchere commented on Mar 15, 2019

HELLO, ANY HELP!!!

Should I send the data and the files by email for assistance?

KoolReport commented on Mar 16, 2019

Daniel,

I will get David to answer your questions as soon as possible. The latest is on Monday. David is in the dev.team and the pivot creator so his answer will be the best.

And yes, please send your code to support@koolphp.net to reach David.

Thank you very much and so sorry for the delay.

Regards,

David Winterburn commented on Mar 18, 2019

Hi Daniel,

Please send us an email to support@koolphp.net. We will send you a development version of the Pivot package which could help you with custom aggregating function. Thanks!

Daniel Amamoo-Otchere commented on Mar 22, 2019

Hello David, Good day. I sent an email but no response. It was with my outlook mail. Kindly check your spam..

Regards, Daniel

Daniel Amamoo-Otchere commented on Mar 26, 2019

Hello Kool Team, Thanks for the quick dirty feedback. It worked with some exception I will want to draw your attention so you kindly consider the following features :

1. Please kindly add a feature to the Pivot and Cube system so that the raw values coming out can be plotted as well as displayed in the pivot table rather than a sum. It is not all cases that users will want to perform an aggregate.

2. Allow the Users to be able to turn off the pivot grand row and column totals as they may not be required.

Looking forward to these features if you can add it to your next Pivot/Cube feature release

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