以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  统计当月天数,均值  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=107664)

--  作者:13868960029
--  发布时间:2017/10/7 11:05:00
--  统计当月天数,均值
老师好  还是这个项目  我要增加一列统计是当月天数  对应的名称,,应该怎样写呢

1.统计当月天数,
2.提取当月最高值
3.计算当月平均值
4提取当月最高值日期

--  作者:有点甜
--  发布时间:2017/10/7 11:19:00
--  

参考

 

http://www.foxtable.com/webhelp/scr/0158.htm

 


--  作者:有点甜
--  发布时间:2017/10/7 11:19:00
--  

参考

 

http://www.foxtable.com/webhelp/scr/0681.htm

 


--  作者:13868960029
--  发布时间:2017/10/7 16:47:00
--  
Dim dr As DataRow = e.DataRow
Dim
 dt As DataTable =DataTables("电站月读数")
If
 e.DataCol.Name = "名称" And dr.IsNull("名称") = False Then
    dr(
"最高发电量") = dt.Compute("Max(" & dr("名称") & ")")
    dr(
"月均发电量") = dt.Compute("Avg(" & dr("名称") & ")")

End If


这样是否可以统计了,,还过没有确定时间段,我要求统计时段为一个自然月,这个最高和均值都是在,,电站录入表中的  这样行吗

还需要提取当月最高发电量的日期


另外要计算一个月的发电天数怎么写呢
[此贴子已经被作者于2017/10/7 16:52:43编辑过]

--  作者:有点甜
--  发布时间:2017/10/7 16:56:00
--  

加上筛选即可

 

http://www.foxtable.com/webhelp/scr/2720.htm

 

不会做请上传具体例子说明


--  作者:13868960029
--  发布时间:2017/10/7 17:03:00
--  统计当月天数,均值
老师请 帮我写一下 电站月读数的,“
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:居民电站.table

当月发电天数”,“当月最高发电量”,“当月最高发电日期\',"月均发电量”的事件,谢谢
--  作者:有点甜
--  发布时间:2017/10/7 17:13:00
--  

参考代码

 

Select Case e.DataCol.Name
    Case "名称","月期"
        If e.DataRow.IsNull("名称") = False AndAlso e.DataRow.IsNull("月期") = False Then
            Dim d As Date = e.DataRow("月期")
            Dim fd As Date = new Date(d.Year,d.Month,1)
            Dim ld As Date = fd.AddMonths(1)
            Dim filter As String = "名称=\'" & e.DataRow("名称") & "\' and 日期 >= #" & fd & "# and 日期 < #" & ld & "#"
            e.DataRow("月发电量") = DataTables("电站录入").Compute("Sum(日发电)", filter)
            e.DataRow("当月发电天数") = DataTables("电站录入").GetValues("日期", filter).count
            e.DataRow("当月最高发电量") = DataTables("电站录入").Compute("max(日发电)", filter)
            e.DataRow("月均发电量") = e.DataRow("月发电量") / e.DataRow("当月发电天数")
            e.DataRow("当月最高发电日期") = DataTables("电站录入").Compute("max(日期)", filter)
        End If
End Select


--  作者:13868960029
--  发布时间:2017/10/7 18:44:00
--  计算出现偏差
老师  谢谢  

项目中的,,发电总量的显示值比月发电量的值还要小,是怎么回事呢?
图片点击可在新窗口打开查看此主题相关图片如下:11.png
图片点击可在新窗口打开查看

--  作者:13868960029
--  发布时间:2017/10/7 18:50:00
--  命令出现异常
统计 月最高发电   均发电出现异常
图片点击可在新窗口打开查看此主题相关图片如下:12.png
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2017/10/7 20:13:00
--  

参考代码

 

Select Case e.DataCol.Name
    Case "名称","月期"
        If e.DataRow.IsNull("名称") = False AndAlso e.DataRow.IsNull("月期") = False Then
            Dim d As Date = e.DataRow("月期")
            Dim fd As Date = new Date(d.Year,d.Month,1)
            Dim ld As Date = fd.AddMonths(1)
            Dim filter As String = "名称=\'" & e.DataRow("名称") & "\' and 日期 >= #" & fd & "# and 日期 < #" & ld & "#"
            e.DataRow("发电总量") = DataTables("电站录入").Compute("Sum(日发电)","名称=\'" & e.DataRow("名称") & "\'")
            e.DataRow("月发电量") = DataTables("电站录入").Compute("Sum(日发电)", filter)
            e.DataRow("当月发电天数") = DataTables("电站录入").GetValues("日期", filter).count
            e.DataRow("当月最高发电量") = DataTables("电站录入").Compute("max(日发电)", filter)
            If e.DataRow("当月发电天数") > 0 Then
                e.DataRow("月均发电量") = e.DataRow("月发电量") / e.DataRow("当月发电天数")
            End If
            Dim fdr = DataTables("电站录入").find(filter, "日发电 desc")
            If fdr IsNot Nothing Then
                e.DataRow("当月最高发电日期") = fdr("日期")
            Else
                e.DataRow("当月最高发电日期") = Nothing
            End If
        End If
End Select