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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Dicken
Responsive Resident
Responsive Resident

Insert different table row or list range at each positon

Hi, 

Any suggestion about this   i want to insert a  tablle row or list range at varous positons, but a different value at 
each position  ie 1st postion "A", 2nd "B" or whatever  so , starting with ; 

= let alist =  { "A".."Z"} in  
List.Accumulate( {3,7,12} , alist, (s,c)=>List.InsertRange( s, c, {null}  ) )

I have used nested accumulation one  inside the other   but have not got it to work on this, this is jsut an idea. 
I have thougt of using list generate rather than accumulate, and again have the insert but not the change of value to insert at the moment . 

Richard 

Richard. 

1 ACCEPTED SOLUTION
MarkLaf
Super User
Super User

List.Generate versions if interested.

 

This iterates the inserts and then grabs last one as output.

 

let
    alist =  {"A".."Z"},
    addPosition = {3,7,12}, // buffer if query output
    addVals = {1,2,3}, // buffer if query output
    genAdds = List.Generate(
        ()=>[ i = 0, l = alist ],
        each [i] <= List.Count(addPosition),
        each let curIndex = [i] in [
            i = curIndex+1,
            l = List.InsertRange( [l], addPosition{curIndex}, {addVals{curIndex}} )
        ],
        each [l]
    ),
    output = List.Last( genAdds )
in
    output

 

MarkLaf_0-1752631685475.png

 

And here is a variation where inserts retain original positioning.

 

let
    alist =  {"A".."Z"},
    addPosition = {3,7,12}, // buffer if query output
    addVals = {1,2,3}, // buffer if query output
    addCount = List.Count(addPosition),
    genAdds = List.Generate(
        ()=>-1,
        each _ < addCount,
        each _ + 1,
        each [
            isLast = _+1 = addCount,
            curPos=if _ = -1 then 0 else addPosition{_}, 
            nextPos=if isLast then List.Count(alist) else addPosition{_+1}, 
            count = nextPos-curPos, 
            output = List.Range( alist, curPos, count ) & ( if isLast then {} else {addVals{_+1}} ) 
        ][output]
    ),
    combineParts = List.Combine( genAdds )
in
    combineParts

 

MarkLaf_1-1752631718150.png

 

View solution in original post

5 REPLIES 5
Dicken
Responsive Resident
Responsive Resident

to answer my own and based on previous answere I have this , not sure it's very effecient but does work; 

let
  Source =
    let
      alist = {"A" .. "Z"},
      pos   = {7, 12, 15},
      val   = {"100", "200", "300"}
    in
      List.Generate(
        () => [x = 0, y = pos{0}, z = alist, i = val{0}],
        each [x] < 4,
        each [x = [x] + 1, y = pos{x}, i = val{x}, z = List.InsertRange([z], [y], {[i]})],
        each [z]
      ),
  Custom1 = List.Last(Source)
in
  Custom1
Dicken
Responsive Resident
Responsive Resident

Thanks I'll have to work through  your method but i do like generate;  I did come up with tihis method, 

 let alist = {"A".."Z"} , pos = {7, 12, 16} , val ={"cat","dog","horse"} ,
index = {0..List.Count(pos)-1 } 
in List.Accumulate( index, alist, (s,c)=>   List.InsertRange( s, pos {c} , { val {c} } ) )

Obviuosly you might want to subtract 1 from each postion, but it does work. 

MarkLaf
Super User
Super User

List.Generate versions if interested.

 

This iterates the inserts and then grabs last one as output.

 

let
    alist =  {"A".."Z"},
    addPosition = {3,7,12}, // buffer if query output
    addVals = {1,2,3}, // buffer if query output
    genAdds = List.Generate(
        ()=>[ i = 0, l = alist ],
        each [i] <= List.Count(addPosition),
        each let curIndex = [i] in [
            i = curIndex+1,
            l = List.InsertRange( [l], addPosition{curIndex}, {addVals{curIndex}} )
        ],
        each [l]
    ),
    output = List.Last( genAdds )
in
    output

 

MarkLaf_0-1752631685475.png

 

And here is a variation where inserts retain original positioning.

 

let
    alist =  {"A".."Z"},
    addPosition = {3,7,12}, // buffer if query output
    addVals = {1,2,3}, // buffer if query output
    addCount = List.Count(addPosition),
    genAdds = List.Generate(
        ()=>-1,
        each _ < addCount,
        each _ + 1,
        each [
            isLast = _+1 = addCount,
            curPos=if _ = -1 then 0 else addPosition{_}, 
            nextPos=if isLast then List.Count(alist) else addPosition{_+1}, 
            count = nextPos-curPos, 
            output = List.Range( alist, curPos, count ) & ( if isLast then {} else {addVals{_+1}} ) 
        ][output]
    ),
    combineParts = List.Combine( genAdds )
in
    combineParts

 

MarkLaf_1-1752631718150.png

 

jgeddes
Super User
Super User

Are you looking for something like this?

let 
    alist = {"A".."Z"},
    list_to_insert = 
    {
        {"abc", "def", "ghi"},
        {"zyx", "wvu", "tsr"},        
        {123, 456,789},
        {987, 654, 321}
    },
    positions_list = {3, 7, 12, 7},
    zipped_list =  List.Zip({positions_list, List.Numbers(0, List.Count(positions_list))})
in  
    List.Accumulate( zipped_list , alist, (s,c)=>List.InsertRange(s, c{0}, list_to_insert{c{1}}))

jgeddes_0-1752606239074.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





AlexisOlson
Super User
Super User

What do you expect the result to be?

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors