I’m trying to set up a calc formula that will reference a number field and convert it to letters (“alphabase”, or base 26).
I’ve got a perfectly splendid simple little algorithm that works fine for anything I throw at it, of any size – except that it treats “Z” as zero, creating some counterintuitive ordinal patterns like “AW, AX, AY, BZ, BA”.
Then I’ve got three different calc formulas that try to wrestle the results into the desired ordinal pattern (A-Z, then AA, AB…AZ, then BA, BB…BZ, CA-CZ, etc to YA-YZ, ZA-AA, then AAA, AAB…AAZ…AZZ, BAA…ZZY…ZZZ, AAAA, you get the picture).
I will post the one that “runs” correctly the longest, generating its first undesired results at 35828 (which in alphabase = 2 1 0 0 where each column is 26 times the value of the column to its right), at which point it yields BZYZ instead of AYYZ following AYYY. I don’t care for the code itself, though – it has more brute force than elegance about it if you know what I mean. I’m getting errors in the 676’s column as well as the 17576’s column at 2 1 0 0 and have yet to get far enough into checking and debugging to even look at columns yet farther to the left.
I’m convinced there must be a simple and reliable formula that for some reason I’ve simply failed to visualize, so if you know one, post one! Thanks! (I’m doing this in FileMaker but a lot of techniques are portable between environments)
Note about the Choose function: “Choose” is a zero-indexed function, e.g., Choose(weekday, “zilch”, “sunday”, “monday”, “tuesday”, “wednesday”, “thursday”, “friday”, “saturday”) returns “saturday” when weekday=7 and returns “sunday” when weekday=1; if you put 0 in for weekday you get back “zilch”.
*
SN: original (decimal) serial number
Units: Mod(SN, 26)
A 26s: Int(Mod( SN/26, 26))
A 676s: Int(Mod( SN/676, 26))
A 17576s: Int(Mod( SN/17576, 26))
A 456976s: Int(Mod( SN/456976, 26))
Conversion to Alpha formula (the ugly brute force thing):
Case(SN¾475254, "",
Choose(A 456976s-Case(A 456976s=0, 1)
, "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y"))
&
Case(SN¾18278,"", A 17576s=0 and A 676s=0, "Y",
Choose(A 17576s-Case(A 676s=0, 1)
, "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y"))
&
Case(SN¾702,"", (SN>17602 and SN<18279), "Z", A 676s=0, "Y",
Choose(A 676s-Case(A 26s=0 or (A 26s=1 and Units=0), 1)
, "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y"))
&
Case(SN¾26,"", A 26s=0 and Units=0, "Y",
Choose(A 26s-Case(Units=0, 1)
, "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y"))
&
Choose(Units
, "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y")