以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  交叉统计如何自动汇总出平均值?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=12428)

--  作者:bad
--  发布时间:2011/9/2 13:57:00
--  交叉统计如何自动汇总出平均值?


图片点击可在新窗口打开查看此主题相关图片如下:未命名.jpg
图片点击可在新窗口打开查看

 

上述表是自动通过下面公式计算出来的。

想让小计、总计行是平均值而不是累计值,如何改公式?

 

Dim g As New CrossTableBuilder("统计汇总", DataTables("绩效计划表"))
g.Caption = "统计汇总"
g.HGroups.AddDef("年度")
g.HGroups.AddDef("季度")
g.VGroups.AddDef("分管领导")
g.Totals.AddDef("权重", "权重")
g.Totals.AddDef("实际得分", "实际得分")
g.Decimals = 2
g.Subtotal = True
g.Build()
MainTable = Tables("统计汇总")


--  作者:狐狸爸爸
--  发布时间:2011/9/2 14:15:00
--  
Dim g As New CrossTableBuilder("统计汇总", DataTables("绩效计划表"))
g.Caption = "统计汇总"
g.HGroups.AddDef("年度")
g.HGroups.AddDef("季度")
g.VGroups.AddDef("分管领导")
g.Totals.AddDef("权重", AggregateEnum.Average)
g.Totals.AddDef("实际得分",AggregateEnum.Average)
g.Decimals = 2
g.Subtotal = True
g.Build()
MainTable = Tables("统计汇总")
[此贴子已经被作者于2011-9-2 14:15:39编辑过]

--  作者:紙上不談兵
--  发布时间:2011/9/2 15:06:00
--  
楼主只要汇总行取平均值,这样不对吧?应该先交叉后汇总

--  作者:紙上不談兵
--  发布时间:2011/9/2 17:19:00
--  
Dim s As String
Dim t As Table = Tables("统计汇总")

Dim g As New CrossTableBuilder("统计汇总", DataTables("绩效计划表"))
g.Caption = "统计汇总"
g.HGroups.AddDef("年度")
g.HGroups.AddDef("季度")
g.VGroups.AddDef("分管领导")
g.Totals.AddDef("权重", "权重")
g.Totals.AddDef("实际得分", "实际得分")
g.Decimals = 2
g.Build()

For Each c As col In t.cols
   If c.name <> "年度" AndAlso c.name <> "季度" Then
      s+ = "," &  c.name
  End If
Next

Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Average
g.GroupOn = "年度"
g.TotalOn = s.trim(",")
g.Caption = "{0}年 平均"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Average
g.GroupOn = "*"
g.TotalOn =s.trim(",")
g.Caption = "总平均"
t.SubtotalGroups.Add(g)
t.Subtotal()
MainTable = t
[此贴子已经被作者于2011-9-2 17:24:25编辑过]

--  作者:bad
--  发布时间:2011/9/3 23:39:00
--  


图片点击可在新窗口打开查看此主题相关图片如下:afd.jpg
图片点击可在新窗口打开查看

上面的公式复制到代码编辑器,点确定后发生上述错误


--  作者:don
--  发布时间:2011/9/3 23:43:00
--  
以下是引用bad在2011-9-3 23:39:00的发言:


图片点击可在新窗口打开查看此主题相关图片如下:afd.jpg
图片点击可在新窗口打开查看

上面的公式复制到代码编辑器,点确定后发生上述错误



这是你纸上谈兵的结果!正确的:


Dim s As String
Dim t As Table = Tables("统计汇总")

Dim g As New CrossTableBuilder("统计汇总", DataTables("绩效计划表"))
g.Caption = "统计汇总"
g.HGroups.AddDef("年度")
g.HGroups.AddDef("季度")
g.VGroups.AddDef("分管领导")
g.Totals.AddDef("权重", "权重")
g.Totals.AddDef("实际得分", "实际得分")
g.Decimals = 2
g.Build()

For Each c As col In t.cols
   If c.name <> "年度" AndAlso c.name <> "季度" Then
      s+ = "," &  c.name
  End If
Next

Dim g1 As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True

g1 = New Subtotalgroup
g1.Aggregate = AggregateEnum.Average
g1.GroupOn = "年度"
g1.TotalOn = s.trim(",")
g1.Caption = "{0}年 平均"
t.SubtotalGroups.Add(g1)

g1 = New Subtotalgroup
g1.Aggregate = AggregateEnum.Average
g1.GroupOn = "*"
g1.TotalOn =s.trim(",")
g.Caption = "总平均"
t.SubtotalGroups.Add(g1)
t.Subtotal()
MainTable = t


--  作者:czy
--  发布时间:2011/9/3 23:43:00
--  

Dim g As Subtotalgroup

将上面一行代码中的g改成g1

然后将下面代码中涉及g的都改成就g1

如:

g1 = New Subtotalgroup