Find and remove duplicate IDs and replace - excel

I have very basic user Excel knowledge. I have a spreadsheet where I keep track of reloading data. Each load I enter gets a unique load number that is calculated automatically with a formula, based on the caliber name and an incrementally increasing number. As of now, every load I enter gets a number, even if it's been repeated before. Popular loads that I repeat often are all the same except for the date and numbers of rounds made but currently will have different load numbers. Is there a way to skips these repeated loads and assign it the previous load number or not assign a load number at all, with a formula instead of manually?
I know this is asking for a great deal but I'd greatly appreciate any help! I'm certainly open to suggestions if this isn't even the best way to go about this.
Sample workbook at:
https://www.dropbox.com/s/v5y1ufxjiosmnap/My%20Reloading%20Data%20-%20Sample.xlsx?dl=0
Here's what I've tried so far:
In column Q2, combine all the criteria.
=C17&E17&F17&G17&H17&L17&M17&N17&P17
In column R2 look for duplicates.
=IF(COUNTIF($Q$2:$Q17, $Q17)>1, "Duplicate", "")
D2 is the Load # column.
=IF(R17="Duplicate","",(TEXT(C17,0)&"-"&TEXT(COUNTIF($C$2:C17,C17),"000")))
This will skip the duplicate loads and not give them a load # leaving the cell blank. I'd love to find and match what that load # should be and insert it. Also, when the sequential numbering resumes it acts as if it's counted the duplicate row. For instance D2 might look like:
9mm-001
9mm-002
(Skipped for duplicate and left blank, but would like it to find, match, and insert the duplicate load #)
9mm-004 (I'd like to to be 9mm-003)

You should be able to achieve this with a VLOOKUP formula or a combination of MATCH and INDEX.
VLOOKUP (Vertical Lookup) looks for a match in another cell and returns a value from an offset column. A non match, if you use FALSE as the last parameter, returns a #N/A error.
So, in D20 (for example) you could, using column Q as your determinant, use the following, assuming you had a copy of D in column R:
=IFERROR(VLOOKUP(Q20,Q$1:R19,2,FALSE),[value for newly found loadno])
What this formula does is calculates a VLOOKUP - if that doesn't find a record, calculate a new value. The VLOOKUP will look at the concatenated key in the current row Q column, search through all previous columns (note it is anchored at row 1, but not anchored for the bottom of the range so you can copy the formula), it uses the column 2 (Q is column 1, so R is column 2) for the result, and demands an exact match (FALSE). If it doesn't find one, return NA and let the second half of the IFERROR take over.
See how you go with this.
The MATCH INDEX may work better because you won't need the additional R column due to VLOOKUP only being able to look to the right of the key.
Here is an INDEX and MATCH solution - slightly harder to understand, but a more flexible solution.
=IFERROR(INDEX(D$1:D19,MATCH(Q20,Q$1:Q19,0)),[value for newly found load number])
I prefer this.
The outer function says return the nth value in the list. The inner MATCH function says find this value (Q20) in this list (Q1:Q19). The 0 as the third parameter of the MATCH function says the match has to be exact.

Related

VLookUp with Nested SUMIFS

I have been trying to make a form for some of my team members who are not that computer literate, and I essentially want to make it click and go. I thought I could do it...but alas I am not as good with nesting functions as I thought I was.
I have this spreadsheet where I want to put data into the yellow cell. On the next sheet I have the below table. What I want to do is use a formula to fill H4 with the "Request Branch's" Account Number. Now, I have currently filled the cells with information. They, in fact, have drop down options - which are pulled from the Account List table. As a result the value in H4 will continually change based on the needs of the user - but must be within the confines of the Account List Table.
What I have tried is here and enter link description here. I keep getting result of #Value, or N/A. I can't figure out what I am doing wrong. I know that I need to nest the SUMIFS withing VLookUp, but I am not sure as to why it won't work.
I'm providing you with two possible solutions.
1) The first one uses the SUMPRODUCT function. You may not have seen this kind of notation before.
When ranges are multiplied by each other like so (B3:B8=G3)*(C3:C8=G4) they are actually turned into boolean arguments. If you highlighted this part of the code and pressed F9 it would look like this: {0;0;0;0;1;0;0}. This is an array where TRUE for both criteria meet. So our Branch is "A" and our Carrier is "F". In the rest of the cases either or both are false resulting in zeroes.
Now if you multiply this array by the range with account numbers, obviously the only number remaining will be the one multiplied by 1 and so you have the answer however keep in mind that as you are multiplying if the account is not a number the function will fail!
2) This is why we have a second method using =INDEX() and =MATCH() functions.
To overly simplify this - the INDEX function grabs contents from an array at a specified position (row and column), while the MATCH function gets the position of an item in an array.
The idea with using ranges as multiple criteria is the same as in the first example, however this time when we get our array of zeroes and ones {0;0;0;0;1;0;0} we use the match function to find at which position our criteria cross (as seen on the screenshot it's the 5th position, as it's in the 5th row of the entire column D, the match function searches the {0;0;0;0;1;0;0} array for a 1 and returns its position in the array) and so this is our ROW.
Knowing the position of the contents we searched for we use the INDEX function to grab the contents of the cell in that position so =INDEX(D2:D8,MATCH(1, INDEX((B2:B8=G3)*(C2:C8=G4),0),0)) is actually =INDEX(D2:D8, 5) meaning that the INDEX function grabs contents of the 5th row from the range D2:D8 which is cell D6.
The green boxes are just there to show the instance where both of our criteria are met (cross).
Please try this formula.
=INDEX(Table1[Account],SUMPRODUCT((Table1[Branch]=F$3)*(Table1[Carrier]=F$4)*ROW(Table1[Account]))-1)
Note that you may have to adjust the final -1. This is because the indexed table starts in row #2 and the SUMPRODUCT function returns a sheet row number. If your table would start in a different row the difference between the sheet row and table row would be larger. It must be adjusted here. Or you might work with sheet references (named ranges) and require no adjustment at all.

Seeking help to excel in Excel

This pictures shows my table and formula's yield
I have used following formula to extract result from a table.
Its working perfectly fine but I am hoping to level up my understanding of Excel formulas.
The trouble is that I use IF in Excel way to often.
what I wanted to know is if its possible to use a different approach, something that can work similar to if but is perhaps more sophisticated.
=IF(OR(J2="08L",J2="08R"),IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$34,0)),"LAM",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$35:$E$35,0)),"West",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$36:$G$36,0)),"East",IF(ISNUMBER(MATCH(LEFT(I2,3),'SID separations'!$D$37,0)),"SFD",NA())))),0)
I very much appreciate any help.
Now that there is an example, I think this is a good question. You've recognised that your formula is fairly messy and also can't be easily expanded if there are more routes.
The problem is that Excel is very good for searching for a value in a single row or column, but not as good for searching for a value in a block of data.
You can simplify this problem by creating an additional column that has each entire route in a single cell. You can do this just by concatenating values. In your example, use column H:
=B2&" "&C2&" "&D2&" "&E2&" "&F2&" "&G2
This will create a string with the entire route in a single cell. Spaces are added in between each part of the route to make sure you don't accidentally create a sequences of letters that matches part of another route. It doesn't matter if there are blank cells, there will just be some extra spaces at the end which doesn't matter. Fill this down the column to get the entire path for each route in a single cell.
Then, you can create a formula that tries to find the 3 letters anywhere in any of the full routes.
=INDEX($A$2:$A$5,MATCH("*"&left(I2,3)&"*",$H$2:$H$5,0))
This formula is basically a deconstructed vlookup. It determines where the 3 characters can be found in column H, then gives back the corresponding value from column A.
The MATCH function tries to find the left 3 characters of I2 in column H. The MATCH function normally tries to find a complete exact match (with the last parameter being equal to 0), but we can just add wildcards to the search value. The MATCH function then returns the index of the range where it was found. I.e., if it was found in the 2nd cell of the range H2:H5, it returns the number 2.
The INDEX function then just gets a value from a range based on an index. In this case, it will get the 2nd value from range A2:A5.

Transpose multiple occurrences

EDIT: I have revived the source data source to remove the ambiguity of my last screen shots
I am trying to transpose spreadsheet data where there are many rows where the customer name may be duplicated but each row contains a different product.
For instance
revised original data source
to
revised proposed data format
I would like to do it with formulae if possible as I struggle with VB
Thank you for any help
I realise this is a huge answer, apologies but I wanted to be clear. If you need anything from me, drop me a comment and I'll help out.
Here's the output from my formula:
EDITED ANSWER - Named ranges used for ease of understanding:
These are just an example of a few of the named ranges I have used, you can reference the ranges directly or name them yourself (simplest way is to highlight the data then put the name in the drop down next to the formula bar [top left])
Be wary that as we will be using Array formulas for AccNum and AccType, you will not want to select the entire column and instead opt for either the exact data length or overshoot it by 100 or so. Large array formulas tend to slow down calculation and will calculate every cell individually regardless of it being empty.
First formula
=IF(COUNTIF(D2:D11,">""")>0,CONCATENATE("Account Number ",LEFT((COLUMN(A:A)+1)/2,1)),"")
This formula is identical to the one in the original answer apart form the adjusted heading title.
=IF(Condition,True,False) - There are so many uses for the IF logic, it is the best formula in Excel in my opinion. I have used to IF with COUNTIF to check whether there is more than 0 cells that are more than BLANK (or ""). This is just a trick around using ISBLANK() or other blank identifiers that get confused when formula is present.
If the result is TRUE, I use CONCATENATE(Text1,Text2,etc.) to build a text string for the column header. ROW(1:1) or COLUMN(A:A) is commonly used to initiate an automatically increasing integer for formulas to use based on whether the count increase is required horizontally or vertically. I add 1 to this increasing integer and divide it by 2 so that the increase for each column is 0.5 (1 > 1.5 > 2 > 2.5) I then use LEFT formula to just take the first digit to the left of this decimal answer so the number increases only once every 2 columns.
If the result is FALSE then leave the cell blank ,""). Standard stuff here, no explanation needed.
Second Formula
=CONCATENATE(INDEX(Forename,MATCH(Sheet4!$A2,Reference,0)))
=CONCATENATE(INDEX(Surname,MATCH(Sheet4!$A2,Reference,0)))
CONCATENATE has only been used here to force blank cells to remain blank when pulled by INDEX. INDEX will read blank cells as values and therefore 0's whereas CONCATENATE will read them as text and therefore "".
INDEX(Range,Row,Column): This is a lookup formula that is much more advanced than VLOOKUP or HLOOKUP and not limited in the way that they are.
The range i have used is the expected output range - Forename or Surname
The row is then calculated using MATCH(Criteria,Range,Match Type). Match will look through a range and return the position as an integer where a match occurs. For this I have set the criteria to the unique reference number in column A for that row, the range to the named range Reference and the match type as 0 (1 Less than, 0 Exact Match, -1 Greater than).
I did not define a column number for INDEX as it defaults to the first column and I am only giving it one column of data to output from anyway.
Third Formula
Remember these need to be entered as an array (when in the formula bar hit Ctrl+Shift+Enter)
=IFERROR(INDEX(AccNum,SMALL(IF(Reference=Sheet4!$A2,ROW(Reference)-ROW(INDEX(Reference,1,1))+1),ROUNDDOWN((COLUMN(A:A)+1)/2,0))),"")
=IFERROR(INDEX(AccType,SMALL(IF(Reference=Sheet4!$A2,ROW(Reference)-ROW(INDEX(Reference,1,1))+1),ROUNDDOWN((COLUMN(B:B)+1)/2,0))),"")
As you can see, one of these is used for AccNum and the other for AccType.
IFERROR(Value): The reason that this has been used is that we are not expecting the formula to always return something. When the formula cannot return something or SMALL has run out of matches to go through then an error will occur (usually #VALUE or #NUM!) so i use ,"") to force a blank result instead (again standard stuff).
I have already explained the INDEX formula above so let's just dive in to how I have worked out the rows that match what we are looking for:
SMALL(IF(Reference=Sheet4!$A2,ROW(Reference)-ROW(INDEX(Reference,1,1))+1),ROUNDDOWN((COLUMN(B:B)+1)/2,0))
The IF statement here is fairly self explanatory but as we have used it as an array formula, it will perform =Sheet4!$A2 which is the unique reference on every cell in the named range Reference individually. In your mock data this returns a result of: {FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE} for the first entry (I included titles in the range, hence the initial FALSE). IF will do my row calculation* for every true but leave the FALSEs as they are.
This leaves a result of {FALSE;2;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE} that SMALL(array,k) will use. SMALL will only work on numeric values and will display the 'k'th result. Again the column trick has been used but to cover more ground, I used another method: ROUNDDOWN(Number,digits) as opposed to using LEFT() Digits here means decimal places so I used 0 to round down to a whole integer for the same result. As this copies across the columns like so: 1, 1, 2, 2, 3, 3, SMALL will alternatively (as the formulas alternate) grab the 1st smallest AccNum then the 1st Smallest AccType before grabbing the 2nd AccNum and Acctype and so forth.
*(Row number of the match minus the first row number of the range then plus 1, again fairly common as a foolproof way to always get the correct row regardless of where the data starts; actually as your data starts on row 1 we could just do ROW(Reference) but I left it as is incase you had data in a different format)
ORIGINAL ANSWER - Same logic as above
Here's your solution in 3 parts
Part 1 being a trick for the auto completion of the titles so that they will hide when not used (in case you will just copay and paste values the whole lot to speed up use again).
=IF(COUNTIF(C2:C11,">""")>0,CONCATENATE("Product ",LEFT((COLUMN(A:A)+1)/2,1)),"") in C
=IF(COUNTIF(D2:D11,">""")>0,CONCATENATE("Prod code ",LEFT((COLUMN(B:B)+1)/2,1)),"") in D
Highlight both of the cells and drag across to stagger the outputs "Product " and "Prod code "
Part 2 would be inputting the unique IDs to the new sheet, I would suggest copying your entire column A across to a new sheet and using DATA > REMOVE DUPLICATES > Continue with current selection to trim out the multiple occurrences of unique IDs.
In column B use =INDEX(Sheet2!$B$1:$B$7,MATCH(Sheet4!$A2,Sheet2!$A$1:$A$7,0)) to get the names pulled across.
Part 3, the INDEX
Once again, we are doing a staggered input here before copying the formula across the page to cover the entirety of the data.
=IFERROR(INDEX(Sheet2!$C$1:$D$11,SMALL(IF(Sheet2!$A$1:$A$11=Sheet4!$A2,ROW(Sheet2!$A$1:$A$11)-ROW(INDEX(Sheet2!$A$1:$A$11,1,1))+1),ROUNDDOWN((COLUMN(A:A)+1)/2,0)),1),"") in C
=IFERROR(INDEX(Sheet2!$C$1:$D$11,SMALL(IF(Sheet2!$A$1:$A$11=Sheet4!$A2,ROW(Sheet2!$A$1:$A$11)-ROW(INDEX(Sheet2!$A$1:$A$11,1,1))+1),ROUNDDOWN((COLUMN(B:B)+1)/2,0)),2),"") in D
The formulas of Part 3 will need to be entered as an array (when in the formula bar hit Ctrl+Shift+Enter) . This will need to be done before copying the formulas across.
These formulas can now be dragged / copied in all directions and will feed off of the unique ID in column A.
My Answer is already rather long so I haven't gone on to break the formula down. If you have any trouble understanding how this works, let me know and I will be happy to write up a quick guide, breaking it down chunk by chunk for you.

Excel - Conditional row from an array to COUNTIF from VLOOKUP

I don't know if I'm going about this the wrong way but it seems like it should be simple. Column A has a list of Names. Along each row is several "W"'s. Another separate field has a drop down representing Column A names. I want to count the number of "W"'s in a row corresponding to what name I select. I've tried using VLOOKUP and COUNTIF but I can't figure out how to select the entire array and then single out the one row that matches my selected name. I can get it working with a bunch of IF statements but thats far too time consuming as I'm manually matching the name to the row (and it isn't future proof).
There are a few ways to first 'narrow in' on the row you're looking for, after which point you can use a simple COUNTIFS to check the number of W's in that row.
One method would be to simply use INDIRECT, and create the row reference on the fly, like so [assumes your search cell is C1]:
=COUNTIFS(INDIRECT(MATCH(C1,A:A,0)&":"&MATCH(C1,A:A,0)),"W")
This first uses MATCH to find the appropriate row, and then builds a reference to that row [like "24:24"], which becomes the row that INDIRECT passes to COUNTIFS, which counts that row for W's.
For only one use of INDIRECT, the high computing costs of INDIRECT should not be an issue.
Another method would be to point out the full possible box that data could be contained in [let's assume that at most only column H would be used], and then use INDEX to give us the appropriate row number, like so:
=COUNTIFS(INDEX(A:H,MATCH(C1,A:A,0)),0,"W")
This again uses MATCH to find the row which contains the value found in C1 within column A. Then it takes the full possible box from INDEX, and returns all columns from the particular row [note that telling index to return 0 for the column # actually returns all columns instead].
Other methods would be possible [for example OFFSET], but I believe these two show the principle fairly well.
You could use the "Helper" Column method:
In the helper column:
=COUNTIF(B2:H2,"W")
Then use SUMIF() in the totals column:
=SUMIF($A$2:$A$9,K2,$I$2:$I$9)

I have multiple IDs for items, how can I use VLOOKUP to scan next column if it doesnt find it in the first?

Imagine my dataset has multiple IDs in columns, for the same item. How can I use VLOOKUP to scan the next column in the order up until it finds the same ID in another dataset? Or if it does not exist just stop searching after 6 columns? Thanks!
You could do this with 6 nested IFERROR statements; that would look like this: (Assuming your ID columns are A->F, your results column is G, and your search term is in J1):
=IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(VLOOKUP(J1,A:G,7,0),VLOOKUP(J1,B:G,6,0)),VLOOKUP(J1,C:G,5,0)),VLOOKUP(J1,D:G,4,0)),VLOOKUP(J1,E:G,3,0)),VLOOKUP(J1,F:G,2,0))
This looks at each column (starting with F and working outwards), and if it can't find a match, it creates an error, so goes to the next column. It is not very clean to read. A better way using this same methodology could be to use a combination of INDEX & MATCH, like so:
=INDEX(G:G,IFERROR(IFERROR(IFERROR(IFERROR(IFERROR(MATCH(J1,A:A,0),MATCH(J1,B:B,0)),MATCH(J1,C:C,0)),MATCH(J1,D:D,0)),MATCH(J1,E:E,0)),MATCH(J1,F:F,0))
Though this is a little shorter [because we don't need to specify the entire block of data, or which column to pull from, as it always pulls from column G], it is still not very readable.
Let's try this instead using an Array Formula which runs the same function multiple times over many cells, gets the result for each cell, and provides an array of results. Then we just need to collapse that array into a single value, like so:
=INDEX(G1:G14,MIN(IFERROR(IF(SEARCH(J1,A1:A14&B1:B14&C1:C14&D1:D14&E1:E14&F1:F14)>0,ROW(A1:A14),""),"")))
Confirm this formula with CTRL + SHIFT + ENTER instead of just ENTER. This adds all strings of all search columns together, basically making a single column of values. It then takes that column, and searches each cell for the word found in J1. If it finds it, it returns that row number, otherwise it returns "". The function then uses MIN to take the lowest row number found (to tie-break to the earliest row, if there is a duplicate), and then uses that with INDEX to return the value from that row in column G.
Note that the logic here is a little different from the options I gave above, as it defaults to the earliest row #, rather than the earliest column #, of a match.

Resources