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.
 
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).
View attachment 75172

This is what it tested:
View attachment 75173
But the #VALUE! is ugly. If we convert them to 0s,
View attachment 75174

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:
View attachment 75175

This is the result we get from the multiplication.
View attachment 75176

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

So this result represents the comparison:
View attachment 75178

Line 5:
View attachment 75179
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.)
View attachment 75181

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

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.
View attachment 75183

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.
    View attachment 75184

  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.)
    View attachment 75187

  3. Filter out duplicates:
    View attachment 75188

  4. Convert the array to a string.
    View attachment 75189

  5. But if there are no matches, you will get an error:
    View attachment 75190

    So just add IFFERROR, and say whatever you want it to say if there are no matches
    View attachment 75191

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") )
WOAH nice breakdown! Thanks so much. Will still need some time, but I probably wouldn't have figured it out at all if you didn't break it down!
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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")
Thank you Jason! Nice writting, I don't know how you guys come up with them so fast! Unfortunately I can only select one correct solution... But I am going to try both formulas and see which one works best
 
Upvote 0
Trying to simplify the one that I've posted for you, it converts the symbols to their corresponding numeric values based on the list that you provided in post 7.

If at least 2 of the 3 cells contain symbols of the same numeric value then that value is returned. If all 3 are different then it will show the error message (which can be changed to a formula for the next stage if that is what is needed).
 
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") )
Hey cmowla,
thanks a lot for this, it really works great, now one thing. if one of the fields is completely empty, I get an Error. how do I fix it so it counts empty as a value and also compares empty? Even better would be if empty and dash, is considered the same thing
 
Upvote 0
Hey cmowla,
thanks a lot for this, it really works great,
You're welcome.

now one thing. if one of the fields is completely empty, I get an Error. how do I fix it so it counts empty as a value and also compares empty? Even better would be if empty and dash, is considered the same thing
That last bit actually simplified things down a lot (at first glance). Only the first line (which I now divided into 3 lines) needed to be modified. (I modified the last line from what you quoted, because I shortened it in the post with the breakdown.)

And:
  • You quoted the formula with FIND instead of SEARCH, so I assumed that you wanted the one with FIND/the one that's case-sensitive. (If not, simply change all FINDs to SEARCHs.)

  • I assumed that you meant a minus sign for the dash. But if not, just change the characters (in the first 3 lines of the formula) to the specific dash character that you want to use.

  • I assumed that by "blank" you mean blank ("") and not spaces (" ", " ", etc.). But if you meant either "" or " ", etc., then add TRIM to the first 3 lines as follows:
    Excel Formula:
    k_1,IF(TRIM(A2)="","-",MID(A2,SEQUENCE(LEN(A2)),1)),
Book1.xlsx
ABCD
1Workbook1Workbook2Workbook3
2↘(D)-
3-C-
4↘?↘(D)
5ABCDABBAB
6123234567823
7aBCDABCDFGBCD
Sheet10
Cell Formulas
RangeFormula
D2:D7D2=LET( k_1,IF(A2="","-",MID(A2,SEQUENCE(LEN(A2)),1)), k_2,IF(B2="","-",MID(B2,SEQUENCE(LEN(B2)),1)), k_3,IF(C2="","-",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(CONCAT(UNIQUE(FILTER(incommon,incommon<>""),1)),"nothing in common") )
 
Last edited:
Upvote 0
If Cmowla's answer is right then your question was nowhere near what you wanted. As a single example, that incredibly convoluted formula is evaluating the (D) part of ↗(D) and↘(D) as matching each other. According to your earlier post they are not the same because of the arrow direction.
 
Upvote 0
You are actually right about that, that part isn't ideal. But due to a second formula I have running, hard to miss as a mistake. The problem with your formula, was that it converts it to a number, but not back to an arrow, but I need it as a visual. the value system is mainly for computation purposes but not for a human to read. This is why I said that the value itself is not that important for this formula (it is for others but not for this one). The big plus on his Formula is that it keeps the (D) or the (M) and while not necessary for computation purposes, it makes it easier for a human to understand, who knows what those values mean. I didn't even consider it a possibility to keep them.

So while you are right, he did not create what I asked for, he came closer to what I actually needed, yours wasn't in any way wrong. ;)

There is another Formula I need help with, a similar problem to the one I just had, basically this formula is giving back the actual values in the other sheet, but each and every one of them. Now my problem is that - and "" is not beeing valued the same. I know I can put an IF around every one of the cells basically, but wondered if there was a simpler solution.

Excel Formula:
=IFS(AND('[Analyst1.xlsm]$DH'!$S$3='[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3),IFS(AND('[Analyst1.xlsm]$DH'!I12='[Analyst2.xlsm]$DH'!I12,'[Analyst2.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12,'[Analyst1.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12),"",AND('[Analyst1.xlsm]$DH'!I12<>'[Analyst2.xlsm]$DH'!I12,'[Analyst2.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12,'[Analyst1.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12),"AA and A2 = "&'[AutoArrows.xlsm]$DH'!I12&", but A1 = "&'[Analyst1.xlsm]$DH'!I12,AND('[Analyst1.xlsm]$DH'!I12='[Analyst2.xlsm]$DH'!I12,'[Analyst2.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12,'[Analyst1.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12),"A1 and A2 = "&'[Analyst1.xlsm]$DH'!I12&", but AA = "&'[AutoArrows.xlsm]$DH'!I12,AND('[Analyst1.xlsm]$DH'!I12<>'[Analyst2.xlsm]$DH'!I12,'[Analyst2.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12,'[Analyst1.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12),"AA and A1 = "&'[AutoArrows.xlsm]$DH'!I12&", but A2 = "&'[Analyst2.xlsm]$DH'!I12,AND('[Analyst1.xlsm]$DH'!I12<>'[Analyst2.xlsm]$DH'!I12,'[Analyst2.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12,'[Analyst1.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12),"A1 = "&'[Analyst1.xlsm]$DH'!I12&", A2 = "&'[Analyst2.xlsm]$DH'!I12&", AA = "&'[AutoArrows.xlsm]$DH'!I12),AND('[Analyst1.xlsm]$DH'!$S$3<>'[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3),IFS(AND('[Analyst1.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12),"A2 DATE ERR",AND('[Analyst1.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12),"AA = "&'[AutoArrows.xlsm]$DH'!I12&", but A1 = "&'[Analyst1.xlsm]$DH'!I12&", A2 DATE ERR"),AND('[Analyst1.xlsm]$DH'!$S$3='[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3),IFS(AND('[Analyst1.xlsm]$DH'!I12='[Analyst2.xlsm]$DH'!I12),"AA DATE ERR",AND('[Analyst1.xlsm]$DH'!I12<>'[Analyst2.xlsm]$DH'!I12),"A1 = "&'[Analyst1.xlsm]$DH'!I12&", but A2 = "&'[Analyst2.xlsm]$DH'!I12&", AA DATE ERR"),AND('[Analyst1.xlsm]$DH'!$S$3<>'[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3),IFS(AND('[Analyst2.xlsm]$DH'!I12='[AutoArrows.xlsm]$DH'!I12),"A1 DATE ERR",AND('[Analyst2.xlsm]$DH'!I12<>'[AutoArrows.xlsm]$DH'!I12),"AA = "&'[AutoArrows.xlsm]$DH'!I12&", but A2 = "&'[Analyst2.xlsm]$DH'!I12&", A1 DATE ERR"),AND('[Analyst1.xlsm]$DH'!$S$3<>'[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3<>'[AutoArrows.xlsm]$DH'!$S$3),"NO DATE MATCH")

As a note, this part only checks for the date, it doesn't need to check ""

Excel Formula:
=IFS(AND('[Analyst1.xlsm]$DH'!$S$3='[Analyst2.xlsm]$DH'!$S$3,'[Analyst2.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3,'[Analyst1.xlsm]$DH'!$S$3='[AutoArrows.xlsm]$DH'!$S$3)
 
Upvote 0
Ignore this reply, posted in error (fat fingers on phone screen). I'll post proper reply shortly, need to edit formula first. May take a bit longer, edit is not going well on phone and i don't have my laptop with me. I'll post formula when I can but may not be for a few days.
 
Last edited:
Upvote 0
Following up with a revised version of my formula suggestion to show the original text entries instead of the numeric equivalent values.

I've included 2 formulas, the first uses the same method with the text codes and values hardcoded into the formula, the second uses a lookup table to list them instead, which would make any future changes much easier.

I notice that you mentioned blanks in one of your replies, which I haven't allowed for yet in this formula. I'll wait to see if this is potentially a better option for you to continue with than cmowla's suggestion before doing so.
Book1
ABCDEFGHI
1Without tableWith tableRefVal
2Sheet1↘,↘(D)↘,↘(D)↗(M)1
3Sheet2↘?↗(D)1
4Sheet3↘(D)1
5↗?0.5
6R0
7Sheet1↘?↘?,↘?-0
8Sheet2↘?↘?-0.5
9Sheet3↘(D)-1
10↘(D)-1
11↘(M)-1
12Sheet1↘,↘,↘(D)
13Sheet2
14Sheet3↘(D)
Sheet1
Cell Formulas
RangeFormula
E2,E12,E7E2=IFERROR(LET(arr,CHOOSE({1,2,3},C2,C3,C4),ref,{"↗(M)","↗(D)","↗","↗?","R","-","↘?","↘","↘(D)","↘(M)"},val,{1,1,1,0.5,0,0,-0.5,-1,-1,-1},l,XLOOKUP(arr,ref,val,""),TEXTJOIN(",",1,IF(l=MODE(l),arr,""))),"")
F2F2=IFERROR(LET(arr,CHOOSE({1,2,3},C2,C3,C4),ref,Table1[Ref],val,Table1[Val],l,XLOOKUP(arr,ref,val,""),TEXTJOIN(",",1,IF(l=MODE(l),arr,""))),"")
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

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