I want to generate 24 hour data(by filtering the date column to 24 hours) in KUSTO by adding custom start time and endtime values

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

I want to generate 24 hour data(by filtering the date column to 24 hours) in KUSTO by adding custom start time and endtime values

问题

我有一个表格中的日期和状态数值,我想选择一个为期24小时的日期范围,我想获取所有状态数值,包括开始和结束日期数值。但这些数值不在表格中。必须从以前的记录中获取。

我已经在截图中附上了示例数据,以便更好地理解。

我尝试通过创建一个带有prev()状态值的列来实现,但通过这种方式我无法获取最后一条记录及其状态值。

您能帮助我如何获取开始和结束的自定义日期值吗?

此外,如果在所选时间段内找不到数据,是否可以显示上一条记录?这是可能的吗?

英文:

I want to generate 24 hour data(by filtering the date column to 24 hours) in KUSTO by adding custom start time and endtime values
I have date and status values in a table, i want to select the date range for a period of 24h, I want to get all the status values including starting and ending date values. But those values were not present in the table. It has to get it from previous record.

I have attached the sample data in the screenshot for better understanding.

I have tried by creating a column with prev() staus value and by doing this i am not able to get the last record and its status value.

Can you help how can i get both starting and ending custom date values.

Also for selected time period if there is no data found, it should display the previous record. Is it possible?

答案1

得分: 0

我已使用一些虚拟数据创建了一个表格。UDF(用户定义函数)创建期望 starttime 和 endtime 参数以实现问题中所需的期望结果。

代码/查询

  1. let myFunc = (CustomStartDate: datetime, CustomEndDate: datetime) {
  2. // 创建名为 "tbl" 的临时表
  3. let tbl = datatable(Time: datetime, Status: string)
  4. [
  5. datetime(2023-03-16 07:14:58.4785756), "Running",
  6. datetime(2023-03-16 11:15:49.7803968), "Stopped",
  7. datetime(2023-03-16 13:46:31.8371005), "Idle",
  8. datetime(2023-03-16 21:00:00.0000000), "Stopped",
  9. datetime(2023-03-16 23:00:00.0000000), "Running",
  10. datetime(2023-03-17 05:16:51.9252773), "Stopped",
  11. datetime(2023-03-17 13:16:51.9252773), "Running"
  12. ];
  13. // 选择在起始日期和结束日期之间的记录并创建新的临时表 "tbl1"
  14. let tbl1 = tbl | where Time between (CustomStartDate .. CustomEndDate);
  15. // 创建两个变量来存储在自定义时间范围内的最小和最大时间值,以获取先前和当前的状态
  16. let minDate = tbl1 | summarize min(Time);
  17. let maxDate = tbl1 | summarize max(Time);
  18. let PreStatus = tbl | where Time < toscalar(minDate) | order by Time desc | project Status | take 1;
  19. let CustomEndStatus = tbl1 | where Time == toscalar(maxDate) | project Status;
  20. // 将自定义日期和状态与 tbl1 进行合并,并按时间升序排序表格
  21. tbl1
  22. | union (print Time = CustomStartDate, Status = toscalar(PreStatus))
  23. | union (print Time = CustomEndDate, Status = toscalar(CustomEndStatus))
  24. | order by Time asc
  25. };
  26. myFunc(datetime(2023-03-16 20:00:00.0000000), datetime(2023-03-17 12:00:00.0000000))

结果
I want to generate 24 hour data(by filtering the date column to 24 hours) in KUSTO by adding custom start time and endtime values

英文:

I have used some dummy data to create a table. The UDF created expects starttime and endtime parameters to achieve the desired result asked in question.

Code/Query

  1. let myFunc = (CustomStartDate : datetime ,CustomEndDate : datetime )
  2. {
  3. //Created temporary table named &quot;tbl&quot;
  4. let tbl = datatable(Time: datetime , Status: string )
  5. [
  6. datetime(2023-03-16 07:14:58.4785756), &quot;Running&quot;,
  7. datetime(2023-03-16 11:15:49.7803968), &quot;Stopped&quot;,
  8. datetime(2023-03-16 13:46:31.8371005), &quot;Idle&quot;,
  9. datetime(2023-03-16 21:00:00.0000000),&quot;Stopped&quot;,
  10. datetime(2023-03-16 23:00:00.0000000),&quot;Running&quot;,
  11. datetime(2023-03-17 05:16:51.9252773), &quot;Stopped&quot;,
  12. datetime(2023-03-17 13:16:51.9252773), &quot;Running&quot;
  13. ];
  14. //selecting records which falls between start date and end date and creating new temporary table named &quot;tbl1&quot;
  15. let tbl1 = tbl | where Time between ( CustomStartDate .. CustomEndDate);
  16. //creating 2 variables to store minimum and maximum time values within the custom time provided to get the previous and current status
  17. let minDate = tbl1 | summarize min(Time);
  18. let maxDate = tbl1 | summarize max(Time);
  19. let PreStatus = tbl | where Time &lt; toscalar(minDate)| order by Time desc | project Status | take 1;
  20. let CustomEndStatus = tbl1 | where Time == toscalar(maxDate) |project Status ;
  21. //Union custom dates and status with tbl1 and sorted the table on basis of Time ascending order.
  22. tbl1
  23. | union (print Time = CustomStartDate, Status = toscalar(PreStatus))
  24. | union (print Time = CustomEndDate, Status = toscalar(CustomEndStatus ))
  25. | order by Time asc
  26. };
  27. myFunc(datetime(2023-03-16 20:00:00.0000000),datetime(2023-03-17 12:00:00.0000000))

Result
I want to generate 24 hour data(by filtering the date column to 24 hours) in KUSTO by adding custom start time and endtime values

huangapple
  • 本文由 发表于 2023年3月15日 20:29:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744705.html
匿名

发表评论

匿名网友

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

确定