Assign letters to areas - excel

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.

Related

Find Coincidences on a Matrix

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")))))

Excel Solver Finding a Target Sum from Subset of Number Set

I want to use Solver to find a target sum from a subset of a larger set. (10 number subset of 16 numbers). I'm not very familiar with Solver and I'm unsure of the best way to set my constraints.
I have 5 categories of numbers within the set, A, B, C, D, E. The set of 16 may include different combinations of these categories, but the target subset total has a defined makeup:
A, B, B, C, C, C, (B or C), (B or C),D, E
So my question is, how would I introduce these rules into Solver?
Secondarily, I know Solver comes up with 1 solution, is there a way to get a range of solutions that are closest to the target? So, if I have a set that doesn't quite produce the target, I could see 3 solutions that are nearest the target (plus or minus)?
Thanks.
TL/DR - Here's a way to setup the problem you have. Getting a series of answers that are "close" is out of scope for Solver. You could do it with VBA, if you define additional criteria to search around. (Edit - added set up for defined makeup)
Comments
It seems there is no criteria about "a number must be selected from each category", or "a number must be selected from category X". Rather, you have a bunch of numbers, each belongs to a category, but you want to find the combination of numbers that provide a certain total - then investigate the categories afterward.
Initial Problem Setup
From the information you provided in your comment, I put together the following ...
Column A (Category) and Column B (Value) is the information you provided. Column C (Selected) is just 0 or 1. Column D (Result) is the multiplication =B2*C2 filled down.
F2 is the sum of Column D. G2 is the target value for this sum (as you provided). H2 is the squared error of the calculation =(F2-G2)^2.
This is the solver setup ...
Set Objective: is set to $H$2 - the squared error of the calculation
To: is set to Min. You could choose Value Of: 0, but if there is no exact answer, it may fail.
By Changing Variable Cells: is set to $C$2:$C$17 or Column C.
Subject to the Constraints: includes $C$2:$C$17 = binary. This forces the values to be either 0 or 1.
Select a Solving Method: is set to Evolutionary. GRG Nonlinear can sometimes solve this type of problem, but it takes much longer than Evolutionary.
Below is the result - different from what you reported. When I force your result, I get 106.61 for CalcTotal (perhaps a transcription error somewhere) ...
Finding Near Results
Solver is an optimizer, so it will find "the answer" that best fits your objective.
In order for it to provide you with different answers, you need to provide it with different objectives.
For example, you may want to force a solution that uses C1, but is still closest to your objective. The setup might look like this...
... with this solution ...
In that example, I excluded $C$10 from the "By Changing Variable Cells:" and from the "Subject To Constraints:" fields. Another way to accomplish the same thing would have been to keep the original field values unchanged, but to add an additional constraint of $C$10 = 1.
Or, as another example, perhaps you want a solution that chooses exactly two values from Category B. You could modify the setup to include sums of values selected from each category, and add a constraint. Here is the setup ...
... and the corresponding result ...
Making an Algorithm
If you determine criteria for the range of solutions you are looking for, you could setup a VBA sub to loop through setting up Solver, getting the solution, and storing the results of the "Selected Column" for review.
If you want to pursue this track, I suggest you look at other solutions provided on this site, try to set something up, and ask a new question if you have problems.
Edit - missed one of your criteria
I missed addressing your statement - "the target subset total has a defined makeup: A, B, B, C, C, C, (B or C), (B or C),D, E"
In this instance, using the setup containing sums for each category, you can specify these constraints ...
$G$4 = 1
$G$5 <= 4
$G$5 >= 2
$G$6 <= 5
$G$6 >= 3
$G$7 = 1
$G$8 = 1
On first pass, it provided this result: A1, B2, B3, C1, C3, C4, C5, C6, D1, E1 with a total of 106.38.

Change the shape of an outline in Excel

Am running Office Professional Plus 2013 on Windows 7.
Have a matrix as depicted in the following image:
Full matrix data is found in this Google spreadsheet. There are two tabs - generic terms and specific terms.
Matrix is used to classify items - such as specific plants. There are items assigned to this matrix, but they are not shown to reduce complexity.
The matrix is a normalized matrix, meaning that the columns are fixed - there is place in the matrix for all possible values. But in many cases there is no value (a NULL value) for a column. For example, the genus on row 8 is defined by kingdom : subkingdom : division : class : order : family : genus.
The columns subdivision, subclass, superorder, suborder and family are not used to define that specific genus. In contrast, the genus on row 14 is defined by subdivision.
Using symbols, the normalized matrix looks as follows:
The goal is create a de-normalized matrix - to reshape the matrix where a column no longer has a meaning, but is just a level in the outline. The general approach is to delete a NULL cell and - on the next line(s) - move its dependent "children" left.
The manual process would be:
Delete D5 and move Class left.
Delete E6 and move Order left.
Repeat ad nauseam.
The de-normalized matrix would look like this:
Fortunately, symbols in the first three columns are never NULL (C - constant) - we can reference them, but do not need to move them. But the position of a symbol in all other columns is variable (V - variable), depending on which nulls have been deleted.
There is one wrinkle. There are instances where an item (implied but not shown) is not mapped to genus. Instead, the item is mapped to a broader terms such as family. Row 15 is an example where family is the terminal node; genus is not used to define this item.
How to create an Excel formula or script that:
deletes a NULL position
on the row with the deleted NULL position, moves the term left
on the next row(s) that are related to the parent cell, move the term(s) to the left?
If it is easier to work with names (division, subdivision, class, etc.) than with symbols, that's OK. The Google spreadsheet provides the generic term and the specific term.
Here's a sample output of my formula based solution:
There are 2 helper columns (M, N).
Formula in M2 (calculates current item's position in row), fill the column with it:
=MATCH("*",A2:L2,0)
Formula in N2 (calculate new item's position in row), fill the column with it:
=IF(M2-M1>0,N1+1,IFERROR(LOOKUP(2,1/($M$1:M1=M2),$N$1:N1),M2))
Formula in O2 simply places the item in right column, fill entire range with it:
=IF($N2=O$1,INDEX($A2:$L2,1,$M2),"")
It takes some time to calculate all rows, but I think it produces the desired output.
EDIT:
I think I found a bug in my solution, the formula in N2 should be:
=IF(M2-M1>0,N1+1,LOOKUP(2,1/($M$1:M1<M2),$N$1:N1)+1)
I didn't notice it earlier, because it affects row 2468 (Amborellanae).

Displaying the row header for highest X values in each row (for ranking list)

I'm having trouble trying to rank and display the popularity of certain items in a table in Excel. An image showing a simplified example of what I'm trying to create is at this link (it won't let me post images, because I'm still new here):
For each row (or shape, here), I want to display in columns H,I and J, the column Header (in this case, the colour) for the most popular three types.
I've tried variations of the following formula for Column H (most popular):
=INDEX($A$2:$F$2,1,MATCH(LARGE($A3:$F3,1),$A3:$F3,0))
...and then, change the "1" in the LARGE() function to "2" and "3" for Columns I and J.
That works for finding the largest number and returning the column Header for H, but it can't handle when there is more than one instance of a particular number in the row.
Example given: for Triangles (Row 5), it comes up with "Blue" in Columns H, I and J, instead of looking for the next equal/lower number. And for Circles, it gives me "Blue", "Blue", "Green" - it knows that Green (2) is lower than Blue (3), but can't tell that Yellow (3) is also higher than Green, because once it finds the first instance of the highest number (in this case, Blue), it stops searching through.
I don't mind that it doesn't recognise that Green is actually 'first equal' rather than 2nd. I'm happy for it to be prioritised from left to right, but I need it to show the top three (and more, once I expand) without duplicating the results.
I'd like to avoid any VBA if I can, and feel like there must be a way to do this easily.
A possible workaround
I assume the values are integers
The idea is to subtract a very small value multiplied by the column to each value so that there are no equal values
Create a second Sheet (I assume the sheetnames are Sheet1 and Sheet2)
Put the formulas in Sheet2:
A3 | = Sheet1!B3-0.00001*COLUMN()| = Sheet1!C3-0.00001*COLUMN()| = Sheet1!D3-0.00001*COLUMN()| = Sheet1!E3-0.00001*COLUMN()| = Sheet1!F3-0.00001*COLUMN()|
A4 | = Sheet1!B4-0.00001*COLUMN()|...
A5 | ...
....
And change the formula to
"=INDEX($ B $2:$F$2,1,MATCH(LARGE(Sheet2!$ B 3:$F3,1),Sheet2!$ B 3:$F3,0))"

IF statement that inserts text based on matching text

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)

Resources