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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
laganlee
Helper II
Helper II

Add an index column in groups of three. 1,1,1,2,2,2,3,3,3, etc

Hi

I need an extra column that is like an index column, but groups in threes:

INDEX Column

1

1

1

2

2

2

3

3

3 etc

I need this after my Column59:

However, I don't want use the usual 'group by' solution as the table is more complicated than that and it wouldn't work!

groups.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Many thanks for looking!

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @laganlee ,

 

You can use Table.Split instead of Table.Group:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZNRkgIxCETvMt8OAw2BcBbL+19jYxwd3bXQqv0kPDrQJOfzAoYKL6dFeGPZruEIVnCQ+nI5TUI4xiFjG9AIr/iq/bsspjp8V8fMSqOwBzHrJfd6mUT60/23DjEI3DVErZNGRUA7iVWEGejo9A2RKWSlhDQlryTEkGR52CG72TjsYCeXikCMWyo7EI26/M8vpY4iHy0J5UrGoJFVkzrsrgDPIKnMNDeKcmHmxNUUwk8v712PEPJWCQSh3DdcKatVpDWqXPg8wyejVY2yAn65MAfvG+v9/5u219fwh1gfyOUH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [period = _t, dtTrans = _t, value = _t]),

    splitTable = Table.Split(Source, 3),
    convToTable = Table.FromList(splitTable, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    addIndex = Table.AddIndexColumn(convToTable, "Index", 1, 1, Int64.Type),
    expandNestedTables = Table.ExpandTableColumn(addIndex, "Column1", {"period", "dtTrans", "value"}, {"period", "dtTrans", "value"})

in
    expandNestedTables

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
laganlee
Helper II
Helper II

Thanks a lot Pete, that is awesome!  

Also very easy to do 🙂

Much appreciated!

BA_Pete
Super User
Super User

Hi @laganlee ,

 

You can use Table.Split instead of Table.Group:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZNRkgIxCETvMt8OAw2BcBbL+19jYxwd3bXQqv0kPDrQJOfzAoYKL6dFeGPZruEIVnCQ+nI5TUI4xiFjG9AIr/iq/bsspjp8V8fMSqOwBzHrJfd6mUT60/23DjEI3DVErZNGRUA7iVWEGejo9A2RKWSlhDQlryTEkGR52CG72TjsYCeXikCMWyo7EI26/M8vpY4iHy0J5UrGoJFVkzrsrgDPIKnMNDeKcmHmxNUUwk8v712PEPJWCQSh3DdcKatVpDWqXPg8wyejVY2yAn65MAfvG+v9/5u219fwh1gfyOUH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [period = _t, dtTrans = _t, value = _t]),

    splitTable = Table.Split(Source, 3),
    convToTable = Table.FromList(splitTable, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    addIndex = Table.AddIndexColumn(convToTable, "Index", 1, 1, Int64.Type),
    expandNestedTables = Table.ExpandTableColumn(addIndex, "Column1", {"period", "dtTrans", "value"}, {"period", "dtTrans", "value"})

in
    expandNestedTables

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors