Formula for finding matching values - excel

I have a table in excel that looks like this:
State Member DOL
MO LLC 1/1/2017
MO LLC 1/1/2017
MO TC 1/1/2017
IL TC 1/2/2017
IL LLC 1/1/2017
I am trying to use conditional formatting to highlight the whole row for any rows that have the same State, Member, and DOL value. In three seperate columns I am using a CountIf formula to find how many times each value is being used for each column: Example(=countif($A$1:$A$10,A1)). This is so that I can identify which rows have duplicates for each individual column. So in the above example my new table will look like this:
State Member DOL
3 3 4
3 3 4
3 2 4
2 2 1
2 3 4
I can't figure out what kind of formula I should use next to identify which rows are duplicates. In the example I showed, the first two rows should be the only ones highlighted because they are the only ones that have the same value for all three columns. Originally I thought that as long as all three columns have a value > than 1, then it's a duplicate. However, row's 3 and 5 in my example have duplicate values in each column, but the row itself is never actually a full duplicate. In the end, I would like some kind of formula that will give me this result in a column:
Is Duplicate
1
1
0
0
0
Anyone have any ideas?

Related

Create filter for a drop down list that groups several rows together

I have the following table:
A
B
C
1
Team
2
Team1
Working hours
10
3
Name
Ronald
4
Team2
Working hours
20
5
Name
Magda
6
Team1
Working hours
30
7
Name
John
Column (A2:A7) represents a dropdown list of {Team1, Team2}
Cell A1 selects the filter for that
I want now select in cell (A1) all data from Team1, to have a table looking like:
A
B
C
1
Team: Team1
2
Team1
Working hours
10
3
Name
Ronald
6
Team1
Working hours
30
7
Name
John
Does anyone know, if that is possible?
A solution would be, to fill every cell of column A with the Team value. However, this is not what I like
Another solution (I guess) is to connect these cells, but this makes it rather complicated if I want to add another attribute per team member (besides Working hours and Name)
I suggest you change your data orientation to be like this (check below picture):
I think it should do the job
How about the following?:
=IF(FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1))="","",FILTER(A2:C8,(A1:A7=E1)+(A2:A8=E1)))
This solution requires Office365.
The length of both ranges in the filter criteria need to be the same size (row numbers) as the range you want to filter. The range Just shifts (offsets) 1 row to have the second row showing.
Added an IF-argument to show blank cells as blank (they would appear as 0 otherwise).

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

Excel: How to add a column from other sheet based on a key column?

I have 2 list. Both have a lot of column. I would like to insert a column from Sheet2 to Sheet1 based on a ceratin key column. Also sheet2 have much more rows than sheet1 so it ll be inserted only partly and still there ll be elements with no matches. For an example:
Sheet1:
Names ID Car Color
John 1 Audi Empty
Andy 4 Toyota Empty
Mike 3 BMW Empty
Tony 2 Suzuki Empty
Sheet2:
ID Cost Color
6 200 Blue
3 200 Red
4 300 Green
5 100 Red
1 50 Black
I would like to get the "color" from Sheet2 to Sheet1 by using the "ID". Using Excel 2010. I suspect I need INDEX+MATCH combination, but the examples I can find are not detailed and more simple so I coudn't figure out how to use them.
How about inserting this formula on Column D in the first row, then dropping the formula down:
=VLOOKUP(B1,Sheet2!$1:$1048576,3,FALSE)
Or to find the column that contains "Color", use Index Match Match, as follows:
=INDEX(Sheet2!$1:$1048576,MATCH(Sheet1!B2,Sheet2!A:A,0),MATCH("Color",Sheet2!$1:$1,0))
This will find the value in Column B in Sheet2 and give you the row number, then it will find the Column that contains "Color" and return the Column number, with those two numbers Index will return your color.

Match criteria between two tables to find maximum date within a list

I have 2 tables of data, one is only 5 columns and the second is 100s of columns, but in simplistic terms they have the formatting below. Both are hundreds of rows long.
Table 1 (is sorted ascending, all columns)
A B C D E
1 Date TeamF Trans Name TeamT
2 date1 teamF1 trans1 name1 teamT1
3 date2 teamF2 trans2 name2 teamT2
4 date3 teamF3 trans3 name3 teamT3
5 date4 teamF4 trans4 name4 teamT4
6 date5 teamF5 trans5 name5 teamT5
Table 2 (not sorted in any manner)
A B C D E F G ,etc.
1 Team Game Date Opp NameA NameB NameC ,etc...
2 team1 game1 date1 opp1 statsA1 statsB1 statsC1 ,etc...
3 team2 game2 date2 opp2 statsA2 statsB2 statsC2 ,etc...
4 team3 game3 date3 opp3 statsA3 statsB3 statsC3 ,etc...
5 team4 game4 date4 opp4 statsA4 statsB4 statsC4 ,etc...
6 team5 game5 date5 opp5 statsA5 statsB5 statsC5 ,etc...
I've been trying to get the INDEX/MATCH formula I typically use (below) a little more sophisticated to avoid some errors I've been having in data processing. I'm trying to pull the TeamT name from Table 1 and populate the stats rows in Table 2, columns E and beyond. I do this based on a
match of Names between Table1 column D and Table 2 row 1
Dates in Table 1 being <= Dates in Table 2 column C
with the following formula
my current formula =INDEX(Table1!$A:$E,MATCH(1,(Table1!$D:$D=Table2!E$1)*(Table1!$A:$A<=Table2!$C2),0),5)
As you can probably see, if there are multiple dates in Table 1 that are less than C2, I only get the first one. What I'd really like is the maximum (newest one). I've been playing with MAX/IF statements and INDEX/MATCH/IF statements but can't get the proper result. Some examples of those failed tries are below
example 1
=MAX(IF(Table1!$D:$D=Table2!E$1,IF(Table1!$A:$A<=Table2!$C2,Table1!$E:$E)))
example 2
=INDEX(Table1!$E:$E,MATCH(MAX(IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2)),IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2),0))
Any help would be appreciated. I've tried many solutions I've found, but I'm still pulling my hair out on this one.
I also have a second variation of formula where I match dates based on Dates in Table 1 being >= Dates in Table 2 column C. In that case I want the minimum match (the oldest date). I'm assuming I'd simply use MIN instead of MAX for this?
If I understand you correctly, here I have the answer for your first question.
To make the sample easier, I put everything in one sheet. You can copy to the new sheet once you are happy with the result. That way you will have the working formula.
The array formula (click Ctrl + Shift + Enter together) I used from cell K2 is:
=IFERROR(INDEX($E$2:$E$11,MATCH(MAX(IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11)),IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11),0)),"")
You can drag this to the fields you need. Please note this to find the most current date. Because I am not 100% sure this is what you are looking for. Therefore, in my example from cell O2, I managed to find the latest row and the formula (regular formula) is:
=IFERROR(INDEX($E$2:$E$11,LOOKUP(2,1/(--($D$2:$D$11=O$1)*--($A$2:$A$11<$I2)),(ROW($E$2:$E$11)-ROW(O$1)))),"")
For the 2nd question, I will leave it to you to find out from these two and that should do the trick.
I worked this out myself with MAXIFS to find the max date and a multi-criteria VLOOKUP function
this finds the max date less than a current row based on a name match
=VLOOKUP(MAXIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,"<="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$E:$E),2,0)
the solution to a min date greater than the current row based on a name match is
=VLOOKUP(MINIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,">="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$B:$B),2,0)

Compare 6 columns and return non identical value

I think I need a macro for what I would like to accomplish. I have 3 columns on sheet 1 and 2, but I would like to compare them and return a list under sheet 3 that has no duplicates and keeps track of the changes.
Sheet1 (New):
Count State City
1 MO STL
2 MO STP
1 FL Tampa
1 FL Ft. L
Sheet2 (Old):
Count State City
7 MO STL
6 MO STP
5 FL Tampa
4 TX Hston
Sheet3:
State City CountNew CountOld
MO STL 1 7
MO STP 2 6
FL Tampa 1 5
FL Ft.L 1
TX Hston 4
So far what I have accomplished has not help me and I cant find any other case with a situation like this one. I was trying to do this through formulas, but quickly realized thatall I was able to do was transfer the values of the columns from sheet 1 and 2, to sheet 3. But I was not able to accommodate the cell values that differ (Houston and Fort Lauderdale).
Would appreciate any help.
Thanks!
An idea would be something along these lines for finding uniques with a State & City helper column or add more to check the 2 columns?
In sheet1 and sheet 2 have a = State & "_" & City
In Sheet 3, A1 you can have =Sheet1!A1
and in A2 you can have =Sheet2!A1
then filled down from A3, you can have the following array formula
=IFERROR(IFERROR(INDEX(Sheet1!$A2:$A$10,MATCH(0,COUNTIF(Sheet3!$A$1:$A2,Sheet1!$A2:$A$10),0),1),INDEX(Sheet2!$A2:$A$10,MATCH(0,COUNTIF(Sheet3!$A$1:$A2,Sheet2!$A2:$A$10),0),1)),"")
This will give you the uniques across the 2 tabs, for normal lookups off the unique helper columns

Resources