Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Trying to figure out how to programatically expand a list of various data types, including other lists.
For example, here is a list of lists:
If I "drill down" to the next level using List.Combine, I now have more lists, and some text values:
The first List contained two Lists, the second List contained two text values.
Now I want to drill down again into those two list items, but I can't use List.Combine anymore, because that only works with data type List, and now I have some text values in my list. I want keep the text values as part of the new list, but continue drilling down into nested lists, until eventually I have a list of all text values.
Any help would be greatly appreaciated!
Solved! Go to Solution.
Thanks guys, I ended up using this function, works great!
You want is similar to {{"a", "b"}, {"c", "d"}, "e", "f", {"g", {"h", "i"}}} to convert to {"a", "b", "c", "d", "e", "f", "g", "h", "i"}?
Hi @shaunm001
try this, a recursive function that keeps using List.Combine until all lists have been expanded. For illustration purposes, it uses the list created in Source = and you'll see the result in the last step
let
expandFunc_ = (inputList_)=>
let
step0 = List.Combine(List.Transform(inputList_, each if Value.Type(_) = type list then _ else {_})),
step1 = List.Accumulate(inputList_, true, (state, current)=> state and Value.Type(current) <> type list ),
output = if step1 = true then step0 else @expandFunc_(step0)
in
output,
Source = {{"a", "b"}, {"c", "d"}, "e", "f", {"g", {"h", {"i",{"j", "l", "m"}}}}},
resfunc = expandFunc_(Source)
in
resfunc
Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs
Cheers
Seems to me that you will need a new column where you make the decision to drill down or not based upon the data type. You could probably turn around and combine that into a single step in your M code.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |