How do you restart numbering in a table with rownum?
Asked by Pauline Ioannou:

I'm using table transformer and have a table sorted by duplicate values in one column. I'd like to use rownum to number the columns. However, I'm trying to get it to restart numbering at each new set of values. The over or partition functions are not available. How can this be done with table transformer? Example below of what I'd like output to look like.

1 \| apple

2 \| apple

1 \| orange

2 \| orange

3 \| orange


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@Pauline Ioannou](/t5/user/viewprofilepage/user-id/4817868) ,

The [Table Transformer](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Transformer+macro?utm_source=atl_community&utm_vendorID=1216111) macro is based on the AlaSQL library, so the OVER PARTITION functions are not supported.

We can suggest the following workaround (the first screenshot was taken for Server/Data Center, note that for Cloud you'll need the [Table Toolbox](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Toolbox+macro?utm_source=atl_community&utm_vendorID=1216111) macro to nest several macros):

![Wed 4-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/188422iE93E136F69E7F2A4/image-size/large?v=v2&px=999 "Wed 4-1.png")

As you can see, you'll need three copies of your original table to get the result.

Use the first internal Table Transformer macro to create a standard numeration:

SELECT ROWNUM() as 'N',  
T1.'Fruit', T1.'Number'  
FROM T1

![Wed 4-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/188423i81F27586B830D50D/image-size/large?v=v2&px=999 "Wed 4-2.png")Use the first internal Pivot Table macro to count the number of the group's entries cumulatively:

![Wed 4-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/188424iD62B53CC85FA780A/image-size/large?v=v2&px=999 "Wed 4-3.png")![Wed 4-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/188425i510B74CBE2DD663E/image-size/large?v=v2&px=999 "Wed 4-4.png")![Wed 4-5.png](https://community.atlassian.com/t5/image/serverpage/image-id/188426i65EF2922535C747D/image-size/large?v=v2&px=999 "Wed 4-5.png")Use the second internal Pivot Table macro to count the number of the group's entries as it is:

![Wed 4-6.png](https://community.atlassian.com/t5/image/serverpage/image-id/188427i2A873C2E11EC9E99/image-size/large?v=v2&px=999 "Wed 4-6.png")

Now use the external Table Transformer macro to count the required numeration:

SELECT T1.'N' - T2.'Count' + T3.'Count' as 'N',  
T1.'Fruit', T1.'Number'  
FROM T1 JOIN T\* ON T1.'Fruit' = T\*.'Fruit'

![Wed 4-7.png](https://community.atlassian.com/t5/image/serverpage/image-id/188428iC7F51ABCC0503B6A/image-size/large?v=v2&px=999 "Wed 4-7.png")

Hope this may help your case.

comments: author: Pauline Ioannou
body: Thank you for this! However, the cumulative count option is not available in our pivot macro.


author: Katerina Kovriga {Stiltsoft}
body: If the tags of the question don't lie and you are on Cloud, then you definitely have this option.

If you are on Server/Data Center, the only reason you don't see this option is that your version of the Table Filter and Charts for Confluence app is rather old.

The current version is 8.1.1, please update.


author: Pauline Ioannou
body: Thanks for that info. I used your methodology with table transformers and it worked! I created a table (using table transformer) with cumulative total column and incremental column. Then, I used your select statement formula to produce the new column. It worked! Thanks so much!!


Tags: cloud

confluence-cloud

table-transformer