Forum Discussion
Create Table based on another table according to criteria
- 6 years ago
This is easier to do in query. Below is some example M on how to do it with your data. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below. The modified #"Grouped Rows" step is the one you will need to adapt to your query.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY1BDsAgCAS/YjybIAvaxxj//402GEqNvW3YYXaMzLlkJiZU1CeCmkehvuIsCwPBuxZYsh6r1wDkdfavSGwP9Vhxk5iJNQA+Zx3sJPHtBjXy+i/Sdmn7Zd4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Date1 = _t, Date2 = _t, Date3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", Int64.Type}, {"Date1", type date}, {"Date2", type date}, {"Date3", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Item"}, {{"Date1", each if List.Contains([Date1], null) then null else List.Max([Date1]), type nullable date}, {"Date2", each if List.Contains([Date2], null) then null else List.Max([Date2]), type nullable date}, {"Date3", each if List.Contains([Date3], null) then null else List.Max([Date3]), type nullable date}}) in #"Grouped Rows"If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
jt024 Here is a trick to work around your special rule with empty cells. btw note that in Power Query the cells will be marked as null rather than empty.
1. In Power Query, select the three date columns, and replace all null cells with a date far in the future, for example 9/9/9000.
2. Select the item column, Transform > Group By as follows:
3. Use replace to switch 9/9/9000 back to null.
Here is the final result: