Excel Help - How to delete duplicates from multipe columns - excel

I am trying to configure a spreadsheet for payroll. In column A I have the employee name. In column B I have the amount of hours they worked. I currently have the sheet broken down by job title/ dept that a particular employee works. In column G I have my skilled employees names and have a formula to auto-populate their hours from column B if their names are found in column A (=VLOOKUP(G2,A:B,2,FALSE). I also have a formula in Column D and E that will take anyone with hours greater than 0 from A and B and paste them (=IF(B2>0,B2," ")). I am now looking for a formula that will delete employee name and hours from D and E if they are in columns G and H. An example of the spreadsheet is:
A B C D E F G H
1 Doe, John 8 Doe, John 8 Doe, John 8
2 Doe, Jane 8 Doe, Jane 8 Bee, Max 8
3 Roy, Bill 8 Roy, Bill 8
4 Bee, Max 8 Bee, Max 8

Assuming the formula for populating column D is =IF(B2>0,A2," ") one way to accomplish what you want is to amend that formula to read =IF(AND(B2>0,COUNTIFS(G:G,A2)<1),A2," "). Similarly amend the formula in column E to read =IF(AND(D2<>" ",B2>0),B2," ").
Hope this helps.

Related

How to unpivot a data using excel formula

I have a table as below,
Column A
Column B
Tom
12,45
Kenny
1,4,6
Jude
1,4,5,7
Benji
15,48
Need it like as below
Column A
Column B
Tom
12
Tom
45
Kenny
1
Kenny
4
Kenny
6
Jude
1
Jude
4
Jude
5
Jude
7
I have tried using the FILTER function, however it is not providing what I need.
Office 365. assuming a range of A1:B4 (change as required within the formula):
=LET(ζ,A1:B4,κ,INDEX(ζ,,1),λ,INDEX(ζ,,2),α,"<a><b>",β,"</b><b>",γ,"</b></a>",δ,"//b",ξ,FILTERXML(α&TEXTJOIN(β,,SUBSTITUTE(λ,",",β))&γ,δ),IF(SEQUENCE(,2,0),ξ,INDEX(FILTERXML(α&CONCAT(REPT(κ&β,1+LEN(λ)-LEN(SUBSTITUTE(λ,",",""))))&γ,δ),SEQUENCE(COUNT(ξ)))))
It is assumed that there are no names in column A with a corresponding blank in column B.

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 lookup query

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)

Comparing Multiple Cells and Returning Values

I have a spreadsheet that looks like this:
A B C D
1 Bob 10/02/2013 10
2 Bob 10/02/2013 2
3 Bob 10/02/2013 8
4 Steve 10/01/2013 6
5 Steve 10/01/2013 6
6 Sally 10/01/2013 6
The requirement is that if A1 matches anything else in column A (A1,A2, and A3) AND B1 matches anything in column B (B1,B2,B3) Then add up the values C, divide by 4 and put that in D.
I want to do this for the whole sheet (500ish rows).
You may use the SUMIFS function. Below is sample.
Formula =SUMIFS(C1:C5,A1:A5,A1,B1:B5,B1)
OR
Or can use SUMPRODUCT function .
=SUMPRODUCT($C$1:$C$5,--($A$1:$A$5=$A1)*--($B$1:$B$5=B1))/4

Compare a column has duplicate cells and then compare duplicate cells again on corresponding column

I want to find the duplicate cells in Item Name. For example A is duplicated. And then compare the duplicate content from Item Name A. Therefore, row 2 and row 6 are duplicated. How to setup the equation to determine the duplication?
1 Item Name Content Dupicate?
2 A Mary Y
3 B Peter N
4 C John N
5 A Mary Y
6 B Paul N
7 A Peter N
If Items are in ColumnB and Names in ColumnC I think a suitable formula might be:
=IF(COUNTIFS($C$2:$C$7,C2,$B$2:$B$7,B2)>1,"Y","N")

Resources