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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors