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

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

Reply
Winata_Saputra
Frequent Visitor

How To Create a Start Time and Finish Time Based on Out Time and Index Using Power Query

Hello everyone. I've been trying to find a solution to my timing issue, but still not getting the expected results. Let me explain.

I have 3 important columns (INDEX, PRODDATE, MACHINE) and 1 reference column which is OUTTIME.

There are only 2 conditions:

  • If PRODDATE and MACHINE are the same, which has INDEX starting at 1, then STARTPRODTIME, starting at 07:00 and FINISHPRODTIME ending the next day at 07:00 (like the desired column in picture).
  • If PRODDATE and MACHINE are the same, but have INDEX of more than 1, then STARTPRODTIME and FINISIHPRODTIME refer to the OUTIME column (like the desired column in picture).

Is this possible?

Please see my picture for better understanding.

Desired ResultDesired Result

 Thankyou!

1 ACCEPTED SOLUTION
slorin
Super User
Super User

Hi

 

Table.Combine(
Table.Group(
#"Previous Step",
{"INDEX"},
{{"Data", each Table.FromColumns(
Table.ToColumns(_) &
{{[PRODDATE]{0} & #time(7,0,0)} & List.RemoveLastN([OUTTIME],1)} &
{List.RemoveLastN([OUTTIME],1) & {Date.AddDays([PRODDATE]{0},1) & #time(7,0,0)}},
Table.ColumnNames(_) & {"STARTPRODTIME","FINISHPRODTIME"})
}},
GroupKind.Local,
(x,y) => if y[INDEX]=1 then 1 else 0)
[Data])

 

Stéphane

View solution in original post

2 REPLIES 2
slorin
Super User
Super User

Hi

 

Table.Combine(
Table.Group(
#"Previous Step",
{"INDEX"},
{{"Data", each Table.FromColumns(
Table.ToColumns(_) &
{{[PRODDATE]{0} & #time(7,0,0)} & List.RemoveLastN([OUTTIME],1)} &
{List.RemoveLastN([OUTTIME],1) & {Date.AddDays([PRODDATE]{0},1) & #time(7,0,0)}},
Table.ColumnNames(_) & {"STARTPRODTIME","FINISHPRODTIME"})
}},
GroupKind.Local,
(x,y) => if y[INDEX]=1 then 1 else 0)
[Data])

 

Stéphane

It works. Terima kasih for your help 😁🇮🇩

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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 Kudoed Authors