Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Dicken
Continued Contributor
Continued Contributor

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"} , 
 poslist = { 0..List.Count( alist )-2}  in 
 List.Accumulate( poslist, {}, (s,c)=>  
          if alist {c} = alist {c +1} then s & { alist {c} } else 
           s & { alist {c} , "", List.Last( alist) } )

 

 just stuck it on at the end,   I know there are oher ways, but I'm just interested in a neater way or perhaps an 'and' 
statement. 

Richard. 

2 ACCEPTED SOLUTIONS
Dicken
Continued Contributor
Continued Contributor

Please read post alist = 

 { "a","a","a","a","b","b","b","b","c","c","c","d"} 

View solution in original post

p45cal
Solution Supplier
Solution 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:

p45cal_0-1724591545677.png

or use null instead of "".

 

View solution in original post

10 REPLIES 10
slorin
Super User
Super User

Hi @Dicken 

 

Without List.Accumulate

= List.Combine(
List.Transform(
List.Zip({alist,List.Skip(alist)}),
each if _{0} = _{1} or _{1} = null then {_{0}} else {_{0}, ""})
)

 

or with your first idea

= let alist = { "a","a","a","a","b","b","b","b","c","c","c","d"} , 
poslist = { 0..List.Count( alist )-1} in
List.Accumulate( poslist, {}, (s,c)=>
if c=List.Max(poslist) or alist {c} = alist {c +1} then s & { alist {c} } else
s & { alist {c} , "" , List.last(alist)} )

 Stéphane

p45cal
Solution Supplier
Solution 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:

p45cal_0-1724591545677.png

or use null instead of "".

 

Dicken
Continued Contributor
Continued Contributor

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 ) )) 

 

p45cal
Solution Supplier
Solution 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}})

Dicken
Continued Contributor
Continued Contributor

No I'm tryiing to achieve what I said I was trying to achieve, a way of avoiding just adding the last  value on 
at then end.   

  s & { alist {c} , "original post.  

 

AntrikshSharma
Super User
Super User

@Dicken What is it that you're trying to achieve here? Add a blank row before each new alphabet?

No I , that is what it does, I want a better solution to  getting the last value included ohter than just adding it on the end, I did say this in the originla post,  please don't suggest alternativves as that is not the point I wans a conditons that will autmatically include the last value when ii is met or something somilar. 

please show us what you have as a start (presumably alist) and what you want to get in the end. We don't need your code. Thanks. 

Dicken
Continued Contributor
Continued Contributor

and what I want at teh end  = 

 { "a","a","a","a","b","b","b","b","c","c","c","d"} , 

but with a space inserted into between each but  want to use an accumlation that does includes the last value as said  I used 

           s & { alist {c} , "", List.Last( alist) } )


I think I've come up wiht a  better way of including the last value. 

Dicken
Continued Contributor
Continued Contributor

Please read post alist = 

 { "a","a","a","a","b","b","b","b","c","c","c","d"} 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.