以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求动态分组统计 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=74010) |
||||
-- 作者:青岛hhh -- 发布时间:2015/8/31 14:58:00 -- 求动态分组统计 已有统计汇总:
固定3个分组统计:大于0占比,大于100占比,大于1000占比
Dim tbs() As String = { "表1", "表2"} Dim cs1() As String = { "指标1", "指标2", "指标3"} Dim cs2() As String = { "指标A", "指标B", "指标C","指标D" } Dim ls As new List(Of String()) ls.Add(cs1) ls.add(cs2) DataTables( "分组统计").DataRows.Clear For i As Integer = 0 To tbs.Length - 1 Dim cs As String() = ls(i) For j As Integer = 0 To cs.Length - 1 Dim fdr = DataTables("分组统计").AddNew fdr("指标") = cs(j) fdr("条件") = Tables(tbs(i)).Cols(cs(j)).Caption Dim All As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")") Dim c0 As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")", cs(j) & " >= 1") Dim c100 As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")", cs(j) & " >= 100") Dim c1000 As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")", cs(j) & " >= 1000") fdr("大于0占比") = c0 / All *100 fdr("大于100占比") = c100 / All *100 fdr("大于1000占比") = c1000 / All *100 Next Next 想改成动态分组统计: 1,由窗口收入动态分组数N 2,判断个统计列最高值,最低值,并平均分成N组 3,生成动态列名"1","2","3"------"N",计算各列数据(各统计指标数据在各数据段所占比例)
|
||||
-- 作者:大红袍 -- 发布时间:2015/8/31 15:01:00 -- 上传项目。 |
||||
-- 作者:青岛hhh -- 发布时间:2015/9/1 10:49:00 --
1,在"分组统计"表汇总统计"表1“,"表2"各指标列数据分布 2,在"分组统计"表建工作窗口输入:分组起始值,分组宽度,分组组数 3,"分组统计"表第一例"列名"汇总"表1“,"表2"各列列名,第二例"标题"汇总"表1“,"表2"各列标题 4,"分组统计"表第三例到N列为分组组数列,汇总统计"表1“,"表2"指标列各分组段数据所占比重 例如:在"分组统计"表窗口输入:分组起始值0,分组宽度100,分组组数10,"分组统计"表第三例生成列名为"0-100",统计大于0小于100区间数据所占比重,最后一列列名为"900-1000",统计大于,900小于1000区间数据所占比重, [此贴子已经被作者于2015/9/1 10:51:27编辑过]
|
||||
-- 作者:大红袍 -- 发布时间:2015/9/1 13:12:00 -- Dim tbs() As String = { "表1", "表2"} Dim cs1() As String = { "指标1", "指标2"} Dim cs2() As String = { "指标A", "指标B", "指标C"} Dim snum As Integer = 0 Dim ls As new List(Of String()) ls.Add(cs1) ls.add(cs2) Dim dtb As New DataTableBuilder("统计") For i As Integer = 0 To tbs.Length - 1 MainTable = Tables("统计") |
||||
-- 作者:青岛hhh -- 发布时间:2015/9/1 14:08:00 -- Dim snum As Integer = 0
这三个数值不是固定的需要从窗口动态输入 |
||||
-- 作者:大红袍 -- 发布时间:2015/9/1 14:29:00 -- 呃,要学会变通。直接赋值
Dim snum As Integer = Forms("窗口1").Controls("TexBox1").Text |
||||
-- 作者:青岛hhh -- 发布时间:2015/9/4 14:35:00 -- 项目已上传请老师帮我看看: “分组统计表”窗口输入起始值0,宽度100,组数10后点击计算只有“列名”,“标题”两列,没有显示数据列 应该是: 列名 标题 0-100 100-200 ------900-1000 指标1 Z1 --- --- --- 指标2 Z2 --- --- --- --- --- --- --- --- 还请老师帮我看看
|
||||
-- 作者:大红袍 -- 发布时间:2015/9/4 14:57:00 -- 请参考4楼代码,只要赋值成功,就没问题
Dim snum As Integer = Forms("窗口1").Controls("TexBox1").Text |
||||
-- 作者:青岛hhh -- 发布时间:2015/9/4 15:19:00 -- Dim tbs() As String = { "表1", "表2"} Dim cs1() As String = { "指标1", "指标2"} Dim cs2() As String = { "指标A", "指标B", "指标C"} Dim snum As Integer = Forms("窗口1").Controls("TextBox1").Text Dim slen As Integer = Forms("窗口1").Controls("TextBox2").Text Dim scount As Integer = Forms("窗口1").Controls("TextBox3").Text Dim ls As new List(Of String()) ls.Add(cs1) ls.add(cs2) DataTables( "分组统计").DataRows.Clear Dim dtb As New DataTableBuilder("分组统计") dtb.AddDef("列名", Gettype(String), 32) dtb.AddDef("标题", Gettype(String), 32) For i As Integer = 1 To scount dtb.AddDef("临时列" & i, Gettype(Double), "", snum+slen*(i-1) & "-" & snum+slen*i) Next dtb.Build() For i As Integer = 0 To tbs.Length - 1 Dim cs As String() = ls(i) For j As Integer = 0 To cs.Length - 1 Dim fdr = DataTables("分组统计").AddNew fdr("列名") = cs(j) fdr("标题") = Tables(tbs(i)).Cols(cs(j)).Caption Dim All As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")", cs(j) & " is not null") For Each dc As DataCol In DataTables("分组统计").datacols If dc.Name Like "临时列*" Then Dim ary() As String = dc.Caption.Split("-") Dim c As Double = Tables(tbs(i)).Compute("count(" & cs(j) & ")", cs(j) & " >= " & ary(0) & " and " & cs(j) & " < " & ary(1) & " and " & cs(j) & " is not null") fdr(dc.name) = c / All *100 End If Next Next Next
|
||||
-- 作者:大红袍 -- 发布时间:2015/9/4 15:35:00 --
|