Auto Increment on row ID (Google Sheet)

Hello, is there any way that i can auto increment (row ID) every time a new row added ?
I am using google sheet as the table data source
Thank you :grinning:

1 Like

@scape

Hey there :wave: Would you mind sharing a screenshot of what you are looking to do here? How are rows currently being added?

1 Like

Hello, thank you for the reply


I tried to make the ID Number auto generated every time i input new data
i used
{{(Math.max(List.data.length) +1)}}
on the ID Number value for the input, but i discover that it counts total array, not the last ID number.

how to get the last value of the ID Number and increment it by 1 for the next data input ?
(i'm using google sheet) :smiley:

1 Like

Hi @scape !

Did you find any solution?

Thanks.

Hi @lamartine.lopes and @scape, welome to the community :wave:

Have you checked this answer of mine on a previously asked similar question? If the timing is a bit iffy, I'd like to hear more of your process so we get the timing of incrementing on your primary ID.

Hey @lamartine.lopes thank you for your reply !
i still trying to find solution, is there any way that i can fetch the value of the row ?

Hello @jocen , thank you for your solution, i tried using your solution, but it only works if the next column is a number, it doesn't work if the next column is plain text, any idea how to make it work?

On your GSheet, set column A as primary ID for that specific table.
Set A2 as 1 or whatever number you want to start at
A3 would be =if(B3,A2+1,) then drag that thing down.

@scape, you can use any of the column by the way. I used column B as I am sure it will not be empty in the table structure I made. But if you have no other option, then you can just use =IF(ISTEXT(B3),A2+1,)

Hey, thanks for the reply @jocen

but I still cannot use this because when I delete a single row from retool, it will return
=IF(ISTEXT(B46),#REF!+1,)

is there any way I can get the value as number ? so I can put the value into some components and use it as an input

Hi @scape,

I didn't expect you'd hard delete rows on your table so that solution wasn't meant for your use-case.

You should take advantage of the temp state of retool then, docs here.

1. Query your table
2. Set value of your temp state var to the last pk id of your table
3. Use your temp state var
4. Update your temp state var when new entries are added

okay, I will try to learn about temp state.
Thank you very much for your help :grinning: