Compare two columns in excel - excel

Hey, I have an excel document with columns A and B. Row A has 2595 values. Row B has 411 values.
I'm trying to figure out how I can compare these two columns by marking column C with the number of times we find a value(s) from row a.
For Example
COLUMN A COLUMN B COLUMN C
1 1 1 (because we have one value of 1 from column A)
2 2 1 (because we have one value of 2 from column A)
3 3 2 (because we have 2 threes from column A)
3 4
4 5
5 6 2 (because there are two 6's in column A)
6 7 0 (because there are no 7's in column A)
6
I'm sure you can see where I'm going with this but for the life of me I cannot figure out how to do this, I've been searching around all morning. Help!
If needed I can supply the excel document.

You can use the COUNTIF function
Column A Column B Column C Answer
1 1 =COUNTIF($A$2:$A$9,B2) [1]
2 2 =COUNTIF($A$2:$A$9,B3) [1]
3 3 =COUNTIF($A$2:$A$9,B4) [2]
3 5 =COUNTIF($A$2:$A$9,B5) [1]
4 6 =COUNTIF($A$2:$A$9,B6) [2]
5 7 =COUNTIF($A$2:$A$9,B7) [0]
6
6

You can use COUNTIF. If A1:A8 is your search criteria, B1 is the value you're currently processing, C1 would be:
=COUNTIF(A1:A8;B1)

Related

Excel Data convert from single row to multiple row

I have data in excel in following manner.
Colname Count
A 5
B 3
C 4
I want to convert it into this way.
A 1
A 2
A 3
A 4
A 5
B 1
B 2
B 3
C 1
C 2
C 3
C 4
Based on the count i want that data must be converted into rows with increasing order. Please let me know the feasiblity .
=IF(ROW()<B$1+1,"A",IF(AND(ROW()>B$1,ROW()<SUM(B$1:B$2)+1),"B",IF(AND(ROW()>SUM(B$1:B$2),ROW()<SUM(B$1:B$3)+1),"C",""))) in F1 and fill down. In G1, this formula =IF(COUNTA(F1)>0,COUNTIF(F$1:F1,F1),"") and fill down. Letters are in Column A and numbers in Column B. I chose these columns randomly to work a solution. Change to match your actual data, if needed.

Excel formula to return last xth numeric value from row

I have a data set like this:
a 1 2 3 5 6 7
b 5 1 3 4
c 7 4 3 2 6
d 1 2 3 7
e 7 5 5 6 7
which i want to transform in excel to only show the last 4 numeric values for each row, i.e.
a 3 5 6 7
b 5 1 3 4
c 4 3 2 6
d 1 2 3 7
e 5 5 6 7
Ive managed to use =INDEX(row1,MATCH(9.99999999999999E+307,row1)) which correctly returns the last value (i.e. 7 for row1 in this case) but how could i get the 2nd last, 3rd last, 4th last etc?
With a in A1, in M1 copied across and down to suit:
=MID(RIGHT($B1&$C1&$D1&$E1&$F1&$G1&$H1&$I1&$J1,4),COLUMN()-12,1)
then hide ColumnsB:L.
(Only works for single digits, as shown. Recent versions of Excel may offer better options.)
So I managed to figure out how to do this generically for any digits:
Say your original numerical data is in cells D5:N9.
OPTIONAL:
If any of the rows of data contain the same value twice create a copy in cells D13:N17 which amends duplicates slightly by using in D13 and dragging to fill
=IF(D5="","",D5+0.0001*(COUNTIF($D5:D5,D5)-1))
Then in cells A13:A17 enter values 13,14,15,16,17
and in cells A20:A29 enter values D, E, F, G, H, I, J, K, L, M
In Cell D20 you can return the last from row 13 value using:
=LOOKUP(9.99999999E+307,D13:N13)
and copy this down for each row.
In Cell E20 you can return the 2nd last entry using
=LOOKUP(9.99999999E+307,$D13:INDIRECT(CONCATENATE(INDEX($A$20:$A$29,MATCH(D20,$D13:$N13,0)-1),$A13)))
and copy this down for each row and drag it across to H24 to fill in all the values for 3rd last, 4th last and 5th last for each row.

Summing a set of values based on cell content and row position

In the below table rows 2,3 and 4 have some details of a sporting event.
Range A2:C4 has a set of squad numbers and range D2:F4 has the details of who scored goals.
A B C D E F
1 Squad # Scorers
2 1 3 6 2 8 3
3 3 6 7 6 1
4 1 5 6 7 2 4
As an example squad # 6 has scored 8 goals based on the values equivalent position in the Squad section and relative to the Scorers range.
What formula will give me this total value and the equivalent total values for all squad numbers like the table below?
Some cells will be empty like F3.
1 9
3 14
5 2
6 8
7 0
A simple SUMPRODUCT function should take care of this.
=SUMPRODUCT($D$2:$F$4, --($A$2:$C$4=H2))
Fill down as necessary.
        
With only 3 games, the simplest way that I can see to do this would be to use 4 SUMIFS statements, as follows [assumes that your results data is in columns A & B, starting at row 5 and moving down; A5:A12 would hold the IDs for the different squads, and this formula would go in B5 and be copied down]:
=SUMIFS($D$2:$F$2,$A$2:$C$2,A5)+SUMIFS($D$3:$F$3,$A$3:$C$3,A5)+SUMIFS($D$4:$F$4,$A$4:$C$4,A5)
What it does is sum columns D:F, for row 1, row 2, and row 3, based on the fact that columns A:C for those rows match the appropriate squad ID.
This would be possible with an arguably shorter but more complex Array Formula, but with the data as you've presented it, I feel this is the clearest method.

Find maximum of row, return column name

I have four rows and six columns of random numbers between 1 and 10. The headers atop are named A through F accordingly. I want to populate a range (A1:A6) on another sheet with the maximum number for each row. That is easy with the MAX function. However, in a another range (B1:B6), I want to put the column name to which this number belongs.
An HLOOKUP() won't work because a maximum value in one row is likely not unique number across the entire sheet. I am thinking a MATCH INDEX type function, but my understanding of those functions, especially in conjunction, is poor.
A B C D E F
1 0 2 10 9 8
9 3 7 6 9 10
10 3 0 2 1 4
9 4 7 8 6 3
Assuming your array is in Sheet1 and the columns are labelled, please try in another sheet, copied down to suit (to Row4 since there are only four rows of numbers in your data):
=INDEX(Sheet1!A$1:F$1,MATCH(MAX(Sheet1!A2:F2),Sheet1!A2:F2,0))
This will return only the first column label from a row where the maximum for that row occurs more than once.

Return list of matching rows

Sheet1
A B C D
1 2 3 4
2 4 5 6
3 3 5 6
4 7 3 1
5 4 6 7
Sheet 2
A B C D
1 4
2 1
3 1 3 4
4 1 2 5
5 2 3
6 2 3 5
7 4 5
Column A of Sheet 2 has a non repeating listing of all values in Sheet 1. I would like a forumla so Col B of Sheet 2 lists the value of Sheet 1 Col A for each row where the Sheet 2 Col A lookup value is found. Either giving me a comma sep list or putting the results in sheet 2 Col B,C,D,...
I came up with a solution, but it involves a handful of formulas, not just one. Hopefully, you will still find it useful.
Your Sheet2 would basically look like this:
Here are the formulas you need to enter:
B1: =IFERROR(SMALL($G4:$U4,COLUMN()-1),"") [drag down and across to D7]
G1: =IF(F2=$W2,F1+1,MAX(1,F1)) [drag across to U1]
G2: =IF(F2=$W2,1,F2+1) [drag across to U2]
G3: =INDEX(Sheet1!B$1:D$5,G1,G2) [drag across to U3]
G4: =IF(G$3=$F4,G$1,"") [drag down and across to U10]
What this does is organize the Sheet1 data into rows, where each row corresponds to a lookup value. Then, it grabs the smallest value, the second smallest value (if one exists), and third smallest value (if one exists) from each row.
This should be easy to scale to as large a spreadsheet as you need (as long as you don't run out of columns).

Resources