comparing three values which are changeable, Excel Formula

DavyJones90

Board Regular
Joined
Feb 23, 2022
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hello everyone!

Need your help again.

What I want to do.

3 different worksheets need to be compared, within these three worksheets, there are three cells with strings, I need to check if there is one value but not another, within these three strings and if at least 2 of the three match

Excel Formula:
=IF(IF(ISNUMBER(SEARCH("↘",Z10)),"↘",1)+IF(ISNUMBER(SEARCH("~?",Z10)),"?",1)="↘?","next formula","↘")

This is what I got so far, but this will only give me if both strings are there in one of the three workbooks. What I need is that these 3 are now compared and ensured that the first part exists but not the second if the second exists and the first, the next formula needs to be applied

Workbook1Workbook2Workbook3
↘?↘(D)

These should give back the value ↘ because both 1 and 3 have a down arrow and only 2 has down arrow questionmark.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I need to check if there is one value but not another
What is the value that should not exist? The description in your post seems to be quite cryptic in places (or maybe I just have caffeine deficiency :oops: ).

Also, could you type =LET( into excel and confirm if that comes up as a valid function (it will make things a lot easier if you have it).
 
Upvote 0
Hi.
  • This will give all characters in common between any two of the 3 (or if a pair has something in common that another pair has in common, it will list what both pairs have in common disjointly) and say "nothing in common" if no two have any character(s) in common.

  • It assumes that you don't want to compare the characters | and , in the cells. If there is a possibility that you do, please let me know and I can modify this.

  • It separates the characters by a comma, and it removes duplicates (only shows the UNIQUE set).
Book1.xlsx
ABCD
1Workbook1Workbook2Workbook3
2↘?↘(D)
3ABCnothing in common
4↘?↘?↘(D)↘,?
5ABCDABBA,B
612323456782,3
7ABCEACDEDFGA,C,E,D
Sheet5
Cell Formulas
RangeFormula
D2:D7D2=LET( k_1,MID(A2,SEQUENCE(LEN(A2)),1),k_2,MID(B2,SEQUENCE(LEN(B2)),1),k_3,MID(C2,SEQUENCE(LEN(C2)),1), k1k2,IFERROR(MMULT(IFERROR(FIND(k_1,TRANSPOSE(k_2)),0),0*SEQUENCE(ROWS(k_2))+1),0), k2k3,IFERROR(MMULT(IFERROR(FIND(k_2,TRANSPOSE(k_3)),0),0*SEQUENCE(ROWS(k_3))+1),0), k3k1,IFERROR(MMULT(IFERROR(FIND(k_3,TRANSPOSE(k_1)),0),0*SEQUENCE(ROWS(k_1))+1),0), relationships,CONCAT(k_1&","&k1k2&"|")&CONCAT(k_2&","&k2k3&"|")&CONCAT(k_3&","&k3k1&"|"), arr,TEXTSPLIT(LEFT(relationships,LEN(relationships)-1),"|"), incommon,IF(IFERROR(FIND(",1",arr),0)>0,LEFT(arr,LEN(arr)-2),""), IFERROR(TEXTJOIN(",",,UNIQUE(TRANSPOSE(FILTER(incommon,incommon<>"")))),"nothing in common") )
 
Last edited:
Upvote 0
Solution
And the above formula is case-sensitive. If you want case-insensitive, all of the FINDs need to be converted to SEARCHs:
Book1.xlsx
ABCD
1Workbook1Workbook2Workbook3
2↘?↘(D)
3ABCnothing in common
4↘?↘?↘(D)
5ABCDABBA,B
612323456782,3
7aBCDABCDFGa,B,C,D
Mega Compare
Cell Formulas
RangeFormula
D2:D7D2=LET( k_1,MID(A2,SEQUENCE(LEN(A2)),1),k_2,MID(B2,SEQUENCE(LEN(B2)),1),k_3,MID(C2,SEQUENCE(LEN(C2)),1), k1k2,IFERROR(MMULT(IFERROR(SEARCH(k_1,TRANSPOSE(k_2)),0),0*SEQUENCE(ROWS(k_2))+1),0), k2k3,IFERROR(MMULT(IFERROR(SEARCH(k_2,TRANSPOSE(k_3)),0),0*SEQUENCE(ROWS(k_3))+1),0), k3k1,IFERROR(MMULT(IFERROR(SEARCH(k_3,TRANSPOSE(k_1)),0),0*SEQUENCE(ROWS(k_1))+1),0), relationships,CONCAT(k_1&","&k1k2&"|")&CONCAT(k_2&","&k2k3&"|")&CONCAT(k_3&","&k3k1&"|"), arr,TEXTSPLIT(LEFT(relationships,LEN(relationships)-1),"|"), incommon,IF(IFERROR(SEARCH(",1",arr),0)>0,LEFT(arr,LEN(arr)-2),""), IFERROR(TEXTJOIN(",",,UNIQUE(TRANSPOSE(FILTER(incommon,incommon<>"")))),"nothing in common") )
 
Upvote 0
Woah, did you just write that freely? I'd take like 3 days to make something, not even closely as complex.

Thanks a lot, this might solve several problems, how do I get rid of the comma between the in commons?

The options are limited so having no comma would give me the correct result.

Thank you so much, I'll probably need several hours to understand what you did, but it will really teach me something.
 
Upvote 0
The options are limited so having no comma would give me the correct result.
What are the options that you need to look at?

Your original question implied that there were things to include and things to exclude but it wasn't clear what they were. With more clarity a much more concise formula should be possible, unless you prefer using a sledgehammer to peel a tomato?
 
Upvote 0
What are the options that you need to look at?

Your original question implied that there were things to include and things to exclude but it wasn't clear what they were. With more clarity a much more concise formula should be possible, unless you prefer using a sledgehammer to peel a tomato?

Hi Jason, nice to hear from you!

Following for understanding.

These Values are possible and need to be computed

↗(M) Value 1
↗(D) Value 1
↗ Value 1
↗? Value 0.5
R Value 0
- Value 0
↘? Value -0.5
↘ Value -1
↘(D) Value -1
↘(M) Value -1


now these are the values and the only possible inputs

That's why wether i have ↗ or ↗(D) does not really matter as an outcome, but ↗? makes a difference.

Now why remove the comma, the correct value would be ↗? or ↘?, not ↘,?.

This is important because whoel array of formulas compute with the value ↘?, but won't compute with ↘,?

The value itself is not so important for this formula though, as it basically only needs to make sure that 2 out of 3 are the same and not add a comma and not change anything based on value.

What it shouldn'T do though is have match like this, ↗? and ↘? = ?, as there is no value with only a questionmark. it should then show error.

Now the other problem I have is that, i am comparing three workbooks, but in case the date only matches on two of them it should compute with only the two where the date matches.

If you have the time to figure out that one too, would be great, if not, I'll probably manage on my own ;)


Does this explain?
 
Upvote 0
Thanks a lot, this might solve several problems, how do I get rid of the comma between the in commons?
For the case-insensitive version (again, if you want case sensitive, just change all SEARCH to FIND),
Book1.xlsx
ABCD
1Workbook1Workbook2Workbook3
2↘?↘(D)
3ABCnothing in common
4↘?↘?↘(D)
5ABCDABBAB
6123234567823
7aBCDABCDFGaBCD
Mega Compare
Cell Formulas
RangeFormula
D2:D7D2=LET( k_1,MID(A2,SEQUENCE(LEN(A2)),1),k_2,MID(B2,SEQUENCE(LEN(B2)),1),k_3,MID(C2,SEQUENCE(LEN(C2)),1), k1k2,IFERROR(MMULT(IFERROR(SEARCH(k_1,TRANSPOSE(k_2)),0),0*SEQUENCE(ROWS(k_2))+1),0), k2k3,IFERROR(MMULT(IFERROR(SEARCH(k_2,TRANSPOSE(k_3)),0),0*SEQUENCE(ROWS(k_3))+1),0), k3k1,IFERROR(MMULT(IFERROR(SEARCH(k_3,TRANSPOSE(k_1)),0),0*SEQUENCE(ROWS(k_1))+1),0), relationships,CONCAT(k_1&","&k1k2&"|")&CONCAT(k_2&","&k2k3&"|")&CONCAT(k_3&","&k3k1&"|"), arr,TEXTSPLIT(LEFT(relationships,LEN(relationships)-1),"|"), incommon,IF(IFERROR(SEARCH(",1",arr),0)>0,LEFT(arr,LEN(arr)-2),""), IFERROR(CONCAT(UNIQUE(TRANSPOSE(FILTER(incommon,incommon<>"")))),"nothing in common") )


Thank you so much, I'll probably need several hours to understand what you did, but it will really teach me something.
I will break it down for you, since you're interested. (Writing up the post now.)
 
Upvote 0
First of all, the LET function is like coding, where you can compute something once and assign it to a variable. So the LET function allows this. So the outer skeleton of the formula is of the form:
LET(
____variableName , variableValue,
____variableName , variableValue,
____variableName , variableValue,
____
.
____.
____.
____variableName , variableValue,
result

)

And the order in which you substitute variableNames matters, so if one variable will use another variable, define the variables that are used in other variables before the variables that use them.

Line 1:
Excel Formula:
k_1,MID(A2,SEQUENCE(LEN(A2)),1),k_2,MID(B2,SEQUENCE(LEN(B2)),1),k_3,MID(C2,SEQUENCE(LEN(C2)),1),

First of call, SEQUENCE is going to give you an array of numbers, for example. (You don't have to fill it down. Excel "spills" it for you.)
Book1.xlsx
E
21
32
43
54
65
Mega Compare (2)
Cell Formulas
RangeFormula
E2:E6E2=SEQUENCE(5)
Dynamic array formulas.


I'm sure you know about the string functions MID, LEFT, and RIGHT. So MID(A2,SEQUENCE(LEN(A2)),1) will just split up all characters of a cell into an array of characters. (LEN(A2) = number of characters in the cell). For example,
Book1.xlsx
FG
2abc 123a
3b
4c
5
61
72
83
Mega Compare (2)
Cell Formulas
RangeFormula
G2:G8G2=MID(F2,SEQUENCE(LEN(F2)),1)
Dynamic array formulas.

Lines 2-4:
Excel Formula:
    k1k2,IFERROR(MMULT(IFERROR(SEARCH(k_1,TRANSPOSE(k_2)),0),0*SEQUENCE(ROWS(k_2))+1),0),
    k2k3,IFERROR(MMULT(IFERROR(SEARCH(k_2,TRANSPOSE(k_3)),0),0*SEQUENCE(ROWS(k_3))+1),0),
    k3k1,IFERROR(MMULT(IFERROR(SEARCH(k_3,TRANSPOSE(k_1)),0),0*SEQUENCE(ROWS(k_1))+1),0),

Begin with the inner part, SEARCH(k_1,TRANSPOSE(k_2)),0). It gives a 2D array which you read as "see what characters of k_1 are in k_2 (if any).
01.PNG


This is what it tested:
02.PNG

But the #VALUE! is ugly. If we convert them to 0s,
03.PNG


But this is a 2D matrix. We want to just get a 1D array that says if each of the characters of k_1 (abc in this case) match any of the characters of k_2. We can use multiplication of matrices to do this:
04.PNG


This is the result we get from the multiplication.
05.PNG


(Imagine that this result is just "pushing" all 1's to the left into the same column.)
06.png


So this result represents the comparison:
07.png


Line 5:
08.PNG

This just collects all of those 1D arrays and puts them into one (horizontal) string. I put a (temporary) comma to separate the character from the 0 or 1. Just for visual purposes. 1 means there was a match, 0 means there wasn't a match.

Line 6:
This step was easy. I just converted the above string into an array, because I want to remove the characters that didn't match. (In the next step/line.)
09.PNG


Line 7:
I begin by removing the (temporary) commas. Again, nothing new here. 0 represents unmatched. But #'s>0 represent matched.
10.PNG


But if they are > 0, I want to put the actual character (see Line 6's image), but if they are not a match, I want to make them a blank.
11.PNG


Line 8:
Excel Formula:
IFERROR(CONCAT(UNIQUE(TRANSPOSE(FILTER(incommon,incommon<>"")))),"nothing in common")
This one is self-explantory. Starting from the inner part of the line, we:
  1. Filter out blanks.
    12.PNG


  2. I transposed it, because for UNIQUE to delete duplicates. And UNIQUE doesn't remove duplicates for this horizontal array unless you pass 1 as a second parameter. UNIQUE(arr,1). (I should have did this to shorten the formula, but I just transposed it instead.)
    13.PNG


  3. Filter out duplicates:
    14.PNG


  4. Convert the array to a string.
    15.PNG


  5. But if there are no matches, you will get an error:
    16.PNG


    So just add IFFERROR, and say whatever you want it to say if there are no matches
    17.PNG

And so therefore, the formula can be shortened to:
Book1.xlsx
ABCD
1Workbook1Workbook2Workbook3
2↘?↘(D)
3ABCnothing in common
4↘?↘?↘(D)
5ABCDABBAB
6123234567823
7aBCDABCDFGaBCD
Mega Compare (2)
Cell Formulas
RangeFormula
D2:D7D2=LET( k_1,MID(A2,SEQUENCE(LEN(A2)),1),k_2,MID(B2,SEQUENCE(LEN(B2)),1),k_3,MID(C2,SEQUENCE(LEN(C2)),1), k1k2,IFERROR(MMULT(IFERROR(SEARCH(k_1,TRANSPOSE(k_2)),0),0*SEQUENCE(ROWS(k_2))+1),0), k2k3,IFERROR(MMULT(IFERROR(SEARCH(k_2,TRANSPOSE(k_3)),0),0*SEQUENCE(ROWS(k_3))+1),0), k3k1,IFERROR(MMULT(IFERROR(SEARCH(k_3,TRANSPOSE(k_1)),0),0*SEQUENCE(ROWS(k_1))+1),0), relationships,CONCAT(k_1&","&k1k2&"|")&CONCAT(k_2&","&k2k3&"|")&CONCAT(k_3&","&k3k1&"|"), arr,TEXTSPLIT(LEFT(relationships,LEN(relationships)-1),"|"), incommon,IF(IFERROR(SEARCH(",1",arr),0)>0,LEFT(arr,LEN(arr)-2),""), IFERROR(CONCAT(UNIQUE(FILTER(incommon,incommon<>""),1)),"nothing in common") )
 
Upvote 0
So, if I'm following correctly something like this will be adequate for the task. I've tested with 1 cell in each of 3 different sheets and it works correctly.

Book1
ABCDE
2Sheet1-1
3Sheet2↘?
4Sheet3↘(D)
5
6
7Sheet1↘?-0.5
8Sheet2↘?
9Sheet3↘(D)
10
11
12Sheet1-1
13Sheet2
14Sheet3↘(D)
Sheet2
Cell Formulas
RangeFormula
E2,E12,E7E2=IFERROR(LET(arr,CHOOSE({1,2,3},C2,C3,C4),MODE(XLOOKUP(arr,{"↗(M)","↗(D)","↗","↗?","R","-","↘?","↘","↘(D)","↘(M)"},{1,1,1,0.5,0,0,-0.5,-1,-1,-1}))),"No common value")
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top