# Defining Fields

Develop powerful and lightweight web applications using ASP.NET MVC controls. Learn more about the ComponentOne MVC controls in ASP.NET MVC documentation.

## Content



The main advantage of an OLAP application is interactivity. User must be able to create and modify views, easily and quickly see the output on the web browser. This is possible in OLAP with the help of Excel-like user interface and user friendly dialogs. However, you can also configure the view and add the following fields through code in the OLAP control.

*   [Add Pivot Fields](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/workwitholap/DefiningPivotFields#add-pivot-fields)
*   [Add Cube Fields](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/workwitholap/DefiningPivotFields#add-cube-fields)

### Add Pivot Fields

To configure the view and add pivot fields through code, you need to use the **AddPivotField** method.


> type=note
> **Note**: In case your field name has multiple upper case letters (For example - ProductName), then view field adds a space between the field names on every instance of upper case letter and throws an exception. You can resolve this by setting the header property of pivot fields to a value same as the field name.

The following image shows how OLAP control appears after defining pivot fields.

![](https://cdn.mescius.io/document-site-files/images/2b3ac322-100e-4637-958d-fb40dcda3f44/images/olappivotfields.png)

If you do not want to auto-generate the fields, use the following example code to define pivot fields in the OLAP control. The example uses **ProductData.cs** model added in the [Quick Start: Add Data to OLAP](/componentone/docs/mvc/online-mvc/workwithcontrols/Olap/QuickStartOlap) topic.

```razor
@using <ApplicationName>.Models;
@model IEnumerable<ProductData>
@(Html.C1().PivotEngine().Id("indexEngine").Bind(Model)
    .Fields(fld =>
    {
        fld.Items(it => it.AddPivotField(pf => pf.Binding("Country"))
        .AddPivotField(pf => pf.Binding("Product"))
        .AddPivotField(pf => pf.Binding("Sales").Aggregate(C1.Web.Mvc.Grid.Aggregate.Avg)));
    })
    .RowFields(pfcb => pfcb.Items("Country"))
    .ColumnFields(cfcb => cfcb.Items("Product"))
    .ValueFields(vfcb => vfcb.Items("Sales")))
@(Html.C1().PivotGrid().ItemsSourceId("indexEngine"))
```

### Add Cube Fields

To configure the view and add cube fields through code, you need to use the **AddCubeField** method. This method helps you to add a cube field by the specified action to the collection. While adding cube fields, you need to make sure that you set the dimension type for each field using the **DimensionType** method provided by the **CubeFieldBuilder** class.

The following image shows how OLAP control appears after defining cube fields.![](https://cdn.mescius.io/document-site-files/images/2b3ac322-100e-4637-958d-fb40dcda3f44/images/addcubefield.png)

If you do not want to auto-generate the fields, use the following example code to define cube fields in the OLAP control.

```razor
@* Initialize PivotEngine*@
@(Html.C1().PivotEngine().Id("cubeEngine")
       .BindCubeService("http://ssrs.componentone.com/OLAP/msmdpump.dll", "Adventure Works")
       .Fields(pfcb =>
            pfcb.Items(c =>
                c.AddCubeField(fb => fb.Header("Internet Orders")
                    .DimensionType(DimensionType.Folder)
                    .SubFields(sfsb =>
                        sfsb.Add(sfb => sfb.Header("Internet Order Count")
                            .Binding("[Measures].[Internet Order Count]")
                            .DimensionType(DimensionType.Measure)
                            .DataType(C1.Web.Mvc.Grid.DataType.Number))))
                .AddCubeField(fb => fb.Header("Internet Customers")
                    .DimensionType(DimensionType.Folder)
                        .SubFields(sfsb =>
                            sfsb.Add(sfb => sfb.Header("Customer Count")
                                .Binding("[Measures].[Customer Count]")
                                .DataType(C1.Web.Mvc.Grid.DataType.Number)
                                .DimensionType(DimensionType.Measure))))
                .AddCubeField(fb => fb.Header("Customer")
                    .DimensionType(DimensionType.Dimension)
                    .SubFields(sfsb =>
                    {
                        sfsb.Add(sfb => sfb.Header("Location")
                            .DimensionType(DimensionType.Folder)
                            .SubFields(sfs =>
                            {
                                sfs.Add(f => f.Header("City").Binding("[Customer].[City]").DimensionType(DimensionType.Hierarchy));
                                sfs.Add(f => f.Header("Country").Binding("[Customer].[Country]").DimensionType(DimensionType.Hierarchy));
                                sfs.Add(f => f.Header("Postal Code").Binding("[Customer].[Postal Code]").DimensionType(DimensionType.Hierarchy));
                                sfs.Add(f => f.Header("State-Province").Binding("[Customer].[State-Province]").DimensionType(DimensionType.Hierarchy));
                            }));
                    }))))
            .RowFields(rfb => rfb.Items("[Customer].[Country]", "[Customer].[State-Province]"))
            .ValueFields(vfb => vfb.Items("[Measures].[Internet Order Count]", "[Measures].[Customer Count]"))
@(Html.C1().PivotGrid().Id("pivotGrid").ItemsSourceId("cubeEngine"))
```