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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
dmcguinn
Frequent Visitor

Group if Date/Time of one column within 24 hours of previous row in another column

Hi All,

Apologies if covered elsewhere, I spent a couple days searching...

 

If Stop_Time is within 24 hours of next Start_Time I need the Sum of Production_Value for those rows as an additional column againest the Earliest Start_Time per grouping, could be more than 2 consectutive rows to be grouped in some instances (2 examples in Bold below).

 

Else I need the Production_Value for those (individual) records not resulting in a grouped result.

 

EXAMPLE DATA

Start_Time                         Stop_Time                         Production_Value

2/16/2021 3:20:01 PM2/16/2021 11:00:00 PM460
2/16/2021 11:20:00 PM2/17/2021 7:00:01 AM460
3/2/2021 3:20:01 PM3/2/2021 11:00:00 PM460
3/5/2021 8:50:01 PM3/6/2021 6:00:00 AM550
3/6/2021 8:00:00 AM3/6/2021 11:30:01 AM210
3/17/2021 11:50:01 PM3/18/2021 7:00:01 AM430
3/18/2021 7:50:01 AM3/18/2021 11:50:01 AM240
3/30/2021 7:50:01 AM3/30/2021 3:00:00 PM430
4/14/2021 11:50:01 PM4/15/2021 6:10:00 AM380
4/26/2021 11:50:01 PM4/27/2021 7:00:01 AM430
4/27/2021 7:50:01 AM4/27/2021 10:30:00 AM160
5/6/2021 11:50:01 PM5/7/2021 7:00:01 AM430
5/19/2021 11:50:01 PM5/20/2021 7:00:01 AM430
5/31/2021 11:50:01 PM6/1/2021 7:00:01 AM430
6/1/2021 7:45:01 AM6/1/2021 10:40:00 AM175
6/14/2021 11:50:01 PM6/15/2021 7:00:01 AM430
6/15/2021 7:30:00 AM6/15/2021 9:10:00 AM100
6/21/2021 11:50:01 PM6/22/2021 7:00:01 AM430
6/22/2021 7:50:01 AM6/22/2021 9:35:01 AM105
6/30/2021 11:50:01 PM7/1/2021 6:25:00 AM395
7/5/2021 11:50:01 PM7/6/2021 7:00:01 AM430
7/6/2021 7:50:01 AM7/6/2021 12:05:00 PM255
7/15/2021 11:30:01 PM7/16/2021 4:50:01 AM320
7/26/2021 11:20:00 PM7/27/2021 2:00:00 AM160
7/27/2021 4:20:01 AM7/27/2021 7:00:01 AM160
8/10/2021 11:50:01 PM8/11/2021 7:00:01 AM430
8/17/2021 11:50:01 PM8/18/2021 7:00:01 AM430
8/30/2021 11:50:01 PM8/31/2021 7:00:01 AM430
8/31/2021 7:50:01 AM8/31/2021 3:00:00 PM430
9/7/2021 11:50:01 PM9/8/2021 4:50:01 AM300
9/27/2021 11:50:01 PM9/28/2021 6:20:01 AM390
9/28/2021 7:50:01 AM9/28/2021 11:00:00 AM190
10/6/2021 11:50:01 PM10/7/2021 4:30:00 AM280
10/18/2021 11:50:01 PM10/19/2021 5:00:00 AM310
10/25/2021 8:20:00 PM10/25/2021 11:00:00 PM160
10/25/2021 11:50:01 PM10/26/2021 7:00:01 AM430
10/30/2021 8:20:00 AM10/30/2021 1:30:00 PM310
10/30/2021 3:30:00 PM10/30/2021 5:30:01 PM120
11/4/2021 9:40:01 PM11/4/2021 11:00:00 PM80
11/4/2021 11:30:01 PM11/5/2021 5:40:00 AM370
11/11/2021 11:50:01 PM11/12/2021 7:00:01 AM430
11/12/2021 8:20:00 AM11/12/2021 11:10:01 AM170
11/18/2021 11:50:01 PM11/19/2021 7:00:01 AM430
11/25/2021 11:50:01 PM11/26/2021 6:20:01 AM390
12/1/2021 8:25:00 PM12/1/2021 11:00:00 PM155
12/1/2021 11:50:01 PM12/2/2021 4:20:01 AM270
12/8/2021 11:50:01 PM12/9/2021 7:00:01 AM430
12/15/2021 11:50:01 PM12/16/2021 7:00:01 AM430
12/22/2021 2:30:01 AM12/22/2021 7:00:01 AM270
12/22/2021 7:50:01 AM12/22/2021 8:30:01 AM40
1/21/2022 12:20:01 AM1/21/2022 3:30:00 AM190
1/21/2022 8:20:00 AM1/21/2022 11:00:00 AM160
1/26/2022 11:50:01 PM1/27/2022 7:00:01 AM430
1/27/2022 7:50:01 AM1/27/2022 3:00:00 PM430
1/27/2022 3:50:00 PM1/27/2022 10:40:00 PM410
2/3/2022 11:50:01 PM2/4/2022 4:30:00 AM280
2/10/2022 8:35:01 PM2/10/2022 11:00:00 PM145
2/10/2022 11:30:01 PM2/11/2022 1:20:01 AM110
2/11/2022 3:40:01 AM2/11/2022 5:10:01 AM90
2/17/2022 11:50:01 PM2/18/2022 7:00:01 AM430
2/26/2022 8:20:00 AM2/26/2022 5:30:01 PM550
3/4/2022 8:50:01 PM3/5/2022 7:00:01 AM610
3/10/2022 11:50:01 PM3/11/2022 7:00:01 AM430
3/11/2022 7:30:00 AM3/11/2022 8:40:00 AM70
3/21/2022 11:50:01 PM3/22/2022 7:00:01 AM430
3/26/2022 9:10:00 PM3/27/2022 6:00:00 AM530
4/4/2022 11:50:01 PM4/5/2022 7:00:01 AM430
4/5/2022 7:30:00 AM4/5/2022 12:10:00 PM280

 

Required Result (Manually created from example data)

dmcguinn_0-1649295135728.png

Appreciate any suggestions

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @dmcguinn ;

You could create two column as group coulmn.

Column = 
var _pirstop=CALCULATE(MAX([Stop_Time]),FILTER(ALL('Table'),[Start_Time]<EARLIER([Start_Time])))
return IF([Start_Time]=MIN([Start_Time]),1, IF( DATEDIFF(_pirstop,[Start_Time],HOUR)>24,1))
Group = CALCULATE(SUM([Column]),FILTER('Table',[Start_Time]<=EARLIER([Start_Time])))

Then create a measure.

Value = 
CALCULATE(SUM([Production_Value]),FILTER(ALL('Table'),[Group]=MAX([Group])))

Then apply the column is not blank.

vyalanwumsft_0-1649652586079.png

The final output is shown below:

vyalanwumsft_1-1649652659536.png


Best Regards,
Community Support Team _ Yalan Wu
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
dmcguinn
Frequent Visitor

Thank you so much @v-yalanwu-msft, the solution is perfect!

v-yalanwu-msft
Community Support
Community Support

Hi, @dmcguinn ;

You could create two column as group coulmn.

Column = 
var _pirstop=CALCULATE(MAX([Stop_Time]),FILTER(ALL('Table'),[Start_Time]<EARLIER([Start_Time])))
return IF([Start_Time]=MIN([Start_Time]),1, IF( DATEDIFF(_pirstop,[Start_Time],HOUR)>24,1))
Group = CALCULATE(SUM([Column]),FILTER('Table',[Start_Time]<=EARLIER([Start_Time])))

Then create a measure.

Value = 
CALCULATE(SUM([Production_Value]),FILTER(ALL('Table'),[Group]=MAX([Group])))

Then apply the column is not blank.

vyalanwumsft_0-1649652586079.png

The final output is shown below:

vyalanwumsft_1-1649652659536.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors