Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

create destination from single departure list

hello, I need help to model my data in PBI desktop. below, is my raw data:   code date time description category 1 22/05/2018 08:22:40 a c 1 22/05/2018 18:11:50 b d 2 23/05/2...
  • Anonymous's avatar
    Anonymous
    8 years ago

    thanks a lot for your help Phil_Seamark!

    I managed to get the final table that I need.
    I started with your final table, then I duplicated the full query into another new table.

    After that, I made 2 filters, one on each table, and then I appended them together and removed duplicate rows.

    One filter is to remove blank dates from one table. The other filter is to remove duplicates from the new column code+date (only date without time).

    Bad thing is, I doubled the data to perform the 2 filters. but I got what I wanted!

     

     

    Table1

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc1LDoAgDATQqxjWJtACQnoV44Lv/Y9gi0ZNZNEupi/TfVegVoWojddoIC6REDlJPEUd6+8OkUCizFMHEI72AYGskwJpqFMBgbxEWTpamxFEMhKVwqv3QawQ9/njrj9pVOXX+K/ZLnMjVscJ", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [code = _t, #"date time" = _t, description = _t, category = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"code", Int64.Type}, {"date time", type datetime}, {"description", type text}, {"category", type text}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type",{{"date time", Order.Ascending}}),
        #"Inserted Date" = Table.AddColumn(#"Sorted Rows", "Date", each DateTime.Date([date time]), type date),
        #"Added Index" = Table.AddIndexColumn(#"Inserted Date", "Index", 0, 1),
        #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1),
        #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Date", "Index.1", "code"},#"Added Index1",{"Date", "Index", "code"},"Added Index1",JoinKind.LeftOuter),
        #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"code", "date time", "description", "category", "Date", "Index", "Index.1"}, {"code.1", "date time.1", "description.1", "category.1", "Date.1", "Index.2", "Index.1.1"}),
        #"Removed Other Columns" = Table.SelectColumns(#"Expanded Added Index1",{"code", "date time", "description", "category", "Date", "date time.1", "description.1", "category.1"}),
        #"Rows Filtered" = Table.SelectRows(#"Removed Other Columns", each ([date time.1] <> null)),
        #"Append queries" = Table.Combine({#"Rows Filtered", #"Table1 (2)"}),
        #"Remove column" = Table.RemoveColumns(#"Append queries",{"Date"}),
        #"Remove duplicates" = Table.Distinct(#"Remove column")
    in
        #"Remove duplicates"

    Table1 (2)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc1LDoAgDATQqxjWJtACQnoV44Lv/Y9gi0ZNZNEupi/TfVegVoWojddoIC6REDlJPEUd6+8OkUCizFMHEI72AYGskwJpqFMBgbxEWTpamxFEMhKVwqv3QawQ9/njrj9pVOXX+K/ZLnMjVscJ", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [code = _t, #"date time" = _t, description = _t, category = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"code", Int64.Type}, {"date time", type datetime}, {"description", type text}, {"category", type text}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type",{{"date time", Order.Ascending}}),
        #"Inserted Date" = Table.AddColumn(#"Sorted Rows", "Date", each DateTime.Date([date time]), type date),
        #"Added Index" = Table.AddIndexColumn(#"Inserted Date", "Index", 0, 1),
        #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1),
        #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Date", "Index.1", "code"},#"Added Index1",{"Date", "Index", "code"},"Added Index1",JoinKind.LeftOuter),
        #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"code", "date time", "description", "category", "Date", "Index", "Index.1"}, {"code.1", "date time.1", "description.1", "category.1", "Date.1", "Index.2", "Index.1.1"}),
        #"Removed Other Columns" = Table.SelectColumns(#"Expanded Added Index1",{"code", "date time", "description", "category", "Date", "date time.1", "description.1", "category.1"}),
        #"Added column" = Table.AddColumn(#"Removed Other Columns", "New", each Text.Combine({Text.From([code], "pt-BR"), "|", Text.From([Date], "pt-BR")}), type text),
        #"Remove duplicates" = Table.Distinct(#"Added column", {"New"}),
        #"Remove column" = Table.RemoveColumns(#"Remove duplicates",{"New"})
    in
        #"Remove column"