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.
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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
8 | |
6 | |
6 | |
5 | |
5 |
User | Count |
---|---|
9 | |
9 | |
8 | |
6 | |
6 |