Forum Discussion
Create Groups of Equal Size
- 1 year ago
ANBILY1
Below is the correct code which dynamically group the code and based on that it splits the table.let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xdExDoAgEAXRu2yNCaAolC57C8L9ryEdGKe3oHkhcT62Jj5swW/RxyRO7nGku6ERdUc9UBPqiXqhZtRCOojurtsUtyluU9ymuE1/+tr6khVfsmKZYZlhmWGZYZlhmWHZ1IxaSF//eCpuC99t/QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Code = _t, Value = _t]), TypeChanged = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Code", type text}, {"Value", type text}}), Result = Table.Combine( let CodeGrouping = Table.Group( TypeChanged,{"Code"},{"AllRows", each _ } )[AllRows], SplitTable = List.Combine( List.Transform( CodeGrouping,(x) => Table.Split(x,5) ) ), Result = List.Transform( SplitTable,(x) => let RowCountAdded =Table.AddColumn( x,"RowCount",each Table.RowCount(x) ), ListOfDatesAdded = Table.AddColumn(RowCountAdded,"Dates",each RowCountAdded[Date]), DateRemoved = Table.SelectColumns(ListOfDatesAdded, List.Select(Table.ColumnNames(ListOfDatesAdded), each _ <>"Date") ), RemoveDuplicate = Table.Distinct(DateRemoved) in RemoveDuplicate ) in Result ) in ResultI have imported more 12 rows as Code D. It dynamically groups and split the table as 5 rows. Below screenshot
one suggesation, please do not use List.FirstN if you are dealing with large data.. It technically slow down the query performance.
Attaching the file for your reference.
Hope it helps
Regards,
sanalytics
Thankyou SundarRaj and sanalytics for your response.
Hi ANBILY1,
We appreciate your inquiry through the Microsoft Fabric Community Forum.
We would like to inquire whether have you got the chance to check the solutions provided by SundarRaj and sanalytics to resolve the issue. We hope the information provided helps to clear the query. Should you have any further queries, kindly feel free to contact the Microsoft Fabric community.
Thank you.