Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
H,
is there a way to use List.Generate to insert a null , at a given position,
so here I have to ways to calculate the positons, one gen one accer ;
Inserting 2 places;
let
alist = {"A".."Z"} ,
itemlist = {"D", "K", "N"} ,
pos = List.PositionOfAny(alist,itemlist,Occurrence.All),
newpos = List.Accumulate( pos, {}, (s,c)=> s & { ( List.Count(s) * 2 ) + c + 1 } )
in
newpos
let
alist = {"A".."Z"} ,
itemlist = {"D", "K", "N"} ,
pos = List.PositionOfAny(alist,itemlist,Occurrence.All),
newpos = List.Generate( ()=> [ x = 0 , y = pos{0}, z = y + 1] ,
each [x] < 3 ,
each [ x = [x] + 1, y = pos{x} , z = (x * 2) + y +1] ,
each [z] )
in newpos
Then to insert I have been using accumuate;
result = List.Accumulate( newpos, alist, (s,c)=> List.InsertRange( s, c, {null,null} ) )
I have been trying to replicate the above using List.Generate, but end up with nested lists one for each positon,
not what I wnated. Any suggestions ?
Richard.
Solved! Go to Solution.
Hi @Dicken ,
Just wanted to check and make sure everything is working good with the solution you shared. It looks like a solid approach, and I am really glad you found a way to use List.Generate to solve your issue.
Is it meeting your needs so far? If there is anything else you would like to adjust or if you run into any other challenges, feel free to reach out .We happy to help further.
Thank you.
To offer a sort of answer to my own question, I had want to use actrual number positons with generate ,
rather than a true false approach , but this does work, I have used null but ideally would create blank record,
[ reclist = Table.ToRecords(Source) ,
poslist = {"F", "K", "N"} ,
gen = List.Generate( ()=> [
x = 0, y = reclist{0} , z = {y} ] ,
each [x] < List.Count( reclist) ,
each [ x = [x] + 1, y = reclist{x} , z =
if List.Contains( poslist, Record.Field( y, "Item"))
then { y,null} else {y} ] ,
each [z] ) ,
result = List.Combine( gen ) ] [result]
Richard.
Hi @Dicken ,
Just wanted to check and make sure everything is working good with the solution you shared. It looks like a solid approach, and I am really glad you found a way to use List.Generate to solve your issue.
Is it meeting your needs so far? If there is anything else you would like to adjust or if you run into any other challenges, feel free to reach out .We happy to help further.
Thank you.
Yes, one thing, if posting code, I feel i should use tags as it would make easier for people to read,
would you recommend ?
How are these list.generate, which is what was asked. i do like the
List.Transform / many , but I wanted to use generate if possible, if it's not possibel that's fine.
let
alist = {"A".."Z"} ,
itemlist = {"D", "K", "N"},
blist = List.Combine(List.Generate(()=>0,each _ < List.Count(alist),each _+1,each if List.Contains(itemlist,alist{_}) then {null,alist{_}} else {alist{_}}))
in
blist
let
alist = {"A".."Z"} ,
itemlist = {"D", "K", "N"} ,
newpos = List.TransformMany(alist,each if List.Contains(itemlist,_) then {_,null,null} else {_},(x,y)=>y)
in
newpos
Hi @Dicken
= List.Combine(
List.Transform(
alist,
each if List.Contains(itemlist, _) then {_, null, null} else {_}
)
)
Stéphane
Remember you can use a shortcut to append lists
List.First(list,2) & {null} & List.Skip(list,2)