Forum Discussion
Grouping Date sets within a month
- 5 years ago
Hello johnlhaase
check out this solution. I hope I got you right. The group-function with GroupKind.Local does the trick here
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdOxDYMwGEThXVwj2b7f4KTNAhkAsQL7l1iCQ1TJkyy78Nc93bqmmmtWUUlTij6P+9NbG88499c2/XGCLqBr0M3QLdB16F7QvaGrhUJQ5LufFEQxBV1MQRpTUMcUBDIFjUxBJlNQ6qICrUx5LfFa4rXEa4nXEq8luijRSYluKnineHTSL6rMpbAMLJ1zOwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start of Month" = _t, EmpID = _t, Fleet = _t, OnOff = _t, #"Rotation Date" = _t]), TransformDate = Table.TransformColumns(Source,{{"Rotation Date", each Date.From(_,"en-US"), type date},{"Start of Month", each Date.From(_,"en-US"), type date}}), Group = Table.Group(TransformDate, {"EmpID", "OnOff"}, {{"AllRows", each _, type table [Start of Month=date, EmpID=text, Fleet=text, OnOff=text, Rotation Date=date]}}, GroupKind.Local), AddMin = Table.AddColumn(Group, "Min", each List.Min([AllRows][Rotation Date]), type date), AddMax = Table.AddColumn(AddMin, "Max", each List.Max([AllRows][Rotation Date]), type date), ExpandGroupedTable = Table.ExpandTableColumn(AddMax, "AllRows", {"Start of Month", "Fleet", "Rotation Date"}, {"Start of Month", "Fleet", "Rotation Date"}) in ExpandGroupedTableCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy - 5 years ago
Hello
You are correct. I did ask about the same month. This is a large data set and when I was going through the restlts I realized some of the On/Off days transition into the following month.
The first solution is fantasitic and is very useful. I wish I realized the data set had the transition issue priro to my first post. The law of unintended consequences. Anyways I am trying to get the scripts to ignore the start of month all together and just get the min/max for each On/Off sets.
Thanks for your time
John
Hello
Looks good. The only thing I cannot follow is the firat part with Compress and Deflate with all the letters in between. What does that do for the script?
Thanks again
John
Hello johnlhaase
this is to reproduce your dataset. You have to replace it with your datasource, or with the query already in place
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
- johnlhaase5 years agoHelper I
Thank you I will check it out!