Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Splitting Table Whenever a Column Value is Encountered

Hello Everyone,   I have a timesheet table and I would like to slice it to show time spent on tasks for selected people/projects.  I also would like to show the total time for a project for everyo...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous 

    You may connect to csv file by improt mode. You can transform your data model in Power Query Editor.

    My table:

    My advanced editor:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tY+xCoMwFEV/RTI7JC9R41hahxZBad3EQUqG2lZFpeDfNzEipiBksBDI493DTU6eo+gjujGpBXJR2jWVuA/nk5yzsn/qYWxVlj3eAhVujg5x7KTX5BIds5sjA32GZihf8g4nZi4icgGYeBQTTbV6Lydv4tQjJhSwAIc84KpShgs5N4KCKePYh99GtjSaEOdAQ+avGjWZiq5varKPtret7Ri/pNbedNvbrARrcViJwz7izFYcrMXhL+LFFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"EveryOne", type text}, {"ProjectID", type text}, {"TaskID", type text}, {"Type", type text}, {"Time", type text}}),
        #"Removed Top Rows" = Table.Skip(#"Changed Type1",5),
        #"Added Conditional Column" = Table.AddColumn(#"Removed Top Rows", "Person", each if Text.Contains([EveryOne], "Person") then [EveryOne] else null),
        #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "P/T", each if Text.Contains([EveryOne], "Project") then [EveryOne] else if Text.Contains([EveryOne], "Task") then [EveryOne] else null),
        #"Reordered Columns" = Table.ReorderColumns(#"Added Conditional Column1",{"Person", "P/T", "EveryOne", "ProjectID", "TaskID", "Type", "Time"}),
        #"Filled Down" = Table.FillDown(#"Reordered Columns",{"Person"}),
        #"Removed Columns" = Table.RemoveColumns(#"Filled Down",{"EveryOne"}),
        #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"P/T", Order.Ascending}}),
        #"Removed Top Rows1" = Table.Skip(#"Sorted Rows",4),
        #"Sorted Rows1" = Table.Sort(#"Removed Top Rows1",{{"Person", Order.Ascending}, {"P/T", Order.Ascending}}),
        #"Changed Type2" = Table.TransformColumnTypes(#"Sorted Rows1",{{"Time", Int64.Type}})
    in
        #"Changed Type2"

    Result:

    You can download the pbix file from this link: Splitting Table Whenever a Column Value is Encountered

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.