calculate array

keda duck

Board Regular
Joined
Jul 9, 2023
Messages
54
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
Platform
  1. Windows
This is a problem I encountered in my work. I want to use formula to solve this problem

Each cell is two numbers separated by character "/", and the number may contain Decimal separator.
The cells may be empty.
B3 and B2 are compared and assigned scores, C3 and C2 are compared and assigned scores...
Finally, the sum of the assigned scores for each row and the second row is calculated and written in column W for each row.

Scoring rules:
2: Two cells are the same and neither is empty
1: A certain number in cell B3 is the same as two numbers in cell B2
0: At least one of the two cells is empty, or the two numbers in cell B3 are different from the two numbers in cell B2

Taking the sixth row as an example.
B6 is empty, so its score is 0.
the first number of c6 is 9, and the second number of c4 is 13, these numbers are not existed in c2, so its score is 0.
The first number of d6 is 9, and the second number of b2 is 12, 12 is existed in b2 but 9 is not existed in, so its score is 1.
……
the first number of j6 is 8, and the second number of j6 is 11, 8 and 11 are both in j2, so its score is 2.
……
and so on.

When I calculate the score for each cell, I sum the scores for each row.

calculate.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1no.data 1data 2data 3data 4data 5data 6data 7data 8data 9data 10data 11data 12data 13data 14data 15data 16data 17data 18data 19data 20data 21
2116/168/811/129/925.2/30.212/1510/1130/308/1116/17.314/1411/1514/1410/1118/2717/2416/209/912/2111/1224/24
3215/1711/1212/1211/1319/28.213/1511/1230/318/813/18.313/1415/1712/1314/1417/2319/2316/207/715/1710/1122/22
4315/1610/118/1011/1322/28.215/167/1130/328/1114/1512/15.211/1510/1411/1419/2324/2515/196/915/1512/1221/22
5417/179/108/1010/1120/27.212/1410/1129/31.28/811/1413/1513/1811/1110/1418/2017/2214/177/915/158/1122/23
659/139/1211/1125.2/26.213/1311/1229/308/1112/1513/15.216/1612/1310/1219/1916/2014/186/915/169/1424/24
7615/1610/128/812/1319.2/24.215/1611/1129/32.28/812/1313/1315/1714/1511/1421/2323/2414/199/914/2011/1223/25
8715/168/118/1112/1322/24.215/1611/1131.2/328/813/1413/15.215/1610/1511/1218/2322/2417/197/914/1510/1222/23
9814/189/1112/139/1425.2/28.216/1611/1232/32.28/915/1613/1417/1710/1210/1419/2116/2314/157/813/1412/1224/25
10915/178/118/1111/1122.2/28.214/1510/1230/318/817/1713.2/14.211/1511/1411.3/1218/1920/2317/187/913/2012/1224/25
111015/178/88/1311/1219/28.210/1029/308/815/1713/14.211/1111/1210/11.318/2019/2017/189/913/1412/1223/25
121117/189/1111/1122.2/28.215/1512/1229/318/1013.2/1415/1513/1411/1219/2114/177/914/2011/1221/24
131214/1610/119/129/1119/26.213/1410/1329/31.28/815/1513/1415/1611/1418/1923/2414/169/913/1610/1024/25
141315/1612/139/1119/27.213/1411/1230/31.28/815/1513/14.215/1611/1410/1218/1919/2314/187/913/1310/1223/25
151415/1510/1112/1310/1019/27.213/1411/1229/31.28/1015/1513/1411/1511/1312/1218/1919/2314/169/913/1610/1223/24
161515/1610/1210/119/1028.2/29.213/1411/1229/298/913/1513/1311/1713/1510/1121/2219/2316/196/714/1811/1223/24
171616/189/128/1111/1219/2113/1512/1332/33.211/1111/1413/14.211/1513/1610/1117/1819/2018/197/816/2310/1223/24
181715/158/98/1311/1223.2/28.213/1311/1330/309/1114/1714.2/14.215/1613/1410/1118/1924/2414/189/1013/1310/1219/20
191816/178/1111/1112/1220/25.213/169/1230/31.210/1112/1512.2/15.215/1612/1410/1018/2019/2016/187/713/1412/1320/23
201914/159/119/139/1019/30.213/1412/1331.2/33.28/1015/1511/1613/1410/1219/1919/2414/177/913/1610/1224/25
212015/168/1012/1210/1126.2/27.213/1310/1129/308/813/1513/1411/1511/1110/1218/1823/2316/189/913/1610/1223/24
222110/138/1012/1219/30.214/1512/1329/308/815/1515/16.211/1612/1311/1418/1919/2316/199/915/1610/1222/23
Sheet1 (2)
 
How about
Excel Formula:
=SUM(MAP($B$2:$V$2,B3:V3,LAMBDA(a,b,LET(x,TEXTSPLIT(b,"/"),y,SUM(--ISNUMBER(FIND("/"&TEXTSPLIT(b,"/",,1)&"/","/"&a&"/"))),IF(b="",0,IF(INDEX(x,1)=INDEX(x,2),IF(b=a,y,y/2),y))))))
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
Excel Formula:
=SUM(MAP($B$2:$V$2,B3:V3,LAMBDA(a,b,LET(x,TEXTSPLIT(b,"/"),y,SUM(--ISNUMBER(FIND("/"&TEXTSPLIT(b,"/",,1)&"/","/"&a&"/"))),IF(b="",0,IF(INDEX(x,1)=INDEX(x,2),IF(b=a,y,y/2),y))))))
These results are what I expected. I marked as solution. Thanks!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
These results are what I expected. I marked as solution.
This simplified version produces the same results for the sample data.
Excel Formula:
=SUM(MAP($B$2:$V$2,B3:V3,LAMBDA(a,b,IF(a=b,2,COUNT(FIND("/"&UNIQUE(TEXTSPLIT(b,"/"),1)&"/","/"&a&"/"))))))
 
Upvote 0
Solution
This simplified version produces the same results for the sample data.
Excel Formula:
=SUM(MAP($B$2:$V$2,B3:V3,LAMBDA(a,b,IF(a=b,2,COUNT(FIND("/"&UNIQUE(TEXTSPLIT(b,"/"),1)&"/","/"&a&"/"))))))
Wow, this version is simple and easy to understand. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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