Compare 2 sets of 2 columns in excel with a lookup - excel

Hi all I need help with the following formula I have looked up ways to compare different datasets in excel but this particular is a little different to the examples ive seen. Say i have the following data set
A
B
C
D
E
F
AB
75
AB
75
Bob
AC
56
AC
68
Fre
AB
75
AB
75
Jill
I need a formula that compares (AB with CD) and prints out E where F is.
for example the result above would like this this since AB & CD are equal so print the name
A
B
C
D
E
F
AB
75
AB
75
Bob
Bob, Jill
AC
56
AC
68
Fre
Fre
AB
75
AB
75
Jill

Give a try on below formula.
=TEXTJOIN(", ",TRUE,FILTER($E$1:$E$3,MMULT(($A$1:$B$3=A1:B1)*($C$1:$D$3=C1:D1),TRANSPOSE({1,1}))))

Related

Transpose data based on two columns and criteria: Excel

I have data that looks like this:
Group: Class: Value:
A 1 51
A 2 60
B 1 55
B 2 67
B 3 70
C 1 53
C 3 65
Need the data to look like this:
Group: 1: 2: 3:
A 51 60 0
B 55 67 70
C 53 0 65
The code I am trying is doing two things wrong: 1. Skipping rows 2. not matching value to class column which causes an issue for Group C since it puts the 65 value into class 2 not and not in class 3 for the final row (row 3 in this example).
=IFERROR(IF(AND($B2=1,COLUMN()<3+MATCH($B2,$B3:$B11000,0)),OFFSET(B2,COLUMN()-3,2-COLUMN()),""),"")
This has worked for me.Hope it helps!
=SUMPRODUCT(($A$2:$A$8=$E2)*($B$2:$B$8=COLUMN(A:A))*$C$2:$C$8)
If the C column format is text, let's try:
=IFERROR(OFFSET($C$2,MATCH(1,INDEX(($A$2:$A$8=$E2)*($B$2:$B$8=COLUMN(A$1)),),0)-1,),"")
I think it's more efficient to use PivotTable for such tasks:

Match duplicates with highest numbers [excel formula]?

Can someone help me with the formula here? I have used something like this before ={MAX(IF(...} but it doesn't really fit what I'm doing now.
=MAX(IF(Sheet1!$A$a:$A$1500=Sheet3!D19,Sheet1!$G$1:$G$1500))
I need to identify that I have duplicates in column A, then look at column B and find the highest value for e.g. cat, then match this highest value with the highest in column C (as you can see "cat" has two 140 figures but in C one of them =56, thus I need "OK" next to it). I would be greatly obliged for your help.
Col A B C Formula?
cat 140 56 OK
cat 140 54 x
cat 87 41 x
cat 91 13 x
cat 100 11 x
dog 230 12 x
dog 230 55 OK
dog 230 45 x
mouse 111 12 x
mouse 123 43 x
mouse 145 55 OK
mouse 103 54 x
Try this in C2 and fill down.
=IF(AND(B2=AGGREGATE(14, 7, B:B/(A$1:A$13=A2), 1), C2=AGGREGATE(14, 7, C:C/((A$1:A$13=A2)*(B$1:B$13=AGGREGATE(14, 7, B:B/(A$1:A$13=A2), 1))), 1)), "OK", "x")

IF formula too long

I’m trying to create a formula that will display mileage from one place to another.
Example: column one is location combinations (there are 39 locations and multiple combinations)
Eg-sams to Petes, sams to mc d, mc d to sams etc.
Last column with formula would automatically place mileage from point a to point b. Etc
The formula i created was IF but way too long
=IF(B12="SVES TO KHS",11,
IF(B12="SVES TO FRHS",4.1,
IF(B12="SVES TO CHS",6.9,
IF(B12="SVES TO KMS",9.5,
IF(B12="SVES TO ISM",6.2,
IF(B12="SVES TO HM",5.3,
IF(B12="SVES TO FHM",2.4,
IF(B12="SVES TO TSM",7.6,...
Is there a way to shorten the formula?
Best thing to do is create a separate table on sheet 2, in column a have a list of answers "SVES TO ", column b the miles. Then use a vlookup to find the miles
=Vlookup (b12, sheet 2!'a1:b50,2,0)
In this example there are 50 different SVES TO examples, change it to however many you have.
An X-to-Y/Y-to-X distance matrix should be your best bet. While VLOOKUP is good for a one-column-lookup/one-column-retrieval, an INDEX/MATCH/MATCH would be more appropriate for a true matrix.
Assume the folowwing data matrix with destinations along the first row and the first column.
a b c d e f g
a - 40 80 17 37 16 70
b 40 - 48 95 85 8 60
c 80 48 - 24 26 75 73
d 17 95 24 - 14 9 56
e 37 85 26 14 - 91 7
f 16 8 75 9 91 - 78
g 70 60 73 56 7 78 -
Note that distances like c-to-f are the same as f-to-c. (yes, there i a simple formula for this but that is another question). Obviously, any x-to-x or y-to-y should be zero when x = y.
In the sample image below your formula in L2 should be,
=INDEX($B$2:$H$8, MATCH(J2, A$2:A$8, 0), MATCH(K2, B$1:H$1, 0))
The cell and row highlighting were added with a couple simple conditional formats formulas.

Excel macro replace cell in A by other cell in B

I have a excel document where I have something like this
A B C
1 1 45 a
2 2 32 b
3 3 34 H
4 3 37
5 4 49 i
5 5 76 H
Note that 3c is combined but 3b isn't.
I need to do a macro to change the content of B with the content of C but only those that don't have a letter H. so the document would look like this
A B C
1 1 a a
2 2 b b
3 3 34 H
4 3 37
5 4 i i
5 5 76 H
Here a image
Just use this simple formula in column C,
=IF(B1="H",A1,B1)
and drag it throughout the range. Once done, copy paste all of the data in column C to A (paste special)

Excel - Sorting based on metric values

I have a dataset which looks like:
Product Metrics C1 C2 C3
A1 Q1 20 30 10
Q2 213123 2312 32123
Q3 454 65 45
Q4 3 4 6
A2 Q1 10 5 1
Q2 123 13 23
Q3 454 65 45
Q4 3 4 6
A3 Q1 18 6 3
Q2 123 13 23
Q3 454 65 45
Q4 3 4 6
Now I want to sort the values based on metric Q1 - From smallest to largest (comparing against the product -A1,A2) then the final dataset should look like,
Product Metrics C1 C2 C3
A2 Q1 10 5 1
Q2 123 13 23
Q3 454 65 45
Q4 3 4 6
A3 Q1 18 6 3
Q2 123 13 23
Q3 454 65 45
Q4 3 4 6
A1 Q1 20 30 10
Q2 213123 2312 32123
Q3 454 65 45
Q4 3 4 6
hope this gives a clear picture. Thanks in advance guys
The way I would probably do it is transpose your columns and rows so that you have columns for Q1, Q2, Q3, Q4.
Like this:
Product Metrics Q1 Q2 Q3 Q4
A1 C1 20 213123 454 3
A1 C2 30 2312 65 4
A1 C3 10 32123 45 6
A2 C1 10 123 454 3
A2 C2 5 13 65 45
A2 C3 1 23 45 6
Then you can sort by Q1 using Data>Sort & Filter
CBRF23 already pointed in the right direction but I believe you have to go even a little bit further and flatten each product related sub-array into a single row like
A | B C D | E F G | H I J | K L M
---| Q1 --------| Q2 ------------ | Q3 ------- | Q4 -------
Pr | C1 C2 C3 | C1 C2 C3 | C1 C2 C3 | C1 C2 C3
A1 | 20 30 10 | 213123 2312 32123 | 454 65 45 | 3 4 6
A2 | 10 5 1 | 123 13 23 | 454 65 45 | 3 4 6
A3 | 18 6 3 | 123 13 23 | 454 65 45 | 3 4 6
(The first row just shows the Excel columns, second row the flattened Q1,Q2,Q3 and Q4 sections and third row the sub-headers for each column)
Now you can safely sort by column B. In case you want to sort by the sum of all Q1 metrics you could introduce another column N being the sum of B,C and D and use that for sorting.
Update:
To get your desired output format back there are basically to possibilities:
If the number of records is known and fixed you can set-up a "results" page in your excel folder with a list of small "sub-tables". The fields of each sub-array then directly reference the "transposed" fields in a line of the sorted master results array.
If the number of results is variable you will have to construct/reconstruct the results page mentioned above using a suitable vba script. The vba generated page can of course also consist of the sorted values directly rather than referencing the values in the sorted master array.

Resources