Forum Discussion
prajwalpanji
3 years agoNew Member
Help needed (Urgent)!
Hello everyone, I need help with follwing, Asset |AssetNum | startdatetime | finishdatetime | comment | hours 1410 | LD03 - 3005 | 2023-07...
- Anonymous3 years ago
Hi prajwalpanji
You can try the following code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYxBCsAgDAS/EnLWshsVq+ce+wPx/99oUCjektlhxlBmQoPK+yBJlAQUfw2WImq0W8BeWseSDkxsfAEQ35rOMNRy89tb+YgQwupq3+ZfYZEFjwqRdM4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Asset = _t, AssetNum = _t, startdatetime = _t, finishdatetime = _t, hours = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Asset", Int64.Type}, {"AssetNum", type text}, {"startdatetime", type datetime}, {"finishdatetime", type datetime}, {"hours", Int64.Type}}), #"Inserted Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([startdatetime]), type date), #"Renamed Columns" = Table.RenameColumns(#"Inserted Date",{{"Date", "startDate"}}), #"Inserted Date1" = Table.AddColumn(#"Renamed Columns", "Date", each DateTime.Date([finishdatetime]), type date), #"Renamed Columns1" = Table.RenameColumns(#"Inserted Date1",{{"Date", "engDate"}}), #"Added Custom" = Table.AddColumn(#"Renamed Columns1", "Custom", each List.Dates([startDate], Duration.Days( [engDate]-[startDate])+1,#duration(1, 0, 0, 0) )), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"), #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom.1", each if [Custom]=[startDate] and [Custom]=[engDate] then [finishdatetime]-[startdatetime] else if [Custom]=[startDate] then ([Custom]&#time(24,0,0))-[startdatetime] else if [Custom]=[engDate] then [finishdatetime]-([Custom]&#time(0,0,0)) else null), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if Duration.Days([Custom.1])>=1 or [Custom.1]=null then 24 else Duration.Hours([Custom.1])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"startDate", "engDate", "Custom.1"}), #"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Date"}, {"Custom.2", "Hour_difference"}}) in #"Renamed Columns2"Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
prajwalpanji
3 years agoNew Member
Hi Yolo Zhu, thanks a lot. It does work. However, when the start time is 12:00 AM, it displays 0 hours instead of 24 hours. Please see the attached image.
Anonymous
3 years agoNot applicable
Hi prajwalpanji
You can try the following code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYxBCsAgDAS/EnLWshsVq+ce+wPx/99oUCjektlhxlBmQoPK+yBJlAQUfw2WImq0W8BeWseSDkxsfAEQ35rOMNRy89tb+YgQwupq3+ZfYZEFjwqRdM4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Asset = _t, AssetNum = _t, startdatetime = _t, finishdatetime = _t, hours = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Asset", Int64.Type}, {"AssetNum", type text}, {"startdatetime", type datetime}, {"finishdatetime", type datetime}, {"hours", Int64.Type}}),
#"Inserted Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([startdatetime]), type date),
#"Renamed Columns" = Table.RenameColumns(#"Inserted Date",{{"Date", "startDate"}}),
#"Inserted Date1" = Table.AddColumn(#"Renamed Columns", "Date", each DateTime.Date([finishdatetime]), type date),
#"Renamed Columns1" = Table.RenameColumns(#"Inserted Date1",{{"Date", "engDate"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns1", "Custom", each List.Dates([startDate], Duration.Days( [engDate]-[startDate])+1,#duration(1, 0, 0, 0) )),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom.1", each if [Custom]=[startDate] and [Custom]=[engDate] then [finishdatetime]-[startdatetime] else if [Custom]=[startDate] then
([Custom]&#time(24,0,0))-[startdatetime] else if [Custom]=[engDate] then [finishdatetime]-([Custom]&#time(0,0,0)) else null),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if Duration.Days([Custom.1])>=1 or [Custom.1]=null then 24 else Duration.Hours([Custom.1])),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"startDate", "engDate", "Custom.1"}),
#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Date"}, {"Custom.2", "Hour_difference"}})
in
#"Renamed Columns2"
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.