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',
),
));