Selecting a value of a table in Excel - excel

I have a definition table, as well as two variable cells. Based on those I want to select a value from the table. See table below.
EXAMPLE
Variable cell 1 is Fitch, variable cell 2 is CCC+. I want in my output cell, called also Credit quality class, to see the value 6. How can I do that?
TABLE
Fitch
Moody's
S&P
Credit quality class
AAA
Aaa
AAA
0
AA+
Aa1
AA+
1
BBB+
Baa1
BBB+
3
CCC+
Caa1
CCC+
6
RD
/LD
SD
6
I tried using INDEX and MATCH functions, but I do not obtain the correct result. It does work if I use IF statemets for each column, but that is not what I am looking for.

A Double Lookup
In Microsoft 365 you can simply do:
=IFERROR(XLOOKUP(G2,XLOOKUP(G1,A1:C1,A2:C6),D2:D6),"")
If you don't have it, you can use INDEX/MATCH:
=IFERROR(INDEX(D2:D6,MATCH(G2,INDEX(A2:C6,,MATCH(G1,A1:C1,0)),0)),"")
Either way, study the following to better understand how INDEX/MATCH work.

If you have Excel 365 you can use this formula:
=LET(step1,FILTER(A1:D6,A1:D1=B11),
INDEX(D1:D6,MATCH(B12,step1,0)))

You may use SUMPRODUCT:
=SUMPRODUCT(($A$2:$C$6=H5)*($A$1:$C$1=H4)*D2:D6)
This formula will work as long as variables are correct, and each variable 2 is unique in each column.

Related

Excel, find a date closest in a range of dates given a number and return another cell

New to advanced excel concepts, I have a list of numbers such as:
101 02/22/2016
100 02/21/2016
and then another list like so:
101 01/01/2016 Apple
101 02/20/2016 Banana
100 02/21/2016 Apple
100 02/23/2016 Banana
I'm trying to get it where I use a vlookup with the number on the more basic table, check for a match on the advanced table then find the date on the advanced table that is closest to the date on the basic table, then return the value to the right (Banana, Apple).
I've got the vlookup part down, but placing an if statement just returns N/A and breaks every time.
I've also tried using this guide: http://eimagine.com/say-goodbye-to-vlookup-and-hello-to-index-match/
You can use this array formula:
=INDEX($C$1:$C$4,MATCH(MIN(IF($A$1:$A$4=E1,ABS($B$1:$B$4-F1))),IF($A$1:$A$4=E1,ABS($B$1:$B$4-F1)),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.

IF 25% match or more, sum up values

Is there a way to use a formula to get excel to look at values and determine if they have atleast a 25% match then to add their values. Kind of like a vlookup and IF function combined but I am not sure how to do the 25% part. The reason I ask this is because I have a data set with Company names that are the same company but they are all typed in differently so excel recognizes them as separate companies. For example:
Company: Value
XYZ Incorperated 25
XYZ Company 40
XYZ 12
ABC INC. 39
ABC inc. 10
ABC COMPANY 15
I need it to realize that all the companies with "XYZ" are the same and to add all their values. Same goes for "ABC". Again, I am not entirely sure it is possible but I haven't been able to find a way to get excel to sum it up for me.
Side note I could do it manually but the problem is that the data set is always changing so I need a formula that can recognize the similarities in each cell.
Try using Sumproduct. I am assuming that all of your Column A will start with the company name. (I.e. there won't be 'Company XYZ', only 'XYZ [...]'. If this isn't always going to be the case, let me know.
Does this work? I assumed Company is Col. A, Value is Col. B - going to row 7.
=SUMPRODUCT(--(LEFT($A$2:$A$7,LEN(E2))=E2),--($B$2:$B$7>=25),$B$2:$B$7)
So, if a cell has "XYZ" as company, and the "Value" for that row is 25 or greater, it'll add together. The XYZ cell equates to 65, and you can see the ABC correctly calculates 39.
edit: Here's a screenshot, using named ranges to maybe make it easier to see what goes where in the formula:
Yes try SUMPRODUCT it is great. Very simply, it look through column B which is the company names to match the left three characters in the name to what ever you type in cell E3 and sums the values in the value column.
=SUMPRODUCT(--(LEFT(B4:B9,3)=E3)*1,C4:C9)

how to create new list in excel after comparing duplicates for unique values

I have a excel problem which has been racking my brain.
I have a list of 1740 student names on a master list (ML) and 956 student's names (PT) who took their yearbook photos. I need to compare the two to form a new list (NL) that I can export into a text file to import into a InDesign file for a no-picture list.
Also, the names in J and K are not side by side but might be shifted in some areas. They are also in different cases one is upper and the other is proper. They are also full names [First Last].
I've tried working with if and countif functions with no avail.
I want to do this:
(ML) (PT) (NL)
J K M
1 Alex James Alex
2 James Alex John
3 John Jason Jamie
4 Lexie Lexie
5 Jamie Austin
6 Austin
7 Alex
I need at least a solution that can give me a new list that can be alphabetized eventually by their surname if it requires more steps however if it can be achieved in a single function that would be great.
A single formula that addresses the end requirement might be possible, but it would be a nasty formula indeed. A couple simple formulae and short workflow might suffice:
In a blank column e.g. M2 write formula
=VLOOKUP(J2,K:K,1,FALSE)
and fill down as far as values go in column J. The result will be #N/A wherever there is no match--these are the people with no picture. VLOOKUP will ignore case differences, and the formula doesn't care if the matching name is on a different row.
Since you want to order by surname you will need a way to get that information out of the [First Last] format. In another blank column, write formula
=MID(J2,FIND(" ",J2,1)+1,30)
and again fill down.
The whole thing can now be sorted on two keys: primary on the VLOOKUP column, and secondary on the surname column. The #N/A people will sort to the bottom of the list, making the full names easy to copy off for further processing.
Edit: In pictures:
Step 1: I added surnames because that's the real use case. Note there are two different people named "Alex". Now add the formulae I gave above (shown in red here):
Step 2: Sort the range as described above.
Step 3: The people shaded in green are not in the PT column. We know this because the lookup column returned #N/A. Also, their names are sorted by surname.
Hope this helps to clarify.

Sorting text and numbers in Excel

I got list of created ranges. What I want to do is sort them ascending by cell numbers they are refering to. I tried using sort option but all I came up with is to create my own sorting list...
List of ranges:
Column 1 Column 2
pp2dni2007 =szkolenia!$B$2:$E$33
pp2dni2010 =szkolenia!$B$273:$E$500
pp3dni2008 =szkolenia!$B$34:$E$83
pp3dni2009 =szkolenia!$B$84:$E$272
Desired output:
Column 1 Column 2
pp2dni2007 =szkolenia!$B$2:$E$33
pp3dni2008 =szkolenia!$B$34:$E$83
pp3dni2009 =szkolenia!$B$84:$E$272
pp2dni2010 =szkolenia!$B$273:$E$500
Here is a way (although a bit ugly).
Suppose a set up like this:
Step 1:
Place the cursor to C1 and go to Formulas --> Define Name. Define the following name:
We need to use this function to get the formula of each cell in column B because we will sort based on this formula.
Step 2:
At cell C1 enter and fill down:
=LEFT(SUBSTITUTE(GET_FORMULA,"=szkolenia!R",""),FIND("C",SUBSTITUTE(GET_FORMULA,"=szkolenia!R",""))-1)
broken down for convenience:
=LEFT(SUBSTITUTE(GET_FORMULA,"=szkolenia!R",""),
FIND("C",SUBSTITUTE(GET_FORMULA,"=szkolenia!R",""))-1)
This basically returns the row number of the reference that is stored in GET_FORMULA.
Step 3:
Select columns A, B and C and sort based on column C:
Result:
Or with formulas:
Notes:
The file has to be saved as macro-enabled in order to make the GET_FORMULA name work.
I do not really like helper columns (like column C above) but in this case things would overcomplicate without it.
I hope this helps, although it is a really ugly solution..
When I read loannis solution I came up with another solution to my problem ;)
Forgot to tell: column 2 data isn't importaat when comes to data but it is a hint on how to sort.
Okay, so it looks like that:
Column 1 Column 2
pp2dni2007 =szkolenia!$B$2:$E$33
pp2dni2010 =szkolenia!$B$273:$E$500
pp3dni2008 =szkolenia!$B$34:$E$83
pp3dni2009 =szkolenia!$B$84:$E$272
We got this data, so what is pain in here is this hard data "=szkoleni...".
To sort it out easy all is needed is to get rid of it. Using find&replace I am deleting "=szkolenia!$B$" part and then using it once again I am deleting rest of it ":*".
Now columns look like that:
Column 1 Column 2
pp2dni2007 2
pp2dni2010 273
pp3dni2008 34
pp3dni2009 84
Now it's just a case of simple sorting and voila! It can be easily used via macro too ;)
Thanks loannis, you were my inspiration ;)
Sort&Filter
Reference Link
http://office.microsoft.com/en-us/excel-help/sort-data-in-a-range-or-table-HP010073947.aspx

Exceptions in Excel calculated columns

(Alternate title: Why on earth doesn't Excel support user-defined formulas with parameters without resorting to VB and the problems that entails?).
[ Updated to clarify my question ]
In excel when you define a table it will tend to automatically replicate a formula in a column. This is very much like "fill down".
But ... what if you need exceptions to the rule?
In the tables I'm building to do some calculations the first row tends to be "special" in some way. So, I want the auto-fill down, but just not on the first row, or not on cells marked as custom. The Excel docs mention exceptions in computed columns but only in reference to finding them and eliminating them.
For example, first row is computing the initial value
The all the remaining rows compute some incremental change.
A trivial example - a table of 1 column and 4 rows:
A
1 Number
2 =42
3 =A2+1
4 =A3+1
The first formula must be different than the rest.
This creates a simple numbered list with A2=42, A3=43, A4=44.
But now, say I'd like to change it to be incremented by 2 instead of 1.
If I edit A3 to be "A2+2", Excel changes the table to be:
A
1 Number
2 =A1+2
3 =A2+2
4 =A3+2
Which of course is busted -- it should allow A2 to continue to be a special case.
Isn't this (exceptions - particularly in the first row of a table) an incredibly common requirement?
If you have the data formatted as a table you can use table formulas (eg [#ABC]) instead of A1 format (eg A1, $C2 etc). But there are 2 tricks to account for.
Firstly there is no table formula syntax for the previous row, instead excel will default back to A1 format, but you can use the offset formula to move you current cell to the previous row as shown below. However in this case it will return an # value error since I cant +1 to "ABC".
ABC
1 =OFFSET([#ABC],-1,0)+1
2 =OFFSET([#ABC],-1,0)+1
3 =OFFSET([#ABC],-1,0)+1
4 ....
So the second trick is to use a if statement to intialise the value, buy checking if the previous row value = heading value. If the same use the initial value else add the increment. Note assumes table is named Table1
ABC
1 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],42,OFFSET([#ABC],-1,0)+1)
2 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],42,OFFSET([#ABC],-1,0)+1)
3 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],42,OFFSET([#ABC],-1,0)+1)
4 ....
Note you can set the initial value to be a cell outside the table to define the initial value (in say $A$1) and increment (in say $A$2) as below
ABC
1 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],$A$1,OFFSET([#ABC],-1,0)+$A$2)
2 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],$A$1,OFFSET([#ABC],-1,0)+$A$2)
3 =IF(OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]],$A$1,OFFSET([#ABC],-1,0)+$A$2)
4 ....
I use this IF OFFSET combination all the time for iterating and looping in tables.
If you have alot of columns that need to determine if they are the first row you can have one column test if first row and the rest can work with a simpler if. eg ABC will give true for first row false for others, then DEF with increment the initial value
ABC DEF
1 =OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]] =IF([#ABC],$A$1,OFFSET([#DEF],-1,0)+$A$2)
2 =OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]] =IF([#ABC],$A$1,OFFSET([#DEF],-1,0)+$A$2)
3 =OFFSET([#ABC],-1,0)=Table1[[#Headers],[ABC]] =IF([#ABC],$A$1,OFFSET([#DEF],-1,0)+$A$2)
4 ....
Hope that helps
I don't know if you are looking for something as simple as locking down a formula. You can do that by highlighting the part of the formula you do not want to change and then hitting F4. This will absolute this section of the formila, using a $ to indicate it, and will not change as you copy/paste it down the table.
Alternately, you may be able to use Defined Names. These you can set up in the Data tab and basically assigns something to a name or variable you can then put into your formulas. These can be as simple as an easy reference for a cell on another sheet to incredibly complex multi-sheet formals.
Normally, to handle "exceptional" formula in the first row of a table consiting of several columns, you simply enter it there manually, and fill only the lines below. But if you have more "exceptional" cases scattered around, you will need another column with 0/1 values indicating where the exceptins are. And then you use if(condition, formula_if_true, formula_if_false) everywhere.
A B
Number Exceptional?
1 if(C1,42,A1+1) 0
2 if(C2,42,A2+1) 1
3 if(C3,42,A3+1) 0
As much as I love Excel, and as much as it is the best product of whole MS, it is still a weak tool. FYI, you can quiclky learn modern and poweful scripting languages, such as Ruby, here, and never be bothered by spreadsheet idiosyncrasies again.

Resources