如何计算两个不规则间隔的事件的时间戳。

huangapple go评论66阅读模式
英文:

how to calculate timestamp of 2 events which are irregularly spaced apart

问题

如何计算两个不规则间隔的事件的时间戳。

所以我有一个事件日志,我想知道当a为真时和b为假时经过的时间,然后将计算时间戳差。我想知道如何搜索最近的以前a为真并参考该时间戳以减去b为假的时间戳。在这两者之间可能会有不规则数量的事件项。

作为额外要求,我需要验证事件的顺序:
a=true -> b=true -> a=false -> b=false

我尝试使用if语句来确认我何时有一个b是假的,但不知道如何向上搜索并参考最后一个以前的a为真。

另外,我不知道如何验证这4个事件的特定顺序。

英文:

如何计算两个不规则间隔的事件的时间戳。

So I have an event log in which I would like to know the time elapsed between when a is true, and when b is false. then the timestamp difference will be calculated. I would like to know how to search the nearest previous a is true and refer to that timestamp to subtract with the b is a false timestamp. There may be an irregular number of event items in between.

as an extra requirement, I need to verify that the events are in the order:
a=true -> b=true -> a=false -> b=false

I have tried to use if statement to confirm where i have a b is false, but don't know how to search up and refer to the last previous a is true.

also, I have no clue how to verify the sequence of 4 events in a certain order.

答案1

得分: 0

你可以创建一个支持列来帮助公式识别。

=C2&D2

然后主要公式如下:

=if((C2&D2)="dFALSE",(B2-ARRAYFORMULA(MAX(IF($A$2:A2="aTRUE",$B$2:B2))))*1440,"")

但请注意,只有在您的数据是按时间顺序排列时才能使用此方法。

这是我在Google表格中创建的示例文件。

https://docs.google.com/spreadsheets/d/138tULefCoMdMHsOYIudugOssworU3wtzh1f7lEWelWs/edit#gid=0

如果您需要在Excel上使用它,可能需要替换arrayformula()。

英文:

You could create a supportive column to help the formula identify.

=C2&D2

And then the main formula would be:

=if((C2&D2)="dFALSE",(B2-ARRAYFORMULA(MAX(IF($A$2:A2="aTRUE",$B$2:B2))))*1440,"")

But please be notified that this method can only be used when your data is time-sequenced.

Here is the example file I created in Google Sheet.

https://docs.google.com/spreadsheets/d/138tULefCoMdMHsOYIudugOssworU3wtzh1f7lEWelWs/edit#gid=0

If you need to use it on Excel, you may need to replace the arrayformula().

huangapple
  • 本文由 发表于 2023年7月3日 17:10:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定