Transforming json with power query (mix of list and record in a single column) Transforming json with power query (mix of list and record in a single column) json json

Transforming json with power query (mix of list and record in a single column)


I wanted to share an external link here (not sure whether I'm violating any policies, please correct me if so) so that someone else can also use this knowledge in need.My core issue got resolved with help of www.mrexcel.com/forum/power-bi. With this snippet, I'm able to create an excel based tool to prepare a data set for business by combining different feeds. Please find the code required for this (M, but very specific to my input file)

let    source = Json.Document(File.Contents("d:\path\filename.json")),    tabled = Table.FromRecords({source}),    expandListField = Table.ExpandListColumn(tabled, "thingstodo"),    expandRecField  = Table.ExpandRecordColumn(expandListField, "thingstodo", {"propCode", "hours"}, {"propCode", "hours"}),    expandList2  = Table.ExpandListColumn(expandRecField, "hours"),    fieldForRec  = Table.AddColumn(expandList2,"Rec",each if Value.Is([hours], type record) then [hours] else null,type record),    fieldForList = Table.AddColumn(fieldForRec, "List",each if Value.Is([hours], type list) then [hours] else null,type list),    removed = Table.RemoveColumns(fieldForList, {"hours"}),    expandRecField2 = Table.ExpandRecordColumn(removed, "Rec", {"day", "time"}, {"day", "time"}),    expandList3 = Table.ExpandListColumn(expandRecField2, "List")in    expandList3

Please find a link to this forum below:

http://www.mrexcel.com/forum/power-bi/904936-transforming-json-power-query-mix-list-record-single-column-2.html

Thanks