以下是引用foxtable_New在2015/6/15 16:31:00的发言:
需要生成表以后重新计算,什么意思,不明白
参考代码
Dim b As New CrossTableBuilder("统计表1",DataTables("订单"))
b.HGroups.AddDef("客户") '添加客户列用于水平分组
b.VGroups.AddDef("产品","产品_{0}") '添加产品列用于垂直分组,并设置了Pattern参数
b.Totals.AddDef("数量") '添加数量列用于统计
b.Filter="客户 Is not null"
b.Build '生成统计表
For Each r As Row In Tables("统计表1").Rows
For Each c As Col In Tables("统计表1").Cols
If c.Name Like "数量*" Then
Dim drs As List(Of DataRow) = DataTables("订单").Select(b.Filter & " and 客户 = '" & r("客户") & "' and 产品 = '" & c.Caption.Replace("产品_","") & "'")
'求平均值
Dim x As Double
For i As Integer = 0 To drs.Count - 1
x = x + drs(i)("数量") / drs.count
Next
'求平方差
Dim s2 As Double
For i As Integer = 0 To drs.Count - 1
s2 = s2 + (drs(i)("数量") - x) ^ 2 / drs.count
Next
Dim s As Double = math.Sqrt(s2)
r(c.Name) = s
End If
Next
Next
MainTable = Tables("统计表1") '打开生成的统计表