SOLVED

Create Invoice Number based on 2 columns and a counter

%3CLINGO-SUB%20id%3D%22lingo-sub-2612687%22%20slang%3D%22en-US%22%3ECreate%20Invoice%20Number%20based%20on%202%20columns%20and%20a%20counter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2612687%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EShared%20sheet%20through%20SharePoint.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20an%20invoice%20tracking%20table%20that%20has%20about%2040%20columns.%20The%20formula%20I%20am%20currently%20using%20to%20create%20the%20invoice%20number%20concatenates%20the%20TRUCK%23%2C%20DATE%2C%20and%20the%20addition%20of%20a%20counter.%26nbsp%3B%20I%20have%20been%20manually%20adjusting%20this%20counter%20whenever%20the%20truck%20and%20date%20combination%20were%20not%20unique.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Note%3A%20Each%20trip%20has%20a%20Load%20%23%20associated%20with%20it%20that%20I%20have%20%3CSTRONG%3Eno%3C%2FSTRONG%3E%20control%20over%20*%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22current.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300586i1D4E34DAE5376AD3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22current.png%22%20alt%3D%22current.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20looking%20for%20a%20formula%20that%20will%20auto%20increment%20the%20counter%20portion%20of%20my%20invoice%20number%20AND%20is%20not%20volatile%20(does%20not%20change%20when%20columns%20are%20sorted.)%26nbsp%3B%20The%20COUNTIF%20function%20(not%20familiar%20with%20it)%20was%20suggested%20to%20me%20for%20creating%20the%20counter%2C%20but%20it%20seems%20to%20be%20volatile%20as%20this%20piece%20of%20the%20invoice%20number%20ALWAYS%20showed%20in%20order%20(1%2C%202%2C%203%2C%20...)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20screen%20cap%20is%20an%20example%20of%20the%20desired%20results%20when%20sorting%20on%20the%20Load%20%23%20column.%3C%2FP%3E%3CP%3E*%20Table%20may%20be%20sorted%20on%20any%20column%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222021-08-04_17-08-28.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300590i005807FF57238706%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%222021-08-04_17-08-28.png%22%20alt%3D%222021-08-04_17-08-28.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20suggestions%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDarrMik%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2612687%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20for%20web%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2612808%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Invoice%20Number%20based%20on%202%20columns%20and%20a%20counter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2612808%22%20slang%3D%22en-US%22%3EYou%20say%20the%20Load%20%23%20you%20have%20NO%20control%20over%20BUT%3A%20a)%20is%20it%20persistent%20(i.e.%20will%20it%20stay%20the%20same%20over%20time%20or%20by%20your%20comment%20do%20you%20mean%20others%20may%20update%2Fchange%20it)%20and%20b)%20is%20it%20unique%3F%3CBR%20%2F%3ENext%2C%20do%20you%20have%20Excel%20365%20or%20some%20older%20version%20of%20Excel%20(i.e.%20we%20need%20to%20know%20which%20functions%20are%20available)%3CBR%20%2F%3Ebasically%20I%20am%20thinking%20of%20a%20formula%20like%20(i.e.%20I%20just%20wrote%20it%20here%20without%20testing%20it%20because%20it%20still%20depends%20on%20your%20answers)%3A%3CBR%20%2F%3E%3D%5B%40Truck%5D%26amp%3B%22-%22%26amp%3BText(%5B%40Date%5D%2C%22YYMMDD%22)%26amp%3B%22-%22%26amp%3BMatch(%5B%40%5BLoad%20%23%5D%5D%2CSort(Filter(%5BLoad%20%23%5D%2C(%5BTruck%5D%26amp%3B%5BDate%5D)%3D(%5B%40Truck%5D%26amp%3B%5B%40Date%5D)))%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2613177%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Invoice%20Number%20based%20on%202%20columns%20and%20a%20counter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2613177%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Ea)%20is%20it%20persistent%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E-%20Yes...the%20Load%20%23%20for%20that%20trip%20(truck%2Fdate%20combination)%20does%20not%20change%20once%20set%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eb)%20is%20it%20unique%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E-%20No....The%20Load%20%23%20is%20set%20by%20multiple%20different%20vendors%2C%20so%20theoretically%20Vendor%20A%20may%20have%20the%20same%20Load%20%23%20as%20Vendor%20B.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20truck%2Fdate%2Fload%20%23%20combination%20is%20unique%20though.%26nbsp%3B%20The%20boss%20wants%20the%20%22counter%22%20instead%20of%20the%20load%20%23%20added%20to%20the%20end%20of%20the%20invoice%20as%20the%20load%20%23%20can%20be%20any%20where%20from%203%20(smallest%20so%20far)%20to%2011%20(length%20is%20unlimited)%20characters%20(alpha%2Fnumeric)%20long.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2613179%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Invoice%20Number%20based%20on%202%20columns%20and%20a%20counter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2613179%22%20slang%3D%22en-US%22%3Eok%20so%20did%20you%20try%20my%20formula%3F%3C%2FLINGO-BODY%3E
Occasional Contributor

Shared sheet through SharePoint.

 

I have created an invoice tracking table that has about 40 columns. The formula I am currently using to create the invoice number concatenates the TRUCK#, DATE, and the addition of a counter.  I have been manually adjusting this counter whenever the truck and date combination were not unique. 

 

* Note: Each trip has a Load # associated with it that I have no control over *

 

current.png

 

I am looking for a formula that will auto increment the counter portion of my invoice number AND is not volatile (does not change when columns are sorted.)  The COUNTIF function (not familiar with it) was suggested to me for creating the counter, but it seems to be volatile as this piece of the invoice number ALWAYS showed in order (1, 2, 3, ...)

 

This screen cap is an example of the desired results when sorting on the Load # column.

* Table may be sorted on any column

 

2021-08-04_17-08-28.png

 

Any suggestions??

 

 

DarrMik

7 Replies
You say the Load # you have NO control over BUT: a) is it persistent (i.e. will it stay the same over time or by your comment do you mean others may update/change it) and b) is it unique?
Next, do you have Excel 365 or some older version of Excel (i.e. we need to know which functions are available)
basically I am thinking of a formula like (i.e. I just wrote it here without testing it because it still depends on your answers):
=[@Truck]&"-"&Text([@Date],"YYMMDD")&"-"&Match([@[Load #]],Sort(Filter([Load #],([Truck]&[Date])=([@Truck]&[@Date])))

@mtarler 

a) is it persistent

- Yes...the Load # for that trip (truck/date combination) does not change once set

b) is it unique?

- No....The Load # is set by multiple different vendors, so theoretically Vendor A may have the same Load # as Vendor B.

 

The truck/date/load # combination is unique though.  The boss wants the "counter" instead of the load # added to the end of the invoice as the load # can be any where from 3 (smallest so far) to 11 (length is unlimited) characters (alpha/numeric) long.

 

ok so did you try my formula?
I just tested it.....looks like it is stable (resorted on different columns and it maintained.) Far closer than I got.

When I add an additional trip (load id) with the same truck/date combination, the "counter" from the first load that was entered is incremented and the new load is appended with a '1.' This is close, but I need the new load to be appended with the '2' or '3' (what ever the current count is) and the load that is already in the list to maintain their "counter."
It will 'lock in' after all the loads for that day are finished but yeah if new loads are added with different load names it will likely change the numbers.
The only suggestion I have for you is to add a entry time. Then you can do that same filter/sort/match but use entry time and then it is guaranteed to be in order of when you enter it.
actually another solution would be to add a macro that creates the tracking number on entry but that wont work if you use excel online or if the settings are set to block macros. I would recommend adding a column called entry time and if you click CTRL-SHIFT-; (CTRL-:) that will automatically insert the time. the replace the [Load #] in the formula with the name of the new Time Stamp column.
best response confirmed by DarrMik (Occasional Contributor)
Solution

@mtarler 

The time column makes it work exactly as I am looking for....assuming the user remembers to enter the current time into the sheet. Hmmmm....just couldn't rely on that.  So...

 

I found a method that will enter the current time into the sheet automatically using the NOW() function and circular reference.   Source

 

Formula in TIME column:

=IF(A2<>"",IF(B2<>"",B2,NOW()),"")

 

Now, using this formula to set the time in a hidden/locked cell, I can use your formula (adjusted) to get the exact outcome I am looking for.

 

Final formula using the new (auto populating) TIME column:

=IF([@[Truck '#]]<>"", [@[Truck '#]]&"-"&TEXT([@[SERVICE
DATE]],"YYMMDD")&"-"&MATCH([@TIME],SORT(FILTER([TIME],([Truck '#]&[SERVICE
DATE])=([@[Truck '#]]&[@[SERVICE
DATE]])))),"")

 

As an added bonus, these formulas also work on the web version, so the user can enter the data from either the web browser or from within the Excel app.

 

Thx @mtarler for all your help