Deriving a new code from the last code in a pull data

Hello @Kal_Lam ,

I have a predefined Code identifying each school, this code is loaded in an excel sheet and is placed in the media of the form builder settings.

When a school types its school code, the code pre fills other options in the questionnaire.

Formula for code:
a. First digit represents the level of the school
b. Next two digits represent the region
c. Next two digits represent the district
d. And the last four digits is for the school

eg1. [Level (6) , Region (02) , District (07) , School (0002) ] hence school code is { 602070002}
eg2. [Level (3) , Region (03) , District (07) , School (0002) ] hence school code is { 303070002}

Assuming there is a new school from level(6), Region(02), District(07), how does the form create the new code using the last code from the excel data loaded to the form?

Code to be created will be
Level - 6
Region - 03
District - 07
School Code - 0002 + 1 = 0003

603070003

@theo27, could you share the sample XLSForm and the CSV file so that the community should be able to help you out?