没看懂你说的 平均库龄 是什么意思,请举例说明。
还有就是你说的最近一次指什么?同一天的都是最近一次?还是说最后一行数据?
如果要引用其它表数据,参考代码
Dim sd As WinForm.DateTimePicker
Dim ed As WinForm.DateTimePicker
sd = e.Form.Controls("StartDate")
ed = e.Form.Controls("EndDate")
If sd.Value Is Nothing OrElse ed.Value Is Nothing Then
MessageBox.Show("请输入起始日期和终止日期!","提示", MessageBoxButtons.OK ,MessageBoxIcon.Information)
Else
'荒料库存情况
Dim g As New GroupTableBuilder("统计表1", DataTables("JKH荒料"))
Dim dt1 As fxDataSource
g.Groups.AddDef("中文品名")
g.Groups.AddDef("级别")
g.Totals.AddDef("荒料编号", AggregateEnum.Count, "荒料_库存_库存数(颗)")
g.Totals.AddDef("计价数量","荒料_库存_库存量")
g.Filter = "[荒料状态] = '在库未出库'"
dt1 = g.BuildDataSource()
'荒料销售
Dim g2 As New GroupTableBuilder("统计表2",DataTables("JKH荒料"))
Dim dt2 As fxDataSource
g2.Filter = "[荒料状态] = '销售出库' And [销售日期] >= '" & sd.Value & "' And [销售日期] <= '" & ed.Value & "'"
g2.Groups.AddDef("中文品名")
g2.Groups.AddDef("级别")
g2.Totals.AddDef("荒料编号", AggregateEnum.Count, "荒料_期间内销售_数(颗)")
g2.Totals.AddDef("计价数量","荒料_期间内销售_数量")
dt2 = g2.BuildDataSource()
Dim nms2 As String() = {"中文品名","级别"} '指定连接列
dt1.Combine(nms2,dt2,nms2)
Tables("荒料库存及去化报表-投管用_Table1").DataSource = dt1
Dim t As Table = Tables("荒料库存及去化报表-投管用_Table1")
t.DataTable.DataCols.Add("最近一次销售日期", Gettype(Date))
t.DataTable.DataCols.Add("最近一次销售量", Gettype(Double))
t.DataTable.DataCols.Add("最近一次销售金额", Gettype(Double))
For Each r As Row In t.Rows
Dim fdr As DataRow = DataTables("JKH荒料").find("中文品名 = '" & r("中文品名") & "' and 级别 = '" & r("级别") & "'", "销售日期 desc")
If fdr IsNot Nothing Then
r("最近一次销售日期") = fdr("销售日期")
r("最近一次销售量") = fdr("计价数量")
r("最近一次销售金额") = fdr("销售金额")
End If
Next
End If