# Choose Fields in PivotEngine

Learn about choosing fields in Wijmo's OLAP Pivot Engine in this documentation topic

## Content


By default, the __PivotEngine__ creates fields automatically based on the raw data it gets from the __itemsSource__ property.

In some cases, you may want to turn that feature off and specify the fields explicitly. For example, you may want to:

- Include only some of the fields available in the data source
- Customize the field properties,
- Create multiple fields based on the same binding (clone fields).

## Clone Measure Fields

In some cases, you may want to summarize values using different aggregates. For example, you may want to show total and average values on the same view. Or you may want to show values next to calculated values such as running totals, differences, or percentages.

To do this, create multiple fields with the same __binding__ and different __aggregate__ or __showAs__ values.

```javascript
let ng = new wjOlap.PivotEngine({
  	autoGenerateFields: false, // turn off auto-generation
    fields: [ // specify the fields we want (no date)
    	{ binding: 'buyer', header: 'Person' },
    	{ binding: 'type', header: 'Category' },
    	{ binding: 'amount', header: 'Total', format: 'c0', aggregate: 'Sum' },
    	{ binding: 'amount', header: 'Average', format: 'c0', aggregate: 'Avg' },
    ],
    itemsSource: getData(10000), // raw data
    showRowTotals: 'Subtotals',
    valueFields: ['Total', 'Average'], // show total and average
    rowFields: ['Person', 'Category'] // by Person and Category
});
```

If you use a __PivotPanel__ control, users may create clone fields by dragging the same source field to the values list multiple times.

## Clone Dimension Fields

In some cases, you may want to use a dimension value in multiple ways. For example, you may want to break up the data according to a date's year and/or quarter.

To do this, create multiple fields with the same __binding__ and different __format__ values.

```javascript
let ng = new wjOlap.PivotEngine({
  	autoGenerateFields: false, // turn off auto-generation
    fields: [ // specify the fields we want (no date)
    	{ binding: 'date', header: 'Year', format: 'yyyy', width: 80 },
    	{ binding: 'date', header: 'Quarter', format: '"Q"q', width: 80 },
    	{ binding: 'buyer', header: 'Person' },
    	{ binding: 'type', header: 'Category' },
    	{ binding: 'amount', header: 'Amount', format: 'c0', aggregate: 'Sum' },
    ],
    itemsSource: getData(10000), // raw data
    showRowTotals: 'Subtotals',
    valueFields: ['Amount'], // show amount spent
    rowFields: ['Year', 'Quarter'] // by Year and Quarter
  });
```

## Deep Binding

You can bind __PivotField__ objects to sub-properties of the data items.

For example, the data in this example below has an 'emotion' member that has four sub-properties. The __PivotEngine__ has fields that bind to each one using binding strings 'emotion.happiness', 'emotion.fear', etc.

```javascript
let theEngine = new wjOlap.PivotEngine({
    autoGenerateFields: false,
    fields: [
    	{ binding: 'country', header: 'Country', width: 90 }, 
        { binding: 'product', header: 'Product'},
        { header: 'Emotion', subFields: [
	        { binding: 'emotion.happiness', header: 'Happiness', dataType: 'Number' },
    	    { binding: 'emotion.surprise', header: 'Surprise', dataType: 'Number' },
  	        { binding: 'emotion.fear', header: 'Fear', dataType: 'Number' },
      	    { binding: 'emotion.disgust', header: 'Disgust', dataType: 'Number' }
		]}
	],
	rowFields: ['Product'],
	valueFields: ['Happiness', 'Surprise'],
    itemsSource: getData(1000)
  });
```
