Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
I have an expression which produces a list of records. Each record can have properties whose values are another list of records or a record. I want to convert it into a Table, where each list of records gets transformed into a table, and each record gets transformed into a table too. All recursively.
For example, if the data structure looks like this:
{
"include": [
{
"relation": "ActivityCodeSet",
"scope": {
"limit": 2
}
}
]
}
Then this query:
= Table.FromRecords(
List.Transform(
Json.Document(Web.Contents("localhost:64977/ActivityCode?filter={""include"":[{""relation"":""ActivityCodeSet"",""scope"":{""limit"":2}}]}")),
each Record.TransformFields(_,
{
{"ActivityCodeSet", (x) => Table.FromRecords({x})}
}
)
)
)
Does the job I want, but the problem is, it is very hardcoded to that json structure. How can I do this more generically where I don't hardcode any field names? It should just work recursively with any json structure.
I got this so far, but it doesn't seem to work recursively. The nested ones remain a list of records.
= let
Source = ...,
fxFactorial = (x as list) =>
let
Check = Table.FromRecords(List.Transform(x, each Record.TransformFields(_,
let
Row = _,
Fields = Record.FieldNames(Row),
RFields = List.Select(Fields, each Value.Is(Record.Field(Row, _), type record)),
LFields = List.Select(Fields, each Value.Is(Record.Field(Row, _), type list)),
RFieldsTr = List.Transform(RFields, each {_, (x) => Table.FromRecords({x})}),
LFieldsTr = List.Transform(LFields, each {_, @fxFactorial}),
Full = List.Combine({RFieldsTr, LFieldsTr})
in
Full
)))
in
Check,
Custom1 = fxFactorial(Source)
in
Custom1
Keep in mind that at the end of your Power Query script needs to be a single table with (ideally) static meta data (column names, column order, column types). So while you may be able to recursively collect all these tables, it is for nought as you then need to squeeze them into a single result.
XML and JSON are by definition hierarchical. RDBMS type solutions are not. Converting one into the other includes making compromises and concessions.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
27 | |
27 | |
24 | |
13 | |
10 |
User | Count |
---|---|
24 | |
21 | |
19 | |
19 | |
11 |