Excel lookup query - excel

I'm not all that with excel and this is driving me nuts. I have a table with 3 columns A B C.
A has up to 150 names.
B has their chosen number from 0-9.
C has 5 random numbers entered from 0-9.
After the numbers have been entered in C, I need to find who in A has a match to the numbers in C and how many times.
I.E:
Bill 7
Mary 4
in C-- 2 7 5 4 4
Results need to show (could be on another sheet):
Bill 1
Mary 2
have spent hours googling, but either can't find help, or I'm too stupid to see it.

You can use COUNTIF to do that.
You can copy/paste to get the name list to the other sheet first.
Then, use:
=COUNTIF(Sheet1!C:C, VLOOKUP(A1, Sheet1!A:B, 2, 0)))
Or if you are able to copy both columns A and B into Sheet2,
=COUNTIF(Sheet1!C:C, B1)
Then copy/paste as values and last delete column B.
If it can be done on the same sheet, you can consider:
=COUNTIF($C$1:$C$5, B1)

Related

How to find and replace from a List in Excel

Not using VBA but just simple excel, can anyone help me find a solution to this problem? Would greatly appreciate it!
I have a list of Names in Sheet 1 like below
-
A
1
sp_abc_Rick
2
sp_abc_Jabba_the
3
sp_abc_Dany
4
sp_random_Rick
5
sp_random_Jabba_the
6
sp_random_Dany
7
sp_constant
8
sp_ripley_art_Dany
9
sp_ripley_art_Jabba_the
10
sp_wakeup
I have a list of Mapping Table in Sheet 2 like below
-
A
B
1
Rick
Morty
2
Jabba_the
Hutt
3
Dany
Dragon
I wish to have a result in Sheet 1, in column B, like below
-
A
B
1
sp_abc_Rick
sp_abc_Morty
2
sp_abc_Jabba_the
sp_abc_Hutt
3
sp_abc_Dany
sp_abc_Dragon
4
sp_random_Rick
sp_random_Morty
5
sp_random_Jabba_the
sp_random_Hutt
6
sp_random_Dany
sp_random_Dragon
7
sp_constant
sp_constant
8
sp_ripley_art_Dany
sp_ripley_art_Dragon
9
sp_ripley_art_Jabba_the
sp_ripley_art_Hutt
10
sp_wakeup
sp_wakeup
To give you a context of the number of rows. Sheet 1 will be bigger with more than 1000 rows. Sheet 2 (Mapping Table) is constant set of rows. Currently it is about 100 rows.
You can use a formula like shown below using LOOKUP(), SEARCH() with SUBSTITUTE()
• Formula used in cell B1
=IFERROR(SUBSTITUTE(A1,LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$D$1:$D$3),
LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$E$1:$E$3)),A1)
There you go. There may have other better solution. This is what I got.
All in column B.
=IFERROR(CONCAT(MID(A1,1,MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)-1),INDIRECT(CONCAT("sheet2!b", MATCH(MID(A1, MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE), LEN(A1)), Sheet2!$A$1:Sheet2!$A$300, 0)))),A1)
Break down is as follow;
Let's start put things from Column C onward.
Column C, to find the index of the first capital letter from the text.
ref: http://dailydoseofexcel.com/archives/2007/02/21/find-position-of-first-capital-letter-in-a-string/
=MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)
Column D, cut the name part by using upper case letter index from column C, sp_abc_Jabba_the -> Jabba_the
=MID(A1, C1, LEN(A1))
Column E, search row number from Sheet2 by matching Column D's name with Sheet 2's Column A, this will get matching row number from Sheet2.
=MATCH(D1, Sheet2!$A$1:Sheet2!$A$300, 0)
Column F, get Sheet2's Column B value by the row number from Column E.
=INDIRECT(CONCAT("sheet2!b", E1))
Column G,
Cut "sp_abc_" from "sp_abc_Rick"
Concat "sp_abc_" with Column F's "Morty".
If there is any error, use Column A value as default.
. <- this dot is intentional. please ignore.
=IFERROR(CONCAT(MID(A1,1,C1-1),F1),A1)
Try:
Formula in B1:
=BYROW(A1:A10,LAMBDA(a,LET(b,TEXTBEFORE(a&"|","_"&A12:A14&"|",-1),IFERROR(CONCAT(IF(b&"_"&A12:A14=a,b&"_"&B12:B14,"")),a))))
The concatenation with a "|" would assert we only replace values when at the exact end of the input. Just in case there would be a stray (for example) 'Rick' somewhere before the end.

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

Assign one value at the time from a column i Excel if the value is the same

I got some help with a problem finding column values in Excel: Find column value Excel
The table looks like this:
A 17 8,5 5,666666667 4,25 3,4 2,833333333 2,428571429
B 5 2,5 1,666666667 1,25 1 0,833333333 0,714285714
C 5 2,5 1,666666667 1,25 1 0,833333333 0,714285714
G 4 2 1,333333333 1 0,8 0,666666667 0,571428571
The code that I got help with basically selects A, B, C and G based of the order of the largest numeric value. The largest value is 17, that is one point for A, then comes 8,5 which gives another point for A. That works fine.
However, then comes 5. I now get B two times instead of first B and the C (the order does not matter, but I do not want to get two points for B when B and C have the same value). How can this be fixed?
(The real problem that this example illustrates is the number of seats on local boards in Swedish multiplicitets, where the number of seats for the different parties is based on the number of seats in the city council.)
Edit: Formula: =INDEX($J$16:$J$25,AGGREGATE(14,6,ROW($K$16:$W$25)/(K28=$K$16:$W$25),1)-ROW($J$16)+1)
Edit2: Wanted result:
Mandate Party
1 A
2 A
3 A
4 B
5 C
To do this by formulas, I think a simple way is to
unpivot the original data using formulas
Apply a unique rank formula to that data
Then use VLOOKUP to return ranks 1-n
The following formulas and defined names will be useful
origTbl =Sheet2!$A$1:$H$4
unpivotTbl =Sheet2!$A$8:$C$35
A8 =RANK(C8,$C$8:$C$35,0)+COUNTIF($C$8:C8,C8)-1
B8 =INDEX(origTbl,INT((ROWS($1:1)-1)/7)+1,1)
C8 =INDEX(origTbl,INT((ROWS($1:1)-1)/7)+1,MOD(7+ROWS($1:1)-1,7)+2)
Fill down A8:C8 to row 35
In the formulas in B8 and C8, the 7 is the number of columns in origTbl minus 1 (eg: COLUMNS(origTbl)-1)
Any changes you make in origTbl will be reflected in the final table
For appearances, you can certainly hide the UnPivot table someplace.
Note: in my locale, decimal separator is the dot

Sumproduct matching values in excel

I have two excel tables:
A B C D E
1 John 10 Mark 2
2 Tommy 20 Tommy 3
3 Jane 15 John 4
4 Kate 2
5 Jane 1
Is there a function to sumproduct values in colum B with those values in column E which match by name, i.e. 10*4 + 20*3 + 15*1 ?
You can use sumif for this and just sum up the results when you are done:
=B1 * sumif(D:D, A1, E:E)
Copy that down your sheet, and then add up the totals.
If you don't want a ton of formulas hanging out on your sheet, you could convert this to a CSE/Array formula:
=SUM($B$1:$B$3*SUMIF(D:D, $A$1:$A$3,E:E ))
Just enter that in and hit Ctrl+Shift+Enter to enter it. It will get curly braces around it, which means it's an Array formula.
Since you asked about sumproduct, we could use SUMPRODUCT
=SUMPRODUCT(($A$1:$A$5=A1)*$B$1:$B$5)*SUMPRODUCT(($D$1:$D$5=A1)*$E$1:$E$5)
Now that is assuming there are no repeats (all names are unique). In the event that names are not unique you will have those numbers added together then multiplied.
After you apply that to a column and copied down appropriately, lets say F1 to F3, in F5 you could get your final answer using:
=SUM(F1:F3)

Excel line up data

I'm a total Excel nub and can't find the answer I'm looking for. Must be easy peasy, but since I'm not into Excel I also don't know what to look for. Sorry if I'm having my question wrong.
I have output in Excel like this:
A 1
A 2
A 3
A 4
B 1
B 2
B 3
B 4
B 5
B 6
and I want it like this:
A 1 2 3 4
B 1 2 3 4 5 6
this question is quite complex in a way.
let me explain it more in detail:
as you see above, we have two columns A and B, you have text strings in column A , these text strings could be repeated. As you see in the example, there are 4 As, 5 Bs, 3 Cs 1 D and 3 Es. In column B each one of these strings have different corresponding values. For example, text strings B in column A has five corresponding values in column B, namely 11, 12, 13, 14, 15, and 16.
Now we want a list of UNIQUE values from column A, and lets say, we put this list in column C and then for each of these unique values in column C we want to list their corresponding cells in column B and put them HORIZONTALLY in front of each of these unique text strings in column C.
For this you need two kinds of formulas:
Formula 1 to calculate the list of the unique values in column A :
this goes in C2:(leave C1 empty)
=IFERROR(INDEX($A$1:$A$999;MATCH(0;FREQUENCY(IF(EXACT($A$1:$A$999;TRANSPOSE($C$1:C1));MATCH(ROW($A$1:$A$999);ROW($A$1:$A$999)); ""); MATCH(ROW($A$1:$A$999);ROW($A$1:$A$999))); 0)); "")
this is an array formula, so press ctrl+shift+enter to calculate the formula, and drag and fill down as many as you want in column C.
*Formula 2 to find and list horizontally the values from column B *
=IFERROR(INDEX($B$1:$B$999;SMALL(IF($C2=$A$1:$A$999;ROW($A$1:$A$999)-ROW($A$1)+1);COLUMN(A$1)));"")
this is an array formula, so press ctrl+shift+enter to calculate the formula, put this in D2 and drag and fill down until the last cell of column C. then select D2 to D6 and drag and fill horizontally. You should get all of the corresponding cells in front of each unique item.
P.S. adjust the formulas to meet your regional settings by replacing ; with , I suppose.
Finally here is the link to an example sheet downloadable from here .
This is very generic but hopefully will help.
Highlight the cells that you want to transpose to.
Type the equation..."=TRANSPOSE(B1:B4)" (edit as necessary).
While the cells are still highlighted, press "ctrl+shift+enter". (brackets should appear around the equation)
Finish editing the cells.
Celebrate

Resources