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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

List values in the next record and all subsequent records.

In PQ, I am trying to add a custom column of lists. Each list contains the values from one column and includes the valve from the current record, the next record, and all subsequent records. Note the process is done for each [id]. Something like columns A, B, and C in the image below. 

Leataloneshimmy_1-1695075449347.png

Thanks,

LAS

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Try this:

let

//change next line to reflect actual data source
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", type text}, {"Value", Int64.Type}}),

//Group by ID
    #"Grouped Rows" = Table.Group(#"Changed Type", {"id"}, {
        {"List Below",(t)=>

    //Add an index column
    // then add the List Below column using the Index column to decide how many items
    // to remove
            let 
                #"Add Index" = Table.AddIndexColumn(t,"idx",0,1,Int64.Type),
                #"Add List Column" = Table.AddColumn(#"Add Index","List Below", each List.RemoveFirstN(t[Value],[idx]), type list)          
            in 
                #"Add List Column", 
                type table[Value=Int64.Type, List Below=list]}
        }),
        
    #"Expanded List Below" = Table.ExpandTableColumn(#"Grouped Rows", "List Below", {"Value", "List Below"})
in
    #"Expanded List Below"

 

Note: I did not expand the List Below column as you said you only wanted columns A, B and

In Power query:

ronrsnfld_0-1695084112427.png

 

 

View solution in original post

3 REPLIES 3
ronrsnfld
Super User
Super User

Try this:

let

//change next line to reflect actual data source
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", type text}, {"Value", Int64.Type}}),

//Group by ID
    #"Grouped Rows" = Table.Group(#"Changed Type", {"id"}, {
        {"List Below",(t)=>

    //Add an index column
    // then add the List Below column using the Index column to decide how many items
    // to remove
            let 
                #"Add Index" = Table.AddIndexColumn(t,"idx",0,1,Int64.Type),
                #"Add List Column" = Table.AddColumn(#"Add Index","List Below", each List.RemoveFirstN(t[Value],[idx]), type list)          
            in 
                #"Add List Column", 
                type table[Value=Int64.Type, List Below=list]}
        }),
        
    #"Expanded List Below" = Table.ExpandTableColumn(#"Grouped Rows", "List Below", {"Value", "List Below"})
in
    #"Expanded List Below"

 

Note: I did not expand the List Below column as you said you only wanted columns A, B and

In Power query:

ronrsnfld_0-1695084112427.png

 

 

Anonymous
Not applicable

Thanks,

I need to try group by custom function. Very cool.

 

It is a remarkably handy tool.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.