How to add auto increment number in Google sheet?

Hello everyone,
I am using Google sheet as database for my customers details. I am able to save all the details in my form but I want to auto increment c_id column when I click on submit form. SQL database auto generate the id. How can I do that in Google sheets?
image

1 Like

I have not seen a way to do this with google sheets. A quick google search shown one way be using the in-sheet function =ROW() which returns the row number the record. Perhaps this would work for you. Though this may cause issues when removing data and changing references.

Another thought I had is using a UUID value instead of an auto-increment value for your id/key. There is a UUID module which I haven't verified if it is available in Retool. There is also an emerging standard of crypto.randomUUID which could work as well.

Though longer than id's it does provide more accurate uniqueness in your table structure.

1 Like

Ooh great call Brett. UUID is indeed available in Retool! :slight_smile:

You invoke it like:

{{ uuid.v2() }} or {{ uuid.v4() }}

There are also a couple workarounds listed in these posts in case they're helpful for you:

http://community.retool.com/t/auto-increment-on-row-id-google-sheet/9387/6

http://community.retool.com/t/trying-to-create-an-id-column-and-autoincrement-each-additional-row-created-with-google-sheets/8838

Let me know if you have any questions about them!

1 Like

{{ uuid.v4() }} works fine.. thank you.! :slightly_smiling_face:

1 Like

This helped. Thank you.

Love to hear it! :blush:

Searching "google sheet auto generate id" on Google show this thread in first result page, so it can help others.

I found that =ROW() returns the number of the current row.
It can be combined with =ARRAYFORMULA() to write only one in the entire sheet.

But if you have an "header row" in row 1, and your data start from row 2 you should compensate for that.

Here is an example where data begins on sheets row 5.

The formula

=ARRAYFORMULA(ROW(A5:A)-4)

is written inside A5 only.

1 Like

Thank you for sharing this, @tresorama! Really appreciate you taking the time to help other users.