Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
reymalave
Helper I
Helper I

handling n number of columns

Hi Guys,

 

I have this table coming from a csv. The table has trajectories over x,y,z points and start and finish instants with and index column.

Each index (trackedFaceID) has multiple (x,y,z) points with duration (start and finish instants) spread over multiple columns, I want to have only four columns ("id", "duration", "x", "y","z")

You can download trajectories csv

 
 
 

Annotation 2019-11-18 140028.png

1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

Here you go something like this:

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\artemus\Downloads\trajectories.xlsx"), null, true),
    in_Sheet = Source{[Item="in",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(in_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"trajectoryId", Int64.Type}, {"trackedFaceID", Int64.Type}, {"beginInstant", type number}, {"endInstant", type number}, {"duration", Int64.Type}, {"trajectoryIntervals", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "trajectoryIntrevals_Json", each "{" & [trajectoryIntervals] & "}"),
    #"Inserted Parsed JSON" = Table.AddColumn(#"Added Custom", "JSON", each Json.Document([trajectoryIntrevals_Json])),
    #"Expanded JSON" = Table.ExpandRecordColumn(#"Inserted Parsed JSON", "JSON", {"trajectoryIntervals"}, {"trajectoryIntervals.1"}),
    #"Expanded trajectoryIntervals.1" = Table.ExpandListColumn(#"Expanded JSON", "trajectoryIntervals.1"),
    #"Expanded trajectoryIntervals.2" = Table.ExpandRecordColumn(#"Expanded trajectoryIntervals.1", "trajectoryIntervals.1", {"s", "e", "x", "y", "z"}, {"s", "e", "x", "y", "z"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded trajectoryIntervals.2",{"trajectoryId", "duration", "x", "y", "z"})
in
    #"Removed Other Columns"

The key is to add {} around your trajectory column so that you can parse the entries as JSON

 

View solution in original post

2 REPLIES 2
artemus
Microsoft Employee
Microsoft Employee

Here you go something like this:

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\artemus\Downloads\trajectories.xlsx"), null, true),
    in_Sheet = Source{[Item="in",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(in_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"trajectoryId", Int64.Type}, {"trackedFaceID", Int64.Type}, {"beginInstant", type number}, {"endInstant", type number}, {"duration", Int64.Type}, {"trajectoryIntervals", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "trajectoryIntrevals_Json", each "{" & [trajectoryIntervals] & "}"),
    #"Inserted Parsed JSON" = Table.AddColumn(#"Added Custom", "JSON", each Json.Document([trajectoryIntrevals_Json])),
    #"Expanded JSON" = Table.ExpandRecordColumn(#"Inserted Parsed JSON", "JSON", {"trajectoryIntervals"}, {"trajectoryIntervals.1"}),
    #"Expanded trajectoryIntervals.1" = Table.ExpandListColumn(#"Expanded JSON", "trajectoryIntervals.1"),
    #"Expanded trajectoryIntervals.2" = Table.ExpandRecordColumn(#"Expanded trajectoryIntervals.1", "trajectoryIntervals.1", {"s", "e", "x", "y", "z"}, {"s", "e", "x", "y", "z"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded trajectoryIntervals.2",{"trajectoryId", "duration", "x", "y", "z"})
in
    #"Removed Other Columns"

The key is to add {} around your trajectory column so that you can parse the entries as JSON

 

Thanks! It worked just fine. Nice trick!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.