Forum Discussion
Dicken
2 years agoPost Prodigy
Inserting blank into a list ,
Hi, in the code below is there a way to deal with the fact the last value is not included, other than what i have don and let alist = { "a","a","a","a","b","b","b","b","c","c","c","d"} , ...
- 2 years ago
Please read post alist =
{ "a","a","a","a","b","b","b","b","c","c","c","d"} - 2 years ago
This perhaps?:
let alist = {"a","a","a","a","b","b","b","b","c","c","c","d"}, poslist = {1..List.Count(alist)-1} in List.Accumulate(poslist, {alist{0}}, (s,c)=> if alist{c} = alist{c-1} then s & {alist{c}} else s & {"",alist{c}})resulting in:
or use null instead of "".
p45cal
2 years agoSolution Supplier
This perhaps?:
let alist = {"a","a","a","a","b","b","b","b","c","c","c","d"},
poslist = {1..List.Count(alist)-1}
in List.Accumulate(poslist, {alist{0}}, (s,c)=> if alist{c} = alist{c-1} then s & {alist{c}} else s & {"",alist{c}})
resulting in:
or use null instead of "".
- Dicken2 years agoPost Prodigy
Yes , thanks, I had gon about it in a slightly different way, this is to insert 3 blank rows but the principle hte same starting a 1 column tablle to insert 3 blank rows at change; the main problem is it's not very effecient, need to re write with generate ?
= let alist = Source [Test] , pos = { 1..List.Count(alist ) -1} , acc = List.Accumulate( pos, {}, (s,c)=> if alist {c-1} = alist {c} then s & {0} else s & { 0,1,0,0} ) in List.Accumulate( List.PositionOf( acc, 1 , Occurrence.All ), Source , (s,c)=> Table.InsertRows( s, c ,Table.ToRecords( insert3 ) ))- p45cal2 years agoSolution Supplier
to insert 3 blank rows instead of one, use:
…then s & {alist{c}} else s & {null,null,null,alist{c}}
or:
…then s & {alist{c}} else s & {"","","",alist{c}}
or any number of blank rows (10 here):
…then s & {alist{c}} else s & List.Repeat({null},10) & {alist{c}})