Forum Discussion
How to Split some rows of a table based on hours worked
- 1 year ago
Hi somnath6309,
Thank you for your follow-up and below is the explanation of the query
Step 1 - Added Custom: End DateTime:- DateTime.From: Converts a text string to a DateTime value in Power Query.
- Text. From: Merges the Date and Time fields into one text string, such as "2024-07-01 09:00:00".
- #duration: Adds the number of hours worked to the start time, subtracting 1 second to ensure the end time does not extend into the next day (e.g., ending at 6:00:00 instead of 6:00:01).
Q-2: Purpose of the functions:
- Duration.Days: Calculates the total number of days between the start and end dates.
- DateTime.Date: Extracts only the date component from a datetime value, removing the time.
- Why is "+1" added at the end of the formula?
- This is to make the range inclusive, so both the start and end dates are counted. For instance, if a shift starts and ends on the same day, NumOfDays should be 1.
Q-3: List.Dates
- List.Dates: Generates a list of dates.
- DateTime.Date: start time
Step 4: AddedCustom - 4: Custom
- This column determines the number of hours worked on each specific date within a shift. If the shift occurs within a single day, it returns the total HoursWorked. For shifts spanning multiple days, it allocates hours by calculating the remaining hours on the start date (24 minus the start hour) and, on the end date, adds 1 second to the end time to address rounding before extracting the hour. This approach accurately assigns hours to each relevant date.
If this post helps, then please consider Accept it as a solution to help the other members find it more quickly.
Thank you.
- 1 year ago
Hi somnath6309,
I hope you had a chance to review the solution shared earlier. If it addressed your question, Consider accepting it as the solution it helps others find answers more quickly.
If you're still facing the issue, feel free to reply, and we’ll be happy to assist further.Thank you.
Hi,
Thanks for the help. However, as a new user of Power Query I will not be able to implement these solution. I have studied the attached PBIX file and broke down the steps. It will be very helpful for all if we get the explanation of the following functions :
Step: 1 - Added Custom : EndDateTime
Q-1: The purpose of the functions:
01. DateTime.From
02. Text.From
03. #duration - is the name of the function starts with "#" ? What is the syntax of the function ? within in bracket we find 0, [HoursWorked], 0, -1 and the same is not understood without syntax break up.
Step: 2 - Added Custom2 - Number of Days
Q-2: The Purpose of the functions :
01. Duration.Days
02. DateTime.Date
03. Why "+1" is getting added at the end of the formula ?
Step 3: Added Custom 3 : Dates
Q-3 : List.Dates
What is the purpose of the fuction : List.Dates ? What are its syntax ?
with in the function, DateTime.Date function is used as an argument. Then [NumOfDays], a filed name is used. And lastly #Duration (1,0,0,0) is used.
Pls provide a detailed discussion for the above formula else the same cannot be usable without a proper understanding.
Step 4 : AddedCustom - 4 : Custom
Pls discuss the highlighted formula :
Regards,
Somnath6309
Hi somnath6309,
Thank you for your follow-up and below is the explanation of the query
Step 1 - Added Custom: End DateTime:
- DateTime.From: Converts a text string to a DateTime value in Power Query.
- Text. From: Merges the Date and Time fields into one text string, such as "2024-07-01 09:00:00".
- #duration: Adds the number of hours worked to the start time, subtracting 1 second to ensure the end time does not extend into the next day (e.g., ending at 6:00:00 instead of 6:00:01).
Q-2: Purpose of the functions:
- Duration.Days: Calculates the total number of days between the start and end dates.
- DateTime.Date: Extracts only the date component from a datetime value, removing the time.
- Why is "+1" added at the end of the formula?
- This is to make the range inclusive, so both the start and end dates are counted. For instance, if a shift starts and ends on the same day, NumOfDays should be 1.
Q-3: List.Dates
- List.Dates: Generates a list of dates.
- DateTime.Date: start time
Step 4: AddedCustom - 4: Custom
- This column determines the number of hours worked on each specific date within a shift. If the shift occurs within a single day, it returns the total HoursWorked. For shifts spanning multiple days, it allocates hours by calculating the remaining hours on the start date (24 minus the start hour) and, on the end date, adds 1 second to the end time to address rounding before extracting the hour. This approach accurately assigns hours to each relevant date.
If this post helps, then please consider Accept it as a solution to help the other members find it more quickly.
Thank you.
- somnath63091 year ago
Helper I