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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
meforwork
New Member

Possible to combine every X number of rows?

I have a simple list with text objects. 

 

Example:

rowHeader
Apples
Oranges
Bananas
Kiwis
Plums
Grapes
Tomatos

 

I am wondering if there is a way to combine every X rows.  For example, I want to combine every 3 rows in to a single row with some string tagged on (like. "Object(s): "), and delimited by a comma (","), so it would look like:

 

rowHeader2
Object(s): Apples,Oranges,Bananas
Object(s): Kiwis,Plums,Grapes
Object(s): Tomatos

 

The out-of-the-box functions from what I see can only do static merges of 2 or more colums, but the list I actually have has 100+ rows.

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @meforwork 

According to your description, you want to combine every 3 rows in to a single row.

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1690425069418.png

 

(2)We can insert a step after the "Changed Type" step, and we can enter this M code in it :

vyueyunzhmsft_1-1690425090150.png

= List.Transform(List.Generate(()=>0,each _<=List.Count(#"Changed Type"[rowHeader]),each _+3,each List.Range( #"Changed Type"[rowHeader],_,3)), (x)=>"Object(s):" & Text.Combine(x,",") )

 

If the above step's name is not the #"Changed Type", you need to change the M code in your side.

 

And then we can get the result as follows:

vyueyunzhmsft_2-1690425176233.png

 

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

View solution in original post

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @meforwork 

According to your description, you want to combine every 3 rows in to a single row.

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1690425069418.png

 

(2)We can insert a step after the "Changed Type" step, and we can enter this M code in it :

vyueyunzhmsft_1-1690425090150.png

= List.Transform(List.Generate(()=>0,each _<=List.Count(#"Changed Type"[rowHeader]),each _+3,each List.Range( #"Changed Type"[rowHeader],_,3)), (x)=>"Object(s):" & Text.Combine(x,",") )

 

If the above step's name is not the #"Changed Type", you need to change the M code in your side.

 

And then we can get the result as follows:

vyueyunzhmsft_2-1690425176233.png

 

 

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

amitchandak
Super User
Super User

@meforwork , add an index column starting with 0 in the power query

then add a new column in the power query

Power BI- Power Query Table.AddIndexColumn- https://youtu.be/KEW4bbuqbV8

 

Number.IntegerDivide([Index],3)

 

Now use group by and concat as given in the video

Concatenate Text- Measure, DAX Table, and Power Query Table: https://youtu.be/xAh3tz1qo24

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.