excelexcel-formulaoffice365

How do I make the number stay the same, but continue from where it was left off if the day is different


I'm trying to make a LOT number generator. If a supplier is mentioned in column K in the same month, it grows, it has a value, but I don't know how to make it stay the same if it is in the same day. So if supplier C supplies me on month:6 day:17 year: 24 (6/17/24), the ending value should be 001, if we have one more month:6 day:17 year: 24 value should be 001 again. But when it is month:6 day:18 year: 24, the value should be 002. I have already fixed how value is different for each supplier, and values reset in each month. But I don't know how to keep the value same if supplier supplied us that day. I have tried If but couldn't make it work Current formula:

=TEXT(COUNTIFS(INDIRECT("K$1:K"&ROW()), K2, INDIRECT("F$1:F"&ROW()), F2, INDIRECT("H$1:H"&ROW()), H2), "000")

enter image description here


Solution

  • I would approach this as counting the cells above the row you're working in to check if the date & Supplier combination exists. If it does then use the match to get the code. If there's no match on the date, then we check if there's a match on the month. If there is a match there, but no exact date, we do a lookup to find the LAST match for the month and add 1 to it to get the next code. Lastly, if there's no matching date or matching month, it would reset to 1, so we set it to 1.

    My formula is: =TEXT( IF( COUNTIFS($A$1:A1,A2,$B$1:B1,B2)>=1, XLOOKUP(A2&B2,$A$1:A1&$B$1:B1,$D$1:D1,0,0), IF(COUNTIFS($A$1:A1,A2,$C$1:C1,C2)>=1, XLOOKUP(A2&C2,$A$1:A1&$C$1:C1,$D$1:D1,0,0,-1)+1,1)),"000")

    ![enter image description here