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 September 15. Request your voucher.

Reply
xieofxie
Frequent Visitor

preserve order when using Table.Group

As documented, Table.Group "cannot guarantee to return a fixed order of rows". While this is bad for sorted data when used with Text.Combine. For example, the following is sorted by Time first and I would like to group by Id while Combine Text in order.

IdTimeText
112:00abc
113:00def
214:00ghi

Another approach would be to create a new column with Time and Text as Table first, then save it as list when grouping, and finally reorder the list according to Time. But it is too complex.

Any ideas? Thanks~

 

 

1 ACCEPTED SOLUTION

You can try GroupKind.Local - to my understanding, it should keep the sort order (but you can only use it if your data is in a consecutive order: https://blog.crossjoin.co.uk/2014/01/03/aggregating-by-local-groups-in-power-query/ 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

If it is complex M, then it's @ImkeF 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

You can try GroupKind.Local - to my understanding, it should keep the sort order (but you can only use it if your data is in a consecutive order: https://blog.crossjoin.co.uk/2014/01/03/aggregating-by-local-groups-in-power-query/ 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks~ But how could we make sure of that (keep order)? I didn't find any document about GroupKind.Local.

Hi @xieofxie ,

 

The GroupKind.Local optional parameter is the key to getting the behaviour you can see here. The default type of grouping, GroupKind.Global, does a standard group by across the whole table as seen in the first example above. 

You can refer to this document:

https://blog.crossjoin.co.uk/2014/01/03/aggregating-by-local-groups-in-power-query/

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

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.