Forum Discussion

jt024's avatar
jt024
Frequent Visitor
6 years ago
Solved

Create Table based on another table according to criteria

hi there, I'm new to PBI and I'm hoping someone here can help me please.   I have a table coming into PBI with the following structure: Item Date1 Date2 Date3 1 1/1/2020 2/5/2020 3/6/...
  • mahoneypat's avatar
    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