Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
shutr3
New Member

Check if datetime is between a start and end datetime in another table and return the row index

Hello,

I have a table of datetimes and heart rates and another table with activities and start end end datetimes. I am trying to grab all the heart rates between the start and end datetimes. The only relationahip between the table is date and it is many to many since there are multiple activites on some days.

 

I am trying to get the activity index value on all the rows in the heart rate table that fall between an activity start and end and be able to plot heart rate for each activity.

 

I have tried using merge on a modified datetime with out seconds  and then a custom column with this code:

List.DateTimes([Start Date Time], Duration.Minutes ([End Date Time] - [Start Date Time] ), #duration(0,0,1,0) )

but I get error.

I have also tried to generate rows for each minute between start and end and then merge tables but I can't get this to work.

I will try to post sample data, this is my first post here so I'm not sure how to do it. Any help would be greatly appreciated.

Sample data pasted in from csv files. In Power Query I have columns for datetime, date , time in both tables.:

 

indexdatestart timeend timeactivity
112/27/202118:23:5918:42:43Cycling
212/27/202118:43:1719:04:15Run
312/27/202119:05:1519:17:34Metabolic

 

hr date timeHeart rate
2021-12-27 07:13:5858
2021-12-27 07:18:5855
2021-12-27 07:24:5256
2021-12-27 07:28:5255
2021-12-27 07:36:3658
2021-12-27 07:37:4054
2021-12-27 07:41:1652
2021-12-27 07:41:5552
2021-12-27 07:47:2056
2021-12-27 07:52:5857
2021-12-27 07:57:0158
2021-12-27 08:03:0159
2021-12-27 08:08:4458
2021-12-27 08:11:1758
2021-12-27 08:16:1358
2021-12-27 08:17:1858
2021-12-27 08:23:0058
2021-12-27 08:26:5457
2021-12-27 08:33:5660
2021-12-27 08:38:3359
2021-12-27 08:41:1859
2021-12-27 08:42:3355
2021-12-27 08:51:1458
2021-12-27 08:56:0958
2021-12-27 08:57:1957
2021-12-27 09:02:0658
2021-12-27 09:07:4555
2021-12-27 09:16:2856
2021-12-27 09:20:2458
2021-12-27 09:26:0459
2021-12-27 09:27:0759
2021-12-27 09:27:5257.52809
2021-12-27 09:32:1958
2021-12-27 09:37:1959
2021-12-27 09:42:3559
2021-12-27 09:47:1658
2021-12-27 09:52:1152
2021-12-27 09:55:2356
2021-12-27 09:57:4357
2021-12-27 10:06:4656
2021-12-27 10:11:3958
2021-12-27 10:15:3159
2021-12-27 10:17:3258
2021-12-27 10:23:2259
2021-12-27 10:28:0262
2021-12-27 10:34:3054
2021-12-27 10:36:5454
2021-12-27 10:44:0557
2021-12-27 10:51:1863
2021-12-27 10:52:4362
2021-12-27 10:58:4464
2021-12-27 11:02:5364
2021-12-27 11:08:3061
2021-12-27 11:12:5356.47059
2021-12-27 11:14:5958
2021-12-27 11:20:1362
2021-12-27 11:21:5561
2021-12-27 11:27:2659
2021-12-27 11:30:2459
2021-12-27 11:31:5859
2021-12-27 11:40:2059
2021-12-27 11:41:5459
2021-12-27 11:49:5158
2021-12-27 11:52:5758
2021-12-27 11:59:1357
2021-12-27 12:03:3559
2021-12-27 12:07:1859
2021-12-27 12:11:5660
2021-12-27 12:19:5160
2021-12-27 12:22:2260
2021-12-27 12:26:0260
2021-12-27 12:28:1959
2021-12-27 12:31:5659
2021-12-27 12:40:5559
2021-12-27 12:42:1155
2021-12-27 12:49:0363
2021-12-27 12:54:0164
2021-12-27 12:59:3759
2021-12-27 13:01:1255
2021-12-27 13:04:3759
2021-12-27 13:09:4859
2021-12-27 13:11:4665.92274
2021-12-27 13:13:1560
2021-12-27 13:18:1665
2021-12-27 13:22:4865
2021-12-27 13:29:5263
2021-12-27 13:31:5663
2021-12-27 13:37:1364
2021-12-27 13:44:2964
2021-12-27 13:48:2967
2021-12-27 13:54:2164
2021-12-27 13:55:1060
2021-12-27 13:57:0263
2021-12-27 14:03:0967
2021-12-27 14:10:3767
2021-12-27 14:14:2367
2021-12-27 14:17:2766
2021-12-27 14:22:5367
2021-12-27 14:30:0064
2021-12-27 14:33:1864
2021-12-27 14:41:5363
2021-12-27 14:43:1363
2021-12-27 14:48:5066
2021-12-27 14:52:1068
2021-12-27 14:58:1766
2021-12-27 14:58:1967
2021-12-27 15:01:5763
2021-12-27 15:08:2363
2021-12-27 15:11:5763
2021-12-27 15:12:0661.93548
2021-12-27 15:20:2064
2021-12-27 15:23:5067
2021-12-27 15:28:2867
2021-12-27 15:35:2164
2021-12-27 15:38:4164
2021-12-27 15:42:5867
2021-12-27 15:48:5462
2021-12-27 15:52:1064
2021-12-27 15:57:2565
2021-12-27 16:02:0164
2021-12-27 16:06:5566
2021-12-27 16:13:3666
2021-12-27 16:21:0363
2021-12-27 16:25:1165
2021-12-27 16:30:4268
2021-12-27 16:33:1966
2021-12-27 16:37:5666
2021-12-27 16:46:2063
2021-12-27 16:47:5661
2021-12-27 16:55:3161
2021-12-27 16:59:3262
2021-12-27 17:02:5660
2021-12-27 17:06:0261
2021-12-27 17:08:3663
2021-12-27 17:12:4863
2021-12-27 17:18:3560
2021-12-27 17:23:0263
2021-12-27 17:27:1963
2021-12-27 17:36:1265
2021-12-27 17:37:1764
2021-12-27 17:45:3963
2021-12-27 17:51:0565
2021-12-27 17:54:4872
2021-12-27 18:01:5363
2021-12-27 18:03:1364
2021-12-27 18:03:4865
2021-12-27 18:07:2068
2021-12-27 18:12:3091
2021-12-27 18:15:1567
2021-12-27 18:16:5967
2021-12-27 18:23:2789
2021-12-27 18:23:5280
2021-12-27 18:23:5782
2021-12-27 18:24:00137.6603
2021-12-27 18:34:57144.9037
2021-12-27 18:42:48134
2021-12-27 18:42:53133
2021-12-27 18:42:56132
2021-12-27 18:43:01129
2021-12-27 18:43:06126
2021-12-27 18:43:12120
2021-12-27 18:43:16116
2021-12-27 18:43:19158.2616
2021-12-27 19:02:45145.6783
2021-12-27 19:04:18137
2021-12-27 19:04:23136
2021-12-27 19:04:24136
2021-12-27 19:04:31134
2021-12-27 19:04:34135
2021-12-27 19:04:41134
2021-12-27 19:04:44133
2021-12-27 19:04:52129
2021-12-27 19:04:58129
2021-12-27 19:04:59129
2021-12-27 19:05:04130
2021-12-27 19:05:09131
2021-12-27 19:05:15131
2021-12-27 19:05:19135.3284
2021-12-27 19:15:57118.1444
2021-12-27 19:17:43121
2021-12-27 19:17:44122
2021-12-27 19:17:51125
2021-12-27 19:17:58128
2021-12-27 19:18:03129
2021-12-27 19:18:05127
2021-12-27 19:18:12125
2021-12-27 19:18:18128
2021-12-27 19:18:19128
2021-12-27 19:18:24128
2021-12-27 19:18:33126
2021-12-27 19:18:34126
2021-12-27 19:18:43128
2021-12-27 19:18:46131
2021-12-27 19:18:49132
2021-12-27 19:18:58130
2021-12-27 19:19:01130
2021-12-27 19:19:04132
2021-12-27 19:19:11131
2021-12-27 19:19:14131
2021-12-27 19:19:19129
2021-12-27 19:19:24129
2021-12-27 19:19:33129
2021-12-27 19:19:36129
2021-12-27 19:19:39127
2021-12-27 19:19:48122
2021-12-27 19:19:50119
2021-12-27 19:19:54120
2021-12-27 19:19:59124
2021-12-27 19:20:07127
2021-12-27 19:20:13130
2021-12-27 19:20:14130
2021-12-27 19:20:21137
2021-12-27 19:20:24137
2021-12-27 19:20:33138
2021-12-27 19:20:35137
2021-12-27 19:20:43135
2021-12-27 19:20:48133
2021-12-27 19:20:49133
2021-12-27 19:25:40105
2021-12-27 19:28:42100
2021-12-27 19:33:4298
2021-12-27 19:38:5094
2021-12-27 19:41:5999
2021-12-27 19:47:4787.0262
2021-12-27 19:49:1986
2021-12-27 19:55:2885
2021-12-27 19:58:0984
2021-12-27 20:02:1184
2021-12-27 20:47:40121
2021-12-27 21:01:32100
2021-12-27 21:03:0998
2021-12-27 21:09:0880
2021-12-27 21:11:4487.27273
2021-12-27 21:14:3188
2021-12-27 21:19:0584
2021-12-27 21:25:0678
2021-12-27 21:32:26130
2021-12-27 21:36:06100
2021-12-27 21:39:2399
2021-12-27 21:44:26104
2021-12-27 21:48:2399
2021-12-27 21:52:16101
2021-12-27 21:55:33113
2021-12-27 21:59:2978
2021-12-27 22:05:1395
2021-12-27 22:09:1897
2021-12-27 22:13:1791
2021-12-27 22:15:3579
2021-12-27 22:17:2379
2021-12-27 22:23:0078
2021-12-27 22:25:37116
2021-12-27 22:31:1292
2021-12-27 22:33:4086
2021-12-27 22:40:3491
2021-12-27 22:46:3391
2021-12-27 22:50:3584
2021-12-27 22:53:5483
2021-12-27 23:01:4295
2021-12-27 23:04:4184
2021-12-27 23:06:5773
2021-12-27 23:16:3280
2021-12-27 23:17:3477.57576
2021-12-27 23:20:3675
2021-12-27 23:26:1872
2021-12-27 23:27:5573
2021-12-27 23:30:2872
2021-12-27 23:35:5070
2021-12-27 23:37:3069
2021-12-27 23:44:0669
2021-12-27 23:50:1071
2021-12-27 23:52:2071
2021-12-27 23:57:0071
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @shutr3 ,

 

You can use Merge Queries to match date time.

Here's the solution.

1.Extract the date of [hr date time] as the matching column.

vstephenmsft_0-1690525918180.png

2.Merge and expand it.

vstephenmsft_1-1690526628083.png

vstephenmsft_2-1690526955650.png

vstephenmsft_3-1690526989683.png

 

3.Add a custom column to extract the time.

vstephenmsft_4-1690527038467.png

4.Add a custom colummn to return the index rows using IF statement.

vstephenmsft_5-1690527073597.png

5.For display, filter out index rows that are not empty. Below is the result.

vstephenmsft_6-1690527112858.png

 

You can download the attachment for more details.

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

View solution in original post

2 REPLIES 2
shutr3
New Member

Thank you for the help. I guess I was over thinking it.

v-stephen-msft
Community Support
Community Support

Hi @shutr3 ,

 

You can use Merge Queries to match date time.

Here's the solution.

1.Extract the date of [hr date time] as the matching column.

vstephenmsft_0-1690525918180.png

2.Merge and expand it.

vstephenmsft_1-1690526628083.png

vstephenmsft_2-1690526955650.png

vstephenmsft_3-1690526989683.png

 

3.Add a custom column to extract the time.

vstephenmsft_4-1690527038467.png

4.Add a custom colummn to return the index rows using IF statement.

vstephenmsft_5-1690527073597.png

5.For display, filter out index rows that are not empty. Below is the result.

vstephenmsft_6-1690527112858.png

 

You can download the attachment for more details.

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors