Forum Discussion

Hansolu's avatar
Hansolu
Helper II
1 year ago
Solved

Add a paired index column

Hi, 

I am struggeling to add a paired index column into a nested table in PQ

 

I know how to add an index in the nested table like 1,2,3,4,5,....

what i do need to add is another column lik 1,1,2,2,3,3,4,4,5,5,6,6,...

So repeat the index number one time and go to the next 

 

Guess not so complicate but somehow I struggle with this.

 

thanks

  • Hansolu 

    First, add a simple index column starting with zero:

    Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type)


    then the second one

    Number.IntegerDivide([Index], 2) + 1


    Result

     



3 Replies

  • Fowmy's avatar
    Fowmy
    Super User

    Hansolu 

    First, add a simple index column starting with zero:

    Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type)


    then the second one

    Number.IntegerDivide([Index], 2) + 1


    Result

     



  • Hi Hansolu 

    Can you please try the below steps to get your requirement ?

    1. Create index column from 0 

    2. Create custome column using below code

    = Number.IntegerDivide([Index], 2) + 1

     

    After creating custom col if index col is not required then you can remove it.


    If this answers your questions, kindly accept it as a solution and give kudos.

  • Hi, 

    thanks both of you, same solution, works great

    Actually I was thinking, must be something easy, I just took the wrong turns in my trials

    Thanks for the help