Excel create a group id based on string column - excel

I want excel to create column B. Basically an arbitary id for each "level of A". in Stata this would be egen groupid = group(A) or in R you could use dplyrs group_indices(). Whats the best way to do it in Excel? Preferably a non-VBA solution.

Formulas for these situations are better when the first row holds unrelated column labels instead of data.
For your situation, put a 1 in B1 then this formula in B2 and drag down.
=IFERROR(VLOOKUP(A2, A$1:B1, 2, FALSE),SUMPRODUCT(1/COUNTIF(A$1:A2,A$1:A2&"")))

Related

excel how to use index and match to match the data

Morning,
My fault, let me converted to English.
My concern is that I do not know how to connect table_1's category with the table_2's column and then found the correct color
You need to use either the VLOOKUP or HLOOKUP feature when structuring your results table. For instance in cell C3 (color for head/set1) you would type =HLOOKUP(a2,e2:h5,2,FALSE). It will look horizontally in the first row for whatever is in cell A2 (HEAD) and return the value from the 2nd row (RED). Of flip it around to use HLOOKUP.
https://support.office.com/en-us/article/hlookup-function-a3034eec-b719-4ba3-bb65-e1ad662ed95f
Please try this formula, to be entered in row 3 where columns A and B are "category" and "Sets" respectively.
=VLOOKUP(B3,E1:H4,MATCH(A3,E1:H1,0),FALSE)
E1:H4 represents your entire table2 incl captions. You can exclude the caption row - probably better. E1:H4 is the first row of that same range. There is presumed to be only one caption row which is needed, and must be 1 only. If you prefer a neater solution take the data column captions only and adjust the result. Then your formula might look like this.
=VLOOKUP(B2,E2:H4,MATCH(A2,F1:H1,0)+1,FALSE)

Excel complicated count function

I have kind of a complicated count I can't seem to figure out. Basically I have a table that looks similar to this image:
Now what I need to do is:
Tally the number of 1's if the category = "Anon" in one cell, then count the number of 2's and 3's in separate cells all if the category = "Anon".
Wash/Rinse/Repeat for if it's "Watterson" and "Davis".
Is there any way I can count the occurrences of 1|2|3 and have it separated by category like this?
Sorry, kind of an Excel noob here. I didn't think pivot tables would be correct though (especially because they want the dates to be columns, plus I couldn't figure out how to insert a conditional). Any pointers in the right direction would be appreciated.
Let's suppose that your screenshot shows cells A1:I6.
Then ...
Add column headings "1", "2", "3" in cells J1:L1
Put the formula =COUNTIF($C2:$I2,J$1) into J2 and copy it across and down
Set up a list of unique Categories (Anon, Watterson etc) starting in A10
Add headings in row 9 like "Category", "Tally of 1s", "Tally of 2s", "Tally of 3s"
Put the formula =SUMIF($B$2:$B$6,$A10,J$2:J$6) into B10 and copy it across and down
My guess is that someone cleverer than I could construct a sumproduct formula for B10 that works without the need for the helper columns J:L.
[Edit] Using Maki's sumproduct formula in my structure, you can scrap helper values in cols J:I and put this into B10 -- =SUMPRODUCT(($B$2:$B$6=$A10)*($C$2:$I$6=B$9))
assuming that you start from cell A1,
=SUMPRODUCT((list name to search for)*(value to search in the data area))
=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=1))
=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=2))
...
=SUMPRODUCT(($B$2:$B$6="Watterson")*($C$2:$I$6=1))
...etc.

Value between or search in range and return value in excel

Hi All,
I have a table for employee scores levels (Table D1 to F6), there is points for each level, for example score (4.60) will be in the 3rd level which has (3) points.
I want to write a formula in the column (B) to check in the table an return the point value from the column F, You can see the examples in D2 & D3.
Regards
Adel
What you need is one of the most awesome functions ever invented... VLOOKUP
=VLOOKUP(A2,$D$2:$F$6,3, TRUE)
(Paste in B2 and drag down)
Quick explanation of the arguments.
A2 is the value we're going to be looking up in the table
$D$2:$F$6 is the "table" we're going to be looking up. It's going to search the first column of it (You could have anything you wanted in Column D, VLOOKUP Only looks at the first column).
3 is the column number of our table that contains the answers we want to be looking up, and returning (in this case, F).
TRUE means we want to search ranges, not just exact values. If it was FALSE then we'd only get the numbers we wanted if we entered the precise scores.
Of course, using this method, there isn't any upper bounds to it, a value of say 20 would give us the last row (i.e. 5 points), however, you could fix this easily using an IF statement.
=IF(A2 > $E$6, "N/A", VLOOKUP(A2,$D$2:$F$6,3, TRUE))
This could of course be done a bit neater if you believed you were going to be adding more rows to the table later, but it works for now.
Use the Below formula in cell B2:
=VLOOKUP(A2,$D$2:$F$6,3, TRUE)

Excel Lookup Formula with Two Conditions

Sorry about the heading but im finding it hard to explain so ill give it my best shot.
Here is my problem
I have 3 cells: Lender, product and productID I have a vlookup that fills the lender and product cells just fine
However i want a way to bring back the productID back from another worksheet matching with lender and product.
For instance if call1 = newcastle and cell2 = 2 year fixed then cell3 = 422
I tried using a vlookup but doesnt seem to work, Any help on this would be greatly appreciated. Thanks
You can use Index and Match to perform a lookup with two criteria. Here is an example of one from http://blog.contextures.com/archives/2012/07/12/check-multiple-criteria-with-excel-index-and-match/
=INDEX($D$2:$D$10,MATCH(1,(A13=$B$2:$B$10)*(B13=$C$2:$C$10),0))
As mentioned on the site, it is an array formula so rather than just pressing enter when you use the formula, you need to hold Ctrl+Shift+Enter.
To break down how the formula is formatted:
=INDEX(a,MATCH(1,(b=c)*(d=e),0))
a = The whole range with all the data in it
b = The first criteria for the data to be filtered on
c = The range in which the first criteria needs to be searched
d = The second criteria for the data to be filtered on
e = The range in which the second criteria needs to be searched
Make sure that you use $ in the correct places as in the above example.
Another alternative to using combination of the MATCH and INDEX functions that some may find more straightforward is to first insert a column on your lookup table and concatenate the cobmination of columns you wish to search by.
=CONCATENATE(B8,C8)
Then you can still use the Vlookup function, but instead of only entering the one column to lookup on, you would combined them in the lookup so that the combination of them looks up to the combination of them on the lookup table.
=VLOOKUP(B3&C3,A9:D10,4,0)
Let's say that Newcastle is in A2 and 2 year fixed is in B2. It doesn't matter what worksheet they are on.In another worksheet named Data you have a table with a column of lenders in column X, products in column Y and product IDs in column Z. There are column labels in row 1 so the real data starts in row 2 and there are 2587 rows of data. In the first worksheet's C2 where you want the double lookup for a ProductID that matches Lende and Product try this formula.
=IFERROR(INDEX('Data'!$Z$2:$Z$9999, MIN(INDEX(ROW($1:$9998)+(('Data'!$X$2:$X$9999<>$A2)+('Data'!$Y$2:$Y$9999<>$B2))*1E99,,))), "no match")

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

Resources