以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]不确定列名的计算 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=141374) |
-- 作者:lgj716330 -- 发布时间:2019/9/27 17:43:00 -- [求助]不确定列名的计算 Dim b As New GroupTableBuilder("统计表","表1") Dim dt As fxDataSource b.Groups.AddDef("部门名称") b.Totals.AddDef("金额","销售金额") dt = b.BuildDataSource() Dim b1 As New SQLCrossTableBuilder("统计表1","表2") Dim dt1 As fxDataSource b1.HGroups.AddDef("部门名称") b1.VGroups.AddDef("成本大类")‘此处的成本大类名称可能会随时调整, b1.Totals.AddDef("金额") dt1 = b1.BuildDataSource() 上面“表2”的成本大类的名称可能会随时改变,导致交叉统计的列名称和列数都不固定,我需要计算b1各个成本大类占b中的销售的比率,由于列名称和列数不固定,用下面这种方法好象也处理不了,有没有其他办法解决呢 Dim dic As new Dictionary(of String, String) For Each c As Col In Tables("汇总表_Table1").cols dic.add(c.Caption, c.name) Next If dic.ContainsKey("销售金额") = False Then DataTables("汇总表_Table1").dataCols.add("销售金额", Gettype(Double)) dic.add("销售金额", "销售金额") End If |
-- 作者:lgj716330 -- 发布时间:2019/9/27 19:39:00 -- 知道怎么解决了 以交叉统计的形式,统计每个客户订购不同产品的数量和金额: Dim dtb As New DataTableBuilder("统计") [此贴子已经被作者于2019/9/27 19:47:55编辑过]
|
-- 作者:lgj716330 -- 发布时间:2019/9/28 10:28:00 -- Dim r1 As Row For i As Integer = 0 To t1.Rows.Count(True) - 1 r1 = t1.Rows(i,True) For Each prd As String In prds Dim xs As Double = DataTables("费用构成情况_Table1").Compute("Sum(销售金额)","部门名称 = \'" & r1("部门名称") & "\' And " & HZ3 & " = \'" & prd & "\'") If r1.IsGroup And xs <> 0 Then r1(prd & "_销售占比") = DataTables("费用构成情况_Table1").Compute("Sum(费用金额)","部门名称 = \'" & r1("部门名称") & "\' And " & HZ3 & " = \'" & prd & "\'")/DataTables("费用构成情况_Table1").Compute("Sum(销售金额)","部门名称 = \'" & r1("部门名称") & "\' And " & HZ3 & " = \'" & prd & "\'") ElseIf r1.IsGroup And xs = 0 Then r1(prd & "_销售占比") =0 End If Next Next 上面标红部分,汇总行的计算代码不对,应该怎么调整
[此贴子已经被作者于2019/9/28 13:30:40编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/9/28 10:42:00 -- For i As Integer = 0 To t1.Rows.Count(True) - 1 r1 = t1.Rows(i,True) msgbo(r1("部门名称"))这里显示什么内容?汇总后部门名称列的数据是怎么样的?截图看看
|
-- 作者:lgj716330 -- 发布时间:2019/9/28 11:11:00 -- 不知咋回事,上传不了图,根据提示,汇总行计算中," & HZ3 & " = \'" & prd & "\'这里不对,提示未找到列
|
-- 作者:有点蓝 -- 发布时间:2019/9/28 11:21:00 -- msgbox("部门名称 = \'" & r1("部门名称") & "\' And " & HZ3 & " = \'" & prd & "\'") 显示什么内容?
|
-- 作者:lgj716330 -- 发布时间:2019/9/28 12:21:00 -- [此贴子已经被作者于2019/9/28 13:27:28编辑过]
|
-- 作者:lgj716330 -- 发布时间:2019/9/28 12:34:00 -- 唉,解决了,是自己想多了 Dim r1 As Row For i As Integer = 0 To t1.Rows.Count(True) - 1 r1 = t1.Rows(i,True) For Each prd As String In prds If r1.IsGroup Then If r1("销售金额") <> 0 Then r1(prd & "_销售占比") = r1(prd & "_费用金额")/r1("销售金额") ElseIf r1("销售金额") = 0 Then r1(prd & "_销售占比") =0 End If End If Next Next [此贴子已经被作者于2019/9/28 13:27:04编辑过]
|