|
Many users working with calculated fields like to have their calculated field totals use the calculated fields formula. The code below demonstrates how to approach setting the GroupFooterType and the GroupFooterExpression for your Row and Column fields so you can use the same calculation as the one used for your calculated field.
Option Explicit
...
Private Sub DCube1_FetchData()
Dim i As Long
' Sample data.
For i = 1 To 5
DCube1.AddRowEx Array("RowData1", "ColData1", i + i, i * 10)
DCube1.AddRowEx Array("RowData3", "ColData1", i + 2, i)
Next i
End Sub
Private Sub Form_Load()
Dim f As DynamiCubeLibCtl.Field
With DCube1
.AutoDataRefresh = False
.DCConnectType = DCCT_UNBOUND
' Set up DCube.
Set f = .Fields.Add("Row", "Row", DCRow)
' Set the RowFields GroupFooterType and the Expression used for the calculated field totals.
' Notice the use of the calculated field VarName for referencing the specific DataField
' to modify the Rows GroupFooterType and the Expression.
f.GroupFooterType("MyCalcField") = DCFCalculated
f.GroupFooterExpression("MyCalcField") = "groupsum(d1) * groupsum(d2)"
Set f = .Fields.Add("Data1", "Data1", DCData)
f.VarName = "d1"
Set f = .Fields.Add("Data2", "Data2", DCData)
f.VarName = "d2"
' Set the ColumnFields, GroupFooterType, and the Expression used for the calculated field totals.
' Notice the use of the calculated field VarName for referencing the specific DataField
' to modify the Columns, GroupFooterType, and the Expression.
f.GroupFooterType("MyCalcField") = DCFCalculated
f.GroupFooterExpression("MyCalcField") = "groupsum(d1) * groupsum(d2)"
Set f = .Fields.Add("Data1", "Data1", DCData)
f.VarName = "d1"
Set f = .Fields.Add("Data2", "Data2", DCData)
f.VarName = "d2"
' Create the calculated field.
Set f = .Fields.Add("d1 * d2", "CalcField", DCData)
f.Calculated = True
f.VarName = "MyCalcField"
.RefreshData
.AutoDataRefresh = True
End With
End Sub
Note: If the user does not specify a GroupFooterType, the default setting for a calculated field is sum. If a field is not calculated and a GroupFooterType is not specified, the GroupFooterType is based on the fields AggregateFunc by default.
The attached sample demonstrates the use of the code above to create calculated row and column totals for the calculated field. The links below contain additional information about the use of the GroupFooterType and GroupFooterExpression properties.
GroupFooterType
http: //www.datadynamics.com/Help/DynamiCube3/DynamiCubeLib~Field~GroupFooterType.html
GroupFooterExpression
http://www. datadynamics.com/Help/DynamiCube3/DynamiCubeLib~Field~GroupFooterExpression.html
Applies To: DynamiCube 3.0
|