Sequential Numbers using Drag

Hello. In most spreadsheets you can click the corner and drag the cell to create sequential numbers and/or repeat text etc.

Is there a way to accomplish the same thing in Grist? And also, what about a formula that would accomplish this.

Thank You!

2 Likes

Hi Chris!

This can be done using formulas. I created an example document that shows the options discussed below:

https://public.getgrist.com/1NenfgCTGrKv/Community-952

If you want the same value all the way down, youā€™d have a formula just equal to that value. Letā€™s say you have a column called ā€˜Stateā€™ and you want the same value all the way down to be Louisiana. The formula would be: = "Louisiana". You can see this in the 'Same Value Formula` column in the example table.

If you want to set a default value for new records, you can do that with a trigger formula. Using the State example, letā€™s say you want the default value to be Louisiana when a new record is created because most of the time, the state will be that but not necessarily all the time, so you want the ability to update it. You can see an example of this in the ā€˜Default Valueā€™ column. It uses the same formula as before, = "Louisiana" but now itā€™s set as a trigger formula that only applies on new records.

When a record is created, it is assigned a unique Row ID. Using this in formulas allows you to create other unique numbers, like Order Number. To have sequential numbers that use the row ID, you can use the row ID in a simple formula. Check out ā€˜Sequential Numbers using IDā€™. Here, the formula is = 1000 + $id. So you have 1001, 1002, etc. I deleted Example 3 which was assigned Row ID = 3 so it jumps to 1004 so the numbers in this column remain unique to each record.

Let me know if you have any further questions!

3 Likes

Not OP, but going to jump in here since I was wondering about something similar relating to sequential numbering:

Iā€™m trying to get a ā€œsite codeā€ to generate automatically when a new site is made, with the site code being a two-character initial representing the city the site is in, followed by a two-digit number that is sequential based on how many other sites are in that city (e.g. when adding a new site in Townsville, which already has four sites, this new fifth siteā€™s code would be TV05). Since the number doesnā€™t relate directly to the list of sites and instead relates to the number of sites in a particular city, Iā€™m not sure I can use RowID for this.

Iā€™ve tried the following (take the last site code and add one, basically):

ss_num = int(RIGHT(list(sorted(set((Sites.lookupRecords(City = $City).Site_Code))))[-1],2)) + 1

But then the system gets (kind of understandably) upset due to circular logic.

Any ideas on sequential numbering in a case like this?

1 Like

Sequential numbers come up in a few situations, and with different requirements. I put together this example to illustrate a couple of the scenarios, with recipes for achieving them:

https://public.getgrist.com/jiNnH5ULBknm/Sequential-Numbers/m/fork

  • How to keep sequential numbers that reflect the order rows are displayed in.
  • How to calculate sequential numbers within a group (@Parker_Smal 's question)
  • How to calculate sequential numbers that should not recalculate (as for check numbers)
6 Likes

Had to like the post because you used ā€œLouisianaā€ as an example :slight_smile:

2 Likes

@OSAcadiana_Jobs - Check out Webinar 7 - Custom Widgets for more Louisiana references :eyes:

2 Likes

lol, I canā€™t believe how few people use GetGrist- it should be millions more than it is. Needless to say, I was shocked to see a Louisiana reference in such a niche product. Great to know there are other fellow cajuns plowing away in this space!

4 Likes

Hi,

Iā€™m also missing this. Really nice that you can come up with a formula. But if I have week numbers, or months, it is not that easy. Would just dragging the fields not be the ā€œnormalā€ solution. Excel, Numbers, Google Sheets, LibreOffice, OpenOffice and every other spreadsheet tool since 1972 is using this technique. Creating a formula is way too hard for such a default type of behaviour. Donā€™t you think?

Best, Dirk