Forum Discussion
adding row
- 1 year ago
Hi wsindharta,
Thank you for reaching out to the Microsoft fabric community forum. Thank you SundarRaj, ZhangKun, BeaBF, for your inputs on this issue.
After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.
M Query:let // Sample source table Source = Table.FromRows({ {"A123789", "06181819", "0120", "23/01/2022", #datetime(2025, 5, 2, 20, 25, 0), #datetime(2025, 5, 5, 8, 45, 35)} }, {"WorkCenter", "WorkOrder", "Operation", "ProductName", "StartTime", "EndTime"}), // Add duration in seconds AddDuration = Table.AddColumn(Source, "DurationSec", each Duration.TotalSeconds([EndTime] - [StartTime]), type number), // Generate list of dates for each row AddDateList = Table.AddColumn(AddDuration, "DateList", each List.Dates( Date.From([StartTime]), Duration.Days([EndTime] - [StartTime]) + 1, #duration(1, 0, 0, 0) )), // Expand date list into rows ExpandedDates = Table.ExpandListColumn(AddDateList, "DateList"), // Add start and end time for each day AddDayTimes = Table.AddColumn(ExpandedDates, "Start_End", each let currentDate = [DateList], startTime = if Date.From([StartTime]) = currentDate then [StartTime] else #datetime(Date.Year(currentDate), Date.Month(currentDate), Date.Day(currentDate), 0, 0, 0), endTime = if Date.From([EndTime]) = currentDate then [EndTime] else #datetime(Date.Year(currentDate), Date.Month(currentDate), Date.Day(currentDate), 23, 59, 59) in [StartTime = startTime, EndTime = endTime] ), // Expand start/end time record RemoveOriginalTimes = Table.RemoveColumns(AddDayTimes, {"StartTime", "EndTime"}), ExpandedTimes = Table.ExpandRecordColumn(RemoveOriginalTimes, "Start_End", {"StartTime", "EndTime"}), // Recalculate duration RecalcDuration = Table.AddColumn(ExpandedTimes, "Duration", each Duration.TotalSeconds([EndTime] - [StartTime]), type number), // Add date column Final = Table.RenameColumns(Table.SelectColumns(RecalcDuration, {"WorkCenter", "WorkOrder", "Operation", "ProductName", "StartTime", "EndTime", "Duration", "DateList"}), {"DateList", "Date"}) in Final
Output: Go to the table view see this output:
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.
Hi wsindharta , here's another solution you could look at. I'll attach the images and the code. I'll attach the file for your reference. Let me if I cleared your query. Thanks!
https://docs.google.com/spreadsheets/d/1V_HewD8xOXVC_mFRx5DLRG6Rp4_Zca9B/edit?usp=sharing&ouid=104752674875039603034&rtpof=true&sd=true
- wsindharta1 year agoHelper I
Hi SundarRaj thank you for reply, but i don't see the attached file, the link is goes to my original file. please advise
- SundarRaj1 year agoSuper User
Hi wsindharta , this should give you the downloadable excel file. Launch the Power Query Editor and you shall see the table there. Thanks. Let me know if it is resolved.
https://docs.google.com/spreadsheets/d/1mRs_F6QpJj4w2obI0i_RB-aEx90XwN6s/export?format=xlsx&ouid=104752674875039603034&rtpof=true&sd=true