通过使用两个不同的行获取datediff [英] Get datediff from using two different rows
问题描述
我有一个数据集,其中包含产品的开/关时间.
即
ON = 1
OFF = 0
I have a dataset that contains on/off times for a product.
i.e.
ON = 1
OFF = 0
DeviceID Event EventDateTime
1 1 12/07/2012 19:00
1 O 12/07/2012 19:10
1 1 12/07/2012 19:15
1 O 12/07/2012 19:45
1 1 12/07/2012 21:00
1 O 12/07/2012 21:15
因此,我想向数据集中添加一个计算字段(DeviceOnTime),以显示ON/OFF周期之间的时间差.因此DeviceOnTime应该看起来像这样,即
Thus i want to add a calculated field (DeviceOnTime) to the dataset to show the difference in time between the ON/OFF periods. Thus DeviceOnTime should look like this i.e
DeviceID Event EventDateTime DeviceOnTime
1 1 12/07/2012 19:00
1 O 12/07/2012 19:10 00:10:00
1 1 12/07/2012 19:15
1 O 12/07/2012 19:45 00:30:00
1 1 12/07/2012 21:00
1 O 12/07/2012 21:15 00:15:00
我的问题是执行此操作所需的表达式,这是香港专业教育学院尝试过的,但由于不喜欢以前的功能而刚得到一个错误
我的表情
= IIF(Fields!EventID.Value = 0,DateDiff("h",Fields!EventDateTime.Value,Previous(Fields!EventDateTime.Value)),什么都没有
这样对吗 ?我可以为计算字段执行此操作吗?
My problem is the expression needed to do this, this what ive tried and a just get an error because it dont like the previous function
My Expression
=IIF(Fields!EventID.Value = 0, DateDiff("h",Fields!EventDateTime.Value, Previous(Fields!EventDateTime.Value)), Nothing)
Is this correct ? can i do this for a calculated field ?
推荐答案
表达式应该可以.我猜想,第一行评估可能会出错(如上一节所述,它什么也不会给出).
试试:
Expression should be ok. I guess, there might be an error for the first row evaluation(as Previous for it will give Nothing).
Try:
=IIF(RowNumber("GroupbyCategory") Mod 2, Nothing, IIF(Fields!EventID.Value = 0, DateDiff("h",Fields!EventDateTime.Value, Previous(Fields!EventDateTime.Value)), Nothing))
它将处理第一行的情况,并为您提供样本中替代行的数据.
It will handle both first row scenario as well give you data for alternate rows as it looks like from your sample.
这篇关于通过使用两个不同的行获取datediff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!