Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
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];
} __
),
)
)))
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
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!
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 ?
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,
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,
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
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo