Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi ,
Wonder if I can get any help on expanding this json result in response to a Post API the response is Json.
There are only 5 rows worth data here and on 3 List columns as per below. 1st and 3rd column has row values and 2nd column is cominbation of 7 field record.
Appreciate your help.
Basically I want a row each with list value for 1st column, expanded record fields of 2nd column and value of 3rd column.
Thank you.
Solved! Go to Solution.
Thanks Zoe, I tried expanding the columns 2 list columns will expand to 5 records each with repeats and record field in the middle can't be extended.
Basically what I want to do is to parse this JSON to a data table below.
Hi @Anonymous
Please see the attached file with a solution or the below script, the main transformation takes place in Added Custom step.
let
Source = Json.Document(File.Contents("C:\Users\mariu\OneDrive\Desktop\test.json")),
#"Converted to Table" = Record.ToTable(Source),
#"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Value] <> null and [Value] <> "")),
#"Transposed Table" = Table.Transpose(#"Filtered Rows"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "Custom", (a) => let
countRows = List.Max (
{
List.Count( a[MeasDataTypes] ),
List.Count( a[MeasDateTimes] ),
List.Count( a[MeasValues] )
}
) -1,
iList = { 0..countRows },
transform = List.Transform(
iList,
(b) => [
MeasDataTypes = a[MeasDataTypes]{b}?,
MeasDateTimes = a[MeasDateTimes]{b}?,
MeasValues = a[MeasValues]{b}?
]
)
in transform),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
#"Expanded Custom1" = Table.ExpandRecordColumn(#"Expanded Custom", "Custom", {"MeasDataTypes", "MeasDateTimes", "MeasValues"}, {"MeasDataTypes", "MeasDateTimes", "MeasValues"}),
#"Expanded MeasDateTimes" = Table.ExpandRecordColumn(#"Expanded Custom1", "MeasDateTimes", {"Day", "HasBeenSet", "Hour", "Minute", "Month", "Second", "Year"}, {"MeasDateTimes.Day", "MeasDateTimes.HasBeenSet", "MeasDateTimes.Hour", "MeasDateTimes.Minute", "MeasDateTimes.Month", "MeasDateTimes.Second", "MeasDateTimes.Year"})
in
#"Expanded MeasDateTimes"
Let me know if you need any help.
Hi @Anonymous ,
I am not clear about your requirement, you could try to expand these columns to see whether it work or not
By the way, you also could inform me your expected output or your sample data.
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks Zoe, I tried expanding the columns 2 list columns will expand to 5 records each with repeats and record field in the middle can't be extended.
Basically what I want to do is to parse this JSON to a data table below.
Hi @Anonymous
Please see the attached file with a solution or the below script, the main transformation takes place in Added Custom step.
let
Source = Json.Document(File.Contents("C:\Users\mariu\OneDrive\Desktop\test.json")),
#"Converted to Table" = Record.ToTable(Source),
#"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Value] <> null and [Value] <> "")),
#"Transposed Table" = Table.Transpose(#"Filtered Rows"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "Custom", (a) => let
countRows = List.Max (
{
List.Count( a[MeasDataTypes] ),
List.Count( a[MeasDateTimes] ),
List.Count( a[MeasValues] )
}
) -1,
iList = { 0..countRows },
transform = List.Transform(
iList,
(b) => [
MeasDataTypes = a[MeasDataTypes]{b}?,
MeasDateTimes = a[MeasDateTimes]{b}?,
MeasValues = a[MeasValues]{b}?
]
)
in transform),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
#"Expanded Custom1" = Table.ExpandRecordColumn(#"Expanded Custom", "Custom", {"MeasDataTypes", "MeasDateTimes", "MeasValues"}, {"MeasDataTypes", "MeasDateTimes", "MeasValues"}),
#"Expanded MeasDateTimes" = Table.ExpandRecordColumn(#"Expanded Custom1", "MeasDateTimes", {"Day", "HasBeenSet", "Hour", "Minute", "Month", "Second", "Year"}, {"MeasDateTimes.Day", "MeasDateTimes.HasBeenSet", "MeasDateTimes.Hour", "MeasDateTimes.Minute", "MeasDateTimes.Month", "MeasDateTimes.Second", "MeasDateTimes.Year"})
in
#"Expanded MeasDateTimes"
Let me know if you need any help.
User | Count |
---|---|
8 | |
6 | |
6 | |
5 | |
5 |
User | Count |
---|---|
9 | |
8 | |
6 | |
6 | |
6 |