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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

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

October NL Carousel

Fabric Community Update - October 2024

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