Search two columns in Excel for duplicates in different rows then only count one row when summing values in a separate column - excel

I am new to the Stackoverflow and I would greatly appreciate anyone's help here as I've racking my brain trying to figure it out if I need a macro or not. Essentially I'd like to match columns A and B to find a duplicate in either direction then only sum the first instance of the match. So I would only sum 10+9+8+7.
**A** **B** **Value**
1 345155 345670 $10
2 345345 $9
3 345346 $8
4 345672 $7
5 345670 345155 $10

create a new column and use the below formula
=IF((COUNTIF(A$1:A5,A6)+COUNTIF(B$1:B5,A6)+COUNTIF(A$1:A5,B6)+COUNTIF(B$1:B5,B6))>0,0,C6)
take sum of this new column
this would ignore the value to be added, if a value in any columns (A or B) is repeated in any of the columns (A or B)

Place this formula in a separate column. Say, column E
=IF(ISNUMBER(MATCH(A1,B2:B$7,0)),"","Add")
Then this formula anywhere you want: =SUMIF(E1:E7,"Add",C1:C7)
This assumes a match on one side is always a match on the other side. If you need to ensure both sides match, change the first formula to this:
=IF(AND(ISNUMBER(MATCH(A1,B2:B$7,0)),ISNUMBER(MATCH(B1,A2:A$7,0))),"","Add")

Related

Displaying a label, sorted in a third column pulled from the first column according to data in the second column? i.e. Ranking

Imagine you have spreadsheet with data in a fixed # of contiguous rows.. let's say row 1 through row 20
Now let's say you have 3 columns of interest.
A, B and C
Column A is a label column.. the data in there are just string labels.. let's say types of canned food.. Tuna, Spam, Sardines, etc.
Column B is our number column.. let's say it is prices. e.g. 2 for Tuna, 5 for Spam and 3 for Sardines. These prices can change often very rapidly.. ok so prices are not the best example but let's imagine that prices change rapidly.
Now Column C is where we want to put the formula.
I would like to have a formula in Column C that will pull the labels from Column A, based on their prices in column B and rank them from highest to lowest.. that is C1 would calculate to "Spam", C2 to "Sardines" and C3 to "Tuna"
right now there are 20 rows of data.. but maybe at some other point there might be 30 or 6 or 40, etc.
So can someone help me out with the formula or at least explain what functions I need to use and the general idea involved? thanks
=IF(A2:A200<>"";SORTBY(A2:A200;B2:B200;-1);"")
You can simply use SORT formula. In this case =SORT(A1:B1000,2,-1) where A1:B1000 is range to be sorted, second parameter 2 is column number from range to sort by, 3rd parameter for order (-1 is desceding).
Place formula in C1 and you will get spilled array.

Formula for Multiple True and False Statements

I have a formula I need to create with multiple criteria.
the basis is that I have to subtract $7 from my savings.
this number is based on how many duplicates there are of the shipment number (column A)
So,if there is 1 I subtract $7. If there are 2 duplicates I only subtract $3.50, with 3 I only subtract $2.33, and 4 I only subtract $1.75 and so on.
Another part of the data is I do not subtract $7 from anything with a carrier code that begins with "LI" it will range from "LI020:LI038".
The current formula I am using is:
=IF(AND(2="C:C",1="C:C"),P2-(3.5/D2),P2-(7/D2))
obviously, it isn't doing what I need it do. I have a current formula as well to divide the actual by duplicates to get a savings column E = D2/Countif(A:A,A2).
sample of data:
=E2 - IF(LEFT(G2,2)="LI",0,7/COUNTIF(A:A,A2))
Please use this formula:
=IF(LEFT(C2,2)="LI",B2,B2-(7/A2))
C -> Carrier Code Column, B -> Savings Column,A -> Duplicate Column
Please replace appropriate columns in the formula provided by me and stick the formula in a new column and propagate the formula to all the rows needing the validation
Regards
=IF(IFERROR(SEARCH("LI*",[Location of Cell for Carrier Code],1),0)=0, [Savings Cell] - (7/[Duplicates Cell]),[Savings Cell])

Excel: Finding next equal match in column

I've googled for a solution to my problem for days and I just can't seem to get my head around how to do this.
I have 28 chickens and I track the eggs each one lays each month. My Excel sheet looks like this:
Current Egg-cel sheet
Column C is populated by the formula:
=LARGE($A$2:$A$29,$B1)
I'm using column B to increment the LARGE function
I want column D to populate with which chicken number laid the quantity in column C.
Obviously INDEX MATCH or VLOOKUP returns the first match for all equal values. How do I find the the next match? i.e.
Egg-cell sheet 2
I've seen similar questions and solutions but I for the life of me can not get it to work.
Use this formula in D2:
=INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$29)/($A$2:$A$29=C2),COUNTIF($C$2:C2,C2)))
And drag down
If you're happy to add a few helper columns, this is a simple way to go:
The formula in column C creates a unique number by bringing together the eggs laid and the chicken number
=--(A2&"."&B2)
Column D is just your LARGE formula,
=LARGE($C$2:$C$4,B2)
Column E just gets the integer part of column D
=INT(D2)
And finally Column F gets the decimal part (chicken number) from column D
=--REPLACE(MOD(D2,1),1,2,"")

Index/match if greater than

Hoping someone can help me with my trouble with an index/match formula.
Column B has a list of names, column C has the frequency of an action taken (sales made) whilst column D has the average sales value.
I've created in column G a track of the 6 highest sales which has worked great:
=LARGE($D$8:$D$13, 2)
Then I've used column F to determine the name that matches each sales average:
=INDEX($B$8:$B$13, MATCH(G4, $D$8:$D$13, 0))
So far so good! However, I'd like to only include the sales average if that individual has had more than 3 sales. IE; the value in column C is >3.
Can any one provide help or suggestions please?
I think you could use a helper column to filter out the values you don't need before applying =LARGE() in the very beginning, like this:
=IF($C8>3, $D8, "")
Then do =LARGE() to this column instead:
=LARGE($X$8:$X$13, 2)
You could use an array formula:
=LARGE(IF(range=criteria,values),n)
so for your case:
=LARGE(IF($C$8:$C$13>3,$D$8:$D$13), 2)
press CTRL+SHIFT+ENTER to enter an array formula.

Ranking in Excel with multiple criteria

For example, I need to create a merit list of few student based on total marks (column C), then higher marks in math (column B) -
A B C D
-------------------------
Student1 80 220 1
Student2 88 180 3
Student3 90 180 2
Expected merit position is given in column D.
I can use RANK function but I can only do that for one column (total number). If total number of multiple student is equal, I could not find any solution of this.
You can try this one in D1
=COUNTIF($C$1:$C$99,">"&C1)+1+SUMPRODUCT(--($C$1:$C$99=C1),--($B$1:$B$99>B1))
and then copy/fill down.
let me know if this helps.
Explanation
Your first criteria sits in column C, and the second criteria sits in Column B.
Basically, first it is counting the number of entries ($C$1:$C$99) that are bigger than the entry itself ($C1). For the first one in the ranking, you will get zero, therefore you need to add 1 to each result (+1).
Until here, you will get duplicate rankings if you have the same value twice. Therefore you need to add another argument to do some extra calculations based on the second criteria:
To resolve the tie situation, you need to sumproduct two array formulas and add the result to the previous argument, the goal is to find the number of entries that are equal to this entry with $C$1:$C$99=C1 and have a bigger value in the second criteria column $B$1:$B$99>B1:
you add -- to convert TRUE and FALSE to 0s and 1s so that you can multiply them:
SUMPRODUCT(--($C$1:$C$99=C1),--($B$1:$B$99>B1))
the first array is to see how many ties you have in the first criteria. And the second array is to find the number of bigger values than the entry itself.
Note you can add as many entries as you like to your columns, but remember to update the ranges in the formula, currently it is set to 99, you can extend it to as many rows as you want.
Sometimes a helper column will provide a quick and calculation-efficient solution. Adding the math marks to the total marks as a decimal should produce a number that will rank according to your criteria. In an unused column to the right, use this formula in row 2,
=C2+B2/1000
Fill down as necessary. You can now use a conventional RANK function on this helper column like =RANK(D2, D$2:D$9) for your ranking ordinals.
Very simple (or, at least, much more simpler that the one provided by the best answer) 'math' solution: do a linear combination with weights.
Do something like
weighted_marks = 10*colC + colB
then sort weighted marks using simple rank function.
It does solve your problem, bulding the ranking you need.
If you don't like to limit the number of rows or the numbers used in the criteria, Jeeped's approach can be extended. You can use the following formulas in cells D2 to L2, assuming that there are three criteria, the first one in column A, the second one in column B, and the third one in column C:
=RANK($A2,$A:$A,1)
=RANK($B2,$B:$B,1)
=D2*2^27+E2
=RANK(F2,F:F,1)
=RANK($C2,$C:$C,1)
=G2*2^27+H2
=RANK(I2,I:I,1)
=J2*2^27-ROW()
=RANK(K2,K:K,0)
The formulas have to be copied down. The result is in column L. Ties are broken using the row number.
If you like to add a fourth criterion, you can do the following after having the formulas above in place:
Add the new criterion between columns C and D.
Insert three new columns between columns I and J.
Copy columns G:I to the new columns J:L.
Copy column G to column M, overwriting its content.
Change the formula in column L to point to the new criterion.
The factor 2^27 used in the formulas balances the precision of 53 bits available in double-precision numbers. This is enough to cover the row limit of current versions of Excel.

Resources