I'm trying to create a formula for the following issue.
I have one sheet with two columns:
A Spare_part_code which are alphanumeric codes
B Part_type which is just a letter from A to E. (we assign the importance f a part based on the letter, being A most important and E less important)
Then on another sheet, I have a list of repairs, one per line that have in lines from G to X the parts used on that repair.
I would like to, per repair, have a formula that search among all the parts used on that repair, and return the level of the parts used, but only the Letter of the most important part, for example:
For repair XXXXX I have used 10 parts, and all of them are E type, except one which is B, so In this case I need to show B on the result
For repair YYYYY I have used 3 parts, all of them A, so I need the formula to return A.
Suppose this is the final output you needed.
Add this formula in cell F2 and Drag down. I have written the formula from column G to X as you have requested.
=IF(COUNTIF(G2:X2,"A"),"A",IF(COUNTIF(G2:X2,"B"),"B",IF(COUNTIF(G2:X2,"C"),"C",IF(COUNTIF(G2:X2,"D"),"D",IF(COUNTIF(G2:X2,"E"),"E","NA")))))
Related
I have a row of data, let's say (a, b, c, d, e, a, c)
I want to count the number of duplicates - in this case, 2 (2 a's, 2 c's)
However, I do not want to use COUNTIF(RNG,A1)>1 and drag out for the entire length of the list.
I would like to search the row for all values in the range and count if it finds a match.
Here is the frequency version (for earlier versions of Excel) for completeness:
=SUMPRODUCT(--(FREQUENCY(MATCH(A1:H1,A1:H1,0),MATCH(A1:H1,A1:H1,0))>1))
counts the number of different letters with frequency>1 which is (a,c) =>2
There is also an alternative interpretation of the question, which is 'how many duplicates exist in total?' (i.e. one for a, two for c making three altogether):
=COUNTA(A1:H1)-SUMPRODUCT(--(FREQUENCY(MATCH(A1:H1,A1:H1,0),MATCH(A1:H1,A1:H1,0))>0))
Counts the total number of letters (8) minus the number of unique letters (5) (a,c,c) => 3
If you don't have Excel 365, then:
=SUMPRODUCT((1/COUNTIF(A1:G1,A1:G1)<1)*(1/COUNTIF(A1:G1,A1:G1)))
With Excel 365 and data in A1 thru G1, pick a cell and enter:
=SUMPRODUCT(--(COUNTIF(A1:G1,UNIQUE(TRANSPOSE(A1:G1)))>1))
(this is actually the method indicated in your question, but with all the helper arrays hidden)
NOTES:
this:
UNIQUE(TRANSPOSE(A1:G1))
will produce an array like:abcdeand this:
COUNTIF(A1:G1,UNIQUE(TRANSPOSE(A1:G1)))
will produce:21211and the SUMPRODUCT() counts how many of the above are greater one.
The blue columns is the data given and the red columns is what is being calculated. Then the table to the right is what I am referencing. So, F2 will be calculated by the following steps:
Look at the Machinery column (D), if the cell contains LF, select column K, otherwise select column L
Look at the Grade column (E), if the cell contains RG, select rows 4:8, otherwise select rows 9:12.
Look at the Species column (A), if the cell contains MS, select rows 5 and 10, otherwise.......
Where every the most selected cell is in columns K and L, copy into column F.
Multiply column F by column C.
I don't want to make another column for my final result. I did in the picture to show the two steps separately. So column F should be the final answer (F2 = 107.33). The reference table can be formatted differently as well.
At first, I tried using nested-if statements, but realized that I would have like 20+ if statements for all the different outcomes. I think I would want to use the SEARCH function to find weather of not the cell contains a specific piece of information. Then I would probably use some sort of combination of match, if, v-lookup, index, search, but I am not sure how to condense these.
Any suggestion?
SUMPRODUCT is the function you need. I quickly created some test data on the lines of what you shared like this:
Then I entered the below formula in cell F2
=SUMPRODUCT(($I$4:$I$9=E2)*($J$4:$J$9=LEFT(A2,FIND(" ",A2)-1))*IF(ISERROR(FIND("LF",D2,1)),$L$4:$L$9,$K$4:$K$9))
The formula may look a little scary but is indeed very simple as each sub formula checks for a condition that you would want to evaluate. So, for example,
($I$4:$I$9=E2)
is looking for rows that match GRADE of the current row in range $I$4:$I$9 and so on. The * ensures that the arrays thus returned are multiplied and only the value where all conditions are true remains.
Since some of your conditions require looking for partial content like in Species and Machine, I have used Left and Find functions within Sumproduct
This formula simply returns the value from either column K or L based on the matching conditions and you may easily extend it or add more conditions.
I have the following data
Person Week1
P1 L,L
P2 M,H
Output I would like is
Person Week1
L M H
P1 2 0 0
P2 0 1 1
My intention is to create a chart based on the output so I can figure out how many codes a person got per week. Pivot tables does not seem to work for this case.
Thanks
This is a pure formula approach.
Its based off of two basic formulas. The first formula is how to count the number of times a string A occurs within string B. This is done, by counting the number of characters in the string B, then by counting the number of characters in String B after string A has been replaced by nothing or "". If string A is more than 1 character long you need to divide the result by the length of string A. That gives us this formula:
=(LEN(STRING B)-LEN(SUBSTITUTE(STRING B, STRING A, "")))/LEN(STRING A)
Now we know how to count the number of time L, M or H occur as they are string A and now we need to determine string B.
IF we look at the first table, it has nice row headers and column hearders. We could take a short cut and just assume everything is in order however I am going to go with the more generic approach in case the headers happen to be in a random order.
Basically we need to find out what column in the first table matches with the header in our second table. ie is week2 really the second column? is P1 still the first row? in order to do that we use the following
=MATCH("WEEK X",$B$1:$D$1,0)
and
=MATCH("PX",$A$2:$A$3,0)
Those will return an integers which we can then drop into the an INDEX function to locate and find the text in the first table:
=INDEX($B$2:$D$3,MATCH("PX",$A$2:$A$3,0),MATCH("WEEK X",$B$1:$D$1,0))
AWESOME we now know how to find the text from the table to drop into our counting formula that we started with. That las formula gets substituted into wherever there is STRING B!
=(LEN(INDEX($B$2:$D$3,MATCH("PX",$A$2:$A$3,0),MATCH("WEEK X",$B$1:$D$1,0)))-LEN(SUBSTITUTE(INDEX($B$2:$D$3,MATCH("PX",$A$2:$A$3,0),MATCH("WEEK X",$B$1:$D$1,0)), STRING A, "")))/LEN(STRING A)
yeah its getting a little ugly isn't it! String A is then whatever cell L is in in your second table. Replace "Week X" with your week header in your second table. Replace "PX" with the name of your person in your second table.
I would do the first formula, then copy it over under the M and under the H. Go into the M and H formula and adjust it so its pointing at the right week header in each. Lock the row but not the column references for the week header and the string A cells. Lock the column but not the row for the persons name. once you have that set up, copy al three formulas and paste under each week. Then just copy your entire first row of table two down for the number of people you have and voila!
Proof of concept
The formula I used in Cells H3, I3, and K3 respectively
=(LEN(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)))-LEN(SUBSTITUTE(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)),H$2,"")))/LEN(H$2)
=(LEN(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)))-LEN(SUBSTITUTE(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)),I$2,"")))/LEN(I$2)
=(LEN(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)))-LEN(SUBSTITUTE(INDEX($B$2:$D$3,MATCH($G3,$A$2:$A$3,0),MATCH(H$1,$B$1:$D$1,0)),J$2,"")))/LEN(J$2)
Here is another proof of concept with expanded range showing rows out of order, and multiple letter strings to be searching for and more than two entries. Same formulas, just had to adjust the look up ranges for the increased table size.
If using VBA is acceptable, splitting the comma separated data using TextToColumns should help as a first processing step.
Then using a pivot table gives you the output you want.
I'm a little stuck on an Excel question where I am required to assign certain locations (A, B, C, D, E and F) to output North, Centre and South in the column called 'Area'.
For example I am told that:
if any individual works in location A, C or D that would be classified as South.
If the work area is B and E then it would be Centre.
And finally if anyone works in area F then it would be North.
How should my external cells look?
Assuming the area letter to be assigned is in A1,
One way:
=IF(A1="F","North",IF(OR(A1="B",A1="E"),"Centre","South"))
This is probably the closest to what you were attempting. South was left as a default value to save specifying three letters for it (A, C and D - North and Centre only required three between them).
Another way:
=CHOOSE(CODE(A1)-64,"South","Centre","South","South","Centre","North")
This converts the letter into its code number and then deducts 64 (so A gives rise to 1, B to 2 etc.) and then feeds that as the choice to be selected from the options shown.
A third way:
=LOOKUP(R1,{"A","B","C","D","E","F"},{"South","Centre","South","South","Centre","North"})
Similar to the second way but without the character code conversion. A formula version of what is more often achieved with a lookup table (below).
A fourth way:
=VLOOKUP(A1,AreaTable,2,0)
This as mentioned by #Tim Williams. AreaTable was my choice of name for a Named Range comprising A to F in sequence in one column and in the column immediately to the right of that (matching rows) the same "South", "Centre", .... , "North".
IF
OR
CHOOSE
CODE
VLOOKUP
There are other ways such as, instead of the vertical Named Range, a horizontal one and HLOOKUP.
I have a large table in excel that has column headings A, B, C, D, and ANSWER
A, B, C, D represent the multiple choice questions I have in the table.
I also have an ANSWER column that has the answers represented by the corresponding multiple choice heading letter mentioned above.
For example, under each column heading (A, B, C, D), I have the possible answers, Food, Car, House, School.
In the example above, House (C) is the correct answer. I would like to create an IF statement that matches the Answer cell, which has C in it with the A, B, C, D column headings and if there's a match, then insert an = before the actual answer. In this case, the result would be =house. The rest of the answers should have the ~ inserted before the word, i.e., ~food, ~car, ~school.
The final result should look like this: ~food, ~car, =house, ~school.
The only way to achieve that securely is to duplicate the table in another sheet or in different columns.
Why is that?
Because you want to change the SOURCE of your statement. Excel would consider that a circular reference and couldn't resolve it.
There's a VBA code solution, that you can run ONLY ONCE. That would change the source data as well and you would lose your originals. Could be an action with no turning back.
So:
I suggest you create a new sheet, put the headers A, B, C and D.
So you would have two sheets: the OriginalSheet containing the answers and each option.
And the ResultSheet, containing the options formated as you want.
In the ResultSheet, use this formula:
= IF(OriginalSheet!$E2 = A$1; "="; "~") & OriginalSheet!A2
That is considering the first line containig the texts: A, B, C and D. So you must insert this formula in the A2 cell of the ResultSheet.
You can click in the little black square in bottom right of the cell and drag this formula to all other cells. (The $ simbols garantee the drag will be safe)