Excel combining countifs and left function - excel

I have a list that I'm checking against the main data.
The main data looks like:
1234 1
1235 1
1234 1
1213 2
1231 2
1212 2
1231 3
1231 3
etc
The list I'm checking against the main data is:
1
2
3
etc
For each number in my list, I want to count how many start with 123, so the output looks like:
ID 123
1 3
2 1
3 2
etc
I have each ID in the list already. To drag down for each number, I currently have countifs(a1:a8, a1,b1:b8, "123") and it's obviously producing an error. I know I need to include left somewhere in here but I'm not sure where or how to. Much thanks.

In the Main Data sheet, add a column and enter formula as eg: C1=IF(LEFT(A1,3)="123",1,0). Drag the formula for every C cell. Then use that C cell in your SUMIFS in your list sheet eg: =SUMIFS(C:C,B:B,"="&E1) E col for me is your list.
Please refer screenshots below.
Identify begins with 123
sumifs to get the output
Edit:
Another Solution: =SUMPRODUCT(--(LEFT(Maindata!$A$1:$A$8,3)="123")*(Maindata!$B$1:$B$8=Maindata!D1)). This solution works fine to me.
sumproduct with --left

You can use someproduct to do this:
=sumproduct((Maindata!$A$1:$A$8=A1)*(left(Maindata!$B$1:$B$8)="123"))
Where A1 holds the digit you're determining the amount of "values that start with 123" for, and the main data is in worksheet Maindata, range A1:B8.

Is your data in the form of text or number values? If the former, your criteria should instead be "123*" (using an asterisk for wildcard), if the latter you might be able to get away with using ">1230".

Related

Find all values in Column A which are present in Column B

Consider the sheet below:
A
B
1
4
3
5
2
2
5
0
4
1
I want to find if there is a match for each row of column 1 with any row of column 2. So ideally this would give me:
A
B
C
1
4
Yes
3
5
No
2
2
Yes
5
0
Yes
4
1
Yes
As a first and simple step, I am using =MATCH(A2,B2:B6) to get the index of the match and then manually calling this across the rows to get something like this:
A
B
C
1
4
6
3
5
-
2
2
3
5
0
2
4
1
1
I am now having a problem:
I want to apply this for a row of 500 in A and 2000 in B. I was thinking of manually filling in the first few rows and then select and drag over the first 500 rows. This however does not work as for each subsequent cell, it just changes the formula to =MATCH(A(N +1),B2 + N:B6 + N) which gives me wrong values and at worst, just repeats the older pattern ahead.
Can anyone help me with how I can just use the MATCH function to find all the values in A that are present in B?
Let me continue where you arrived:
=MATCH(A2,B2:B6,0)
(You forgot the last zero)
This formula is correct, but it is also wrong.
???
Well, when you drag it down, you get:
=MATCH(A3,B3:B7,0)
This is not what you want: you want the search term (A2) to change into A3 but you want the search array (B2:B6) not to change. In order to get this done, you need to work with absolute references. This looks like this:
=MATCH(A2,B$2:B$6,0)
When you drag this down, this is what you get:
=MATCH(A3,B$2:B$6,0)
=> ok so far.
Problem now: you need to translate your current results (a number or #N/A) into "yes" or "no". This can be done in numerous ways, let me give you an example:
=IF(ISERROR(MATCH(A2,B$2:B$6,0)),"No","Yes")
One remark: there exists an IFERROR() function in Excel, but this does not have an "else"-clause, hence the choice for the IF(ISERROR( combination.
Within Sheets you may try this out:
=index(if(len(A2:A),if(ifna(xmatch(A2:A,B2:B)),"Yes","No"),))
If you want to separate those matching values then could use FILTER() function.
=FILTER(A1:A5,COUNTIFS(B1:B9,A1:A5))
And for YES, NO dynamically, try MAP() function.
=MAP(A1:A5,LAMBDA(x,ISNUMBER(XMATCH(x,B:B))))

Dynamically sort list based off associated values with tie-breaker values

I'm trying to sort students based off frequency of participation. I have a table that is automatically generated totaling up how often a student has participated in the last few days.
I want it to do 2 things that I can't figure out.
I want it to ignore students that are at 0 removing them from the resulting rankings.
The first number is most important but I want it to reference the next value in the result of a tie.
Short example of table:
Andy - 1 1 2 3
Brad - 0 1 2 3
Cade - 1 2 3 4
Dane - 1 1 1 2
Desired result:
Cade - 1
Andy - 1
Dane - 1
The tie-breaker isn't that important and I figure I can have conditional formatting to remove children at 0, but I still can't seem to figure it out.
The closest formulas I have found in my searching are:
=INDEX($A$10:$A$9,MATCH(ROWS($C$1:C1),$C$1:$C$9,0))
This one doesn't work because it returns #N/A for pretty much all students who are tied.
=IFERROR(INDEX($C$1:$C$9,MATCH(SMALL(NOT($C$1:$C$9="")*IF(ISNUMBER($C$1:$C$9),COUNTIF($C$1:$C$9,"<="&$C$1:$C$9),COUNTIF($C$1:$C$9,"<="&$C$1:$C$9)+SUM(--ISNUMBER($C$1:$C$9))),ROWS($C$1:C1)+SUM(--ISBLANK($C$1:$C$9))),NOT($C$1:$C$9="")*IF(ISNUMBER($C$1:$C$9),COUNTIF($C$1:$C$9,"<="&$C$1:$C$9),COUNTIF($C$1:$C$9,"<="&$C$1:$C$9)+SUM(--ISNUMBER($C$1:$C$9))),0)),"")
I had this formula that can handle ties but it needs to be OFFSET but I don't know how since it is an array formula. Also, with both these formulas it reverses the ranks with the lowest values at the top. If anyone could assist me I would greatly appreciate it. I'm doing this so that I can give all students a chance to participate equally.
Use a helper column. In that column put the following formula:
=IF(B1=0,"n/a",SUMPRODUCT(B1:E1/10^(COLUMN(B1:E1)-MIN(COLUMN(B1:E1)))))
This will return a single number based on the rankings.
Then in your output column use:
=IFERROR(INDEX(A:A,MATCH(LARGE(F:F,ROW(1:1)),F:F,0)),"")
Then a simple VLOOKUP to return the first number:
=IF(I1<>"",VLOOKUP(I1,A:B,2,FALSE),"")

Excel: sort names by given values

I had to do a little work with excel but I am stuck at the following point:
A B C D E F ....
1
2
3 "A" 1
4 "B" 0
5 "C" 1
6 "D" 2
7
8
9
My table looks something like this.
In B3:B6 I do have 4 names, in C3:C6, I do have the corresponding scores.
Now, I would like to order the names by their given points and display them in E3:E6
I am not that familiar with excel so I am very happy for any help.
Greetings,
Finn
First get the numbers in order with Large Function:
=LARGE($C$3:$C$6,ROW(A1))
Put that in F3 and copy down 4. It will list the numbers in order.
Then in E3 put this formula:
=INDEX(B:B,AGGREGATE(15,6,ROW($C$3:$C$6)/($C$3:$C$6=F3),COUNTIF($F$3:F3,F3)))
Which looks up the corresponding name.

Excel sort data in newspaper style columns

I have an excel sheet that has names and extension numbers. The sheet is designed to be printed as a reference and so it has the data split into 3 columns like how a newspaper is laid out.
EXT Name EXT Name EXT Name
1 bob 4 pete 8 sam
2 dave 5 sally 9 john
I need to have excel sort this data on name, A-Z. I can only work out how to make it sort one column at a time and so I end up having to manaually sort the data every time I add or remove information.
Can excel sort all 3 columns top to bottom and left to right?
Thanks!
Maybe this KB artikel helps.
Or u can try using the small function like
Column A
=SMALL($A$1:$A$9;0+ROWS(A$1:A1))
Column C
=SMALL($A$1:$A$9;30+ROWS(A$1:A1))
In this case you clone the sorted dataset, which is in two columns
The value for the B colums can be found using a vlookup. the value 0 and zero are an offset, so the length of the page is fixed

Excel: filter table rows by specified column value

I have a table with first column as primary key. Ex:
id value1 value2
1 10 5
2 2 3
3 12 5
..
I also have a second list of id's I want to select, which can have repeated ids. Ex:
selectId
1
2
2
2
5
10
..
How can I "merge" the two tables (something like INNER JOIN) to obtain:
id value1 value2
1 10 5
2 2 3
2 2 3
2 2 3
5 99 99
10 22 22
..
I tried using 'Microsoft Query' from Data > Extern Data to join the two tables. The problem is that it seems it cannot handle tables with more than 256 columns.
Thanks
UPDATE:
Thanks, VLOOKUP works as intended.
However one problem is that if the row was found but that corresponding column was blank, this function returns 0 (where I expected it to return an empty cell), and since zero is a valid value, I have no way to differentiate between the two (blank and zero)?
Any help is appreciated..
If this is Excel -like the title says- just use vlookups.
Not very relational, but that's the Excel way.
Using the VLOOKUP function would get you the data in the layout you require.
If you are using Tables in Excel 2007, the formula would look like this based on the example below.
in cell B8
=VLOOKUP([selectId],Table1,2,FALSE)
in cell C8
=VLOOKUP([selectId],Table1,3,FALSE)
Lookup screenshot http://img208.imageshack.us/img208/1/lookupz.png
It is not clear where you store your data, but it looks like you have this problem, described on Microsoft site:
http://support.microsoft.com/kb/272729

Resources