Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am building a Power BI report with an API data source. I’m connecting to the API endpoint fine but the json that is being returned has two arrays per object, one for the column metadata and the other array providing the values. Similar to this post: https://community.powerbi.com/t5/Desktop/Load-JSON-array-of-values-with-field-names-in-another-eleme...
Here’s an example of the json that is being returned. I’ve simplified it greatly, but you’ll see the columnMetadata array and the rowData array. I need the FieldName value in the columnMetadata array and the corresponding value from the rowData array.
[
{
"jobId":"a",
"columnMetadata":[
{
"name":"JOB ID",
"FieldName":"job_id",
"unitText":null,
"columnIndex":0,
"dataType":"string",
"schemaType":"Static"
},
{
"name":"TASK ID",
"FieldName":"TASK_id",
"unitText":null,
"columnIndex":1,
"dataType":"string",
"schemaType":"Static"
}
],
"rowData":[
[
"a",
"t1"
],
[
"a",
"t2"
]
]
},
{
"jobId":"b",
"columnMetadata":[
{
"name":"JOB ID",
"FieldName":"job_id",
"unitText":null,
"columnIndex":0,
"dataType":"string",
"schemaType":"Static"
},
{
"name":"TASK ID",
"FieldName":"TASK_id",
"unitText":null,
"columnIndex":1,
"dataType":"string",
"schemaType":"Static"
},
{
"name":"TASK NAME",
"FieldName":"TASK_Name",
"unitText":null,
"columnIndex":2,
"dataType":"string",
"schemaType":"Static"
}
],
"rowData":[
[
"b",
"t1",
"name1"
],
[
"b",
"t2",
"name2"
],
[
"b",
"t3",
"name3"
]
]
}
]
In the json example above, you can see a few things:
I’m looking for recommendations as to the best way to proceed. My gut tells me that I’ll have to go down the custom connector path with logic that handles each JobID object, parses the columnMetadata along with the rowData arrays to align the column name and values together. This will need to be done for each JobID object and then at the end put all of them together for a final output to Power BI.
Another thought is that maybe this could be done within the M code. Or maybe even a python script within Power BI to handle this transformation.
Solved! Go to Solution.
Hi JSON results can be navigated fairly reliably. After parsing the JSON and transformed it into a table, just add a column with this formula:
Table.FromRows(
_[Column1][rowData],
List.Transform(
_[Column1][columnMetadata],
(metadata) => metadata[FieldName])
)
For the dynamic column names, you can use this expression:
List.Union(List.Transform(#"Added Custom"[Custom], Table.ColumnNames) )
See file attached:
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi JSON results can be navigated fairly reliably. After parsing the JSON and transformed it into a table, just add a column with this formula:
Table.FromRows(
_[Column1][rowData],
List.Transform(
_[Column1][columnMetadata],
(metadata) => metadata[FieldName])
)
For the dynamic column names, you can use this expression:
List.Union(List.Transform(#"Added Custom"[Custom], Table.ColumnNames) )
See file attached:
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thanks @ImkeF for the help. I was able to get this working against the API data source.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
24 | |
12 | |
12 | |
11 | |
8 |
User | Count |
---|---|
45 | |
28 | |
14 | |
13 | |
13 |