Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
In the absence of a direct function for slicing a list, I found several ways, combining various library functions, to get the result, using List.Accumulate, for example, or List.Transform.
but for this last function I encountered a difficulty that I have overcome, but it is not clear to me how.
The signature of the function is
List.TransformMany(list as list, collectionTransform as function, resultTransform as function) as list
but using this form, I get an error message about a value that cannot be converted to a list
let
lst={10..20},
idx={2,3,5},
sel=List.TransformMany(idx, each lst{_},(x,y)=>y)
in
sel
instead using this form, you get the desired result:
let
lst={10..20},
idx={2,3,5},
sel=List.TransformMany(idx, each {lst{_}},(x,y)=>y)
in
sel
12 |
13 |
15 |
.
can anyone explain why?
Hi @Anonymous ,
I think {lst{_}} seems to convert the value to list, then you could use idx as index to get corresponind value in lst List.
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.
Hi @dax, yes I know tha {something} convert the "something" as value in "something" as list of only one element.
Is for that reason that I changed the script from the first form to the second form, as I in the first case get the eror message (something like a "value wich can't be read as list" . For this reason I thought that the function somewhere expected a list and not a value and so I made several attempts until I found the second form).
My question is about the the documentation of the function, which seems to me to be misleading.
But, I'm not very practical with the English language, so I may have misunderstood the explanation.
From this example, it can be understood that the function makes a sort of Cartesian product of the two lists
let lst1={1..5}, lst2={-5..-1}
in Table.FromRecords(List.TransformMany(lst1, each lst2,(x,y)=>[x=x,y=y]))
So using this property, choosing appropriate subsets of the Cartesian product to which to apply the appropriate transformations, many things can be done.
Another way of slicing lists can make use of some record functions:
0-based:
let
idx=List.Transform({0,1,2,10},Text.From),
lst1={11..33},
lstFields=List.Transform({0..List.Count(lst1)-1}, Text.From),
rec1=Record.FromList(lst1,lstFields)
in Record.ToList(Record.SelectFields(rec1, idx) )
1-based:
let
idx=List.Transform({1,2,10},Text.From),
lst1={11..33},
lstFields=List.Transform({1..List.Count(lst1)}, Text.From),
rec1=Record.FromList(lst1,lstFields)
in Record.ToList(Record.SelectFields(rec1, idx) )
PS
I absolutely do not take into account the efficiency aspects in these solutions. It's just an exercise.
here another "experiment" with the funcion, to get the result more directly
let
lst={10..20},
idx={2,3,5},
sel=List.TransformMany({0}, each idx,(x,y)=>lst{y})
in
sel
perhaps the documentation of the function that is provided in https://docs.microsoft.com/en-us/powerquery-m/list-transformmany should be revised or it is I who do not understand the explanation well.
You could use any list instead of {0}.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
9 | |
7 | |
5 | |
5 | |
5 |
User | Count |
---|---|
10 | |
8 | |
6 | |
6 | |
6 |