KoolReport's Forum

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

Multiple aggragetes #29

Closed Hallie Gromek opened this topic on on Jul 11, 2017 - 6 comments

Hallie Gromek commented on Jul 11, 2017

Hi,

I am trying to place sales and cases into the aggregates for a pivot report, however when I add cases the Sales no longer calculate (just 0 for all, even lost the formatting), any trick on how to accomplish this?

      'aggregates'=>array(
        'sum'=>'dollar_sales',
       'sum'=>'cases'
David Winterburn commented on Jul 12, 2017

Hi Hallie,

Would you please post your entire report's php code for us to check? Thanks!

Hallie Gromek commented on Jul 13, 2017

Here is the set up: ` function setup() {

$node = $this->src('main')
->query("SELECT cust_name AS customerName, cust_number, brand_description, yr as shipYear, ship_date, qtr, gross_dollars AS dollar_sales, quantity_ordered as cases,  prin_name, item_description AS productName FROM new_hist_a 
	WHERE prin_number = :clients AND cust_number = :customers 
			AND 	
            ship_date > :start
            AND
            ship_date < :end
    ")
    ->params(array(
        ":start"=>$this->params["dateRange"][0],
        ":end"=>$this->params["dateRange"][1],
        ":customers"=>$this->params["customers"],
		":clients"=>$this->params["clients"]
    ))


->pipe(new ColumnMeta(array(
  'dollar_sales'=>array(
    'type' => 'number',
    'prefix' => '$',
  ),
)))
->pipe(new Pivot(array(
  'dimensions'=>array(
    'column'=>'shipYear',
	'row'=> 'productName'
	
  ),
  'aggregates'=>array(
    'sum'=>'dollar_sales',
   'sum'=>'cases'
  )
)))
->pipe($this->dataStore('sales'));  


Here is the view:
      $dataStore = $this->dataStore('sales');
      PivotTable::create(array(
        'dataStore'=>$dataStore,
        'rowDimension'=>'row',
		'columnDimension'=>'column',
        'measures'=>array(
          'dollar_sales - sum', 
         'cases - sum',
        ),
       // 'rowSort' => array(
       //   'dollar_sales - sum' => 'desc',
     //   ),
        'rowCollapseLevels' => array(1),
		'columnCollapseLevels' => array(0),
        //'totalName' => 'All',
        'width' => '100%',
        'nameMap' => array(
          'dollar_sales - sum' => 'Sales (in USD)',
         'cases - sum' => 'Cases',
        ),
      ));

Hallie Gromek commented on Jul 13, 2017

Here is how it displays

David Winterburn commented on Jul 14, 2017

Hi Hallie,

Please change this code

  'aggregates'=>array(
    'sum'=>'dollar_sales',
   'sum'=>'cases'
  )

to

  'aggregates'=>array(
    'sum'=>'dollar_sales, cases',
  )

In PHP, when you use a literal array with the same indexes, only the last one has meaning (i.e 'sum'=>'dollar_sales' has no meaning in this case). Please let us know if this works for you. Thanks!

Hallie Gromek commented on Jul 17, 2017

This don't work, only sums the first aggregates, so dollar_sales.will work and cases will be zero.

Hallie Gromek commented on Jul 31, 2017

This now executes, thank you !

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
solved

Pivot