Formulas within Array Constants (INDEX MATCH within SMALL)

gcefaloni

Board Regular
Joined
Mar 15, 2016
Messages
119
Hi,

I have the following Credit Rating Table

#RTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
100​
AAAAAAAaaAAA
95​
AA+AAHAa1AA+
90​
AAAAAa2AA
85​
AA-AALAa3AA-
80​
A+AHA1A+
75​
AAA2A
70​
A-ALA3A-
65​
BBB+BBBHBaa1BBB+
60​
BBBBBBBaa2BBB
55​
BBB-BBBLBaa3BBB-
50​
BB+BBHBa1BB+
45​
BBBBBa2BB
40​
BB-BBLBa3BB-
35​
B+BHB1B+
30​
BBB2B
25​
B-BLB3B-
20​
CCC+CCCHCaa1CCC
15​
CCCCCCCaa2CCC
10​
CCC-CCCLCaa3CCC
5​
CCCCCaDDD
0​
DDCDD

I'm trying to get this formula working:

=SMALL(IFERROR(M9:P9,""),ROW(1:1))

Where currently: M9 is =INDEX(Credit_Ratings,MATCH(M6,Table1[[#All],[RTG_SP]],0),MATCH("#",Table1[#Headers],0))
N9=INDEX(Credit_Ratings,MATCH(N6,Table1[[#All],[RTG_DBRS]],0),MATCH("#",Table1[#Headers],0))
O9=INDEX(Credit_Ratings,MATCH(O6,Table1[[#All],[RTG_MOODY]],0),MATCH("#",Table1[#Headers],0))
P9=INDEX(Credit_Ratings,MATCH(P6,Table1[[#All],[RTG_FITCH]],0),MATCH("#",Table1[#Headers],0))

But I do not want to have a reference to the M9:P9 cells or any other cells for a matter of fact.. So I would like to do something that incorporates the INDEX MATCH formulas within the initial SMALL formula so that I can know which is the smallest #s just from referring the letters.

Could I do something like the following?
{=SMALL(IFERROR({(INDEX(Credit_Ratings,MATCH(M6,Table1[[#All],[RTG_SP]],0),MATCH("#",Table1[#Headers],0))),(INDEX(Credit_Ratings,MATCH(N6,Table1[[#All],[RTG_DBRS]],0),MATCH("#",Table1[#Headers],0))),(INDEX(Credit_Ratings,MATCH(O6,Table1[[#All],[RTG_MOODY]],0),MATCH("#",Table1[#Headers],0))),(INDEX(Credit_Ratings,MATCH(P6,Table1[[#All],[RTG_FITCH]],0),MATCH("#",Table1[#Headers],0)))},""),ROW(1:1))}

Right now, when I'm trying this, it is giving me the "There's a problem with this formula." popup.

Thanks a lot for your help!

Best regard,

Gabriel
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe:

Book1
ABCDELMNOPQR
1ScoreRTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
2100AAAAAAAaaAAA
395AA+AAHAa1AA+
490AAAAAa2AA
585AA-AALAa3AA-RTG_SPRTG_DBRSRTG_MOODYRTG_FITCHScores in ascending order
680A+AHA1A+A+AAa3BBB60
775AAA2A75
870A-ALA3A-80
965BBB+BBBHBaa1BBB+85
1060BBBBBBBaa2BBB
1155BBB-BBBLBaa3BBB-
1250BB+BBHBa1BB+
1345BBBBBa2BB
1440BB-BBLBa3BB-
1535B+BHB1B+
1630BBB2B
1725B-BLB3B-
1820CCC+CCCHCaa1CCC
1915CCCCCCCaa2CCC
2010CCC-CCCLCaa3CCC
215CCCCCaDDD
220DDCDD
Sheet7
Cell Formulas
RangeFormula
R6:R9R6=SMALL(SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M$6:P$6),ROW(1:1))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Maybe:

Book1
ABCDELMNOPQR
1ScoreRTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
2100AAAAAAAaaAAA
395AA+AAHAa1AA+
490AAAAAa2AA
585AA-AALAa3AA-RTG_SPRTG_DBRSRTG_MOODYRTG_FITCHScores in ascending order
680A+AHA1A+A+AAa3BBB60
775AAA2A75
870A-ALA3A-80
965BBB+BBBHBaa1BBB+85
1060BBBBBBBaa2BBB
1155BBB-BBBLBaa3BBB-
1250BB+BBHBa1BB+
1345BBBBBa2BB
1440BB-BBLBa3BB-
1535B+BHB1B+
1630BBB2B
1725B-BLB3B-
1820CCC+CCCHCaa1CCC
1915CCCCCCCaa2CCC
2010CCC-CCCLCaa3CCC
215CCCCCaDDD
220DDCDD
Sheet7
Cell Formulas
RangeFormula
R6:R9R6=SMALL(SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M$6:P$6),ROW(1:1))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.

Thank you Eric.

However, I'm getting a small error that I can't fix that I forgot to mention in my initial post. It is possible that some of the credit agencies don't give a rating to a stock and therefore instead of the table values shown, it returns either a "NR" or "#N/A #N/A" or "#N/A Invalid Security". Right now, those error messages return a 0 and therefore it skews the rating.

This is what I'm trying to recreate:
"• If only one agency rates a security, use that rating;
• If two agencies rate a security, use the lower of the two ratings;
• If three agencies rate a security, use the middle of the three ratings;
• If four agencies rate a security, use the middle of the three lowest ratings"

Right now, this is the formula that I have, but it doesn't work perfectly when those "#N/A #N/A" come up because those return a 0 rather than a blank and therefore skew the "Lowest three or Lowest one" due to the 0 being accounted for:

{=INDEX(Credit_Ratings,MATCH(MIN((IF(COUNTIF(M6:P6,"#N/A*")=3,SMALL(SUMIFS(Credit_Ratings,OFFSET(Credit_Ratings,0,{1,2,3,4}),M$6:P$6),ROW(1:1)),999)),IF(COUNTIF(M6:P6,"#N/A*")=2,SMALL(SUMIFS(Credit_Ratings,OFFSET(Credit_Ratings,0,{1,2,3,4}),M$6:P$6),ROW(1:1)),999),(IF(COUNTIF(M6:P6,"#N/A*")=1,MEDIAN(SMALL(SUMIFS(Credit_Ratings,OFFSET(Credit_Ratings,0,{1,2,3,4}),M$6:P$6),ROW(1:3))),999)),IF(COUNTIF(M6:P6,"#N/A*")=0,MEDIAN(SMALL(SUMIFS(Credit_Ratings,OFFSET(Credit_Ratings,0,{1,2,3,4}),M$6:P$6),ROW(1:3))),999)),Table1[[#All],['#]],0),MATCH("RTG_SP",Table1[#Headers],0))}
 
Upvote 0
OK, try this:

Book1
ABCDELMNOPQR
1ScoreRTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
2100AAAAAAAaaAAA
395AA+AAHAa1AA+
490AAAAAa2AA
585AA-AALAa3AA-RTG_SPRTG_DBRSRTG_MOODYRTG_FITCHComposite Score
680A+AHA1A+#N/A Invalid SecurityAALA3A75
775AAA2A
870A-ALA3A-
965BBB+BBBHBaa1BBB+
1060BBBBBBBaa2BBB
1155BBB-BBBLBaa3BBB-
1250BB+BBHBa1BB+
1345BBBBBa2BB
1440BB-BBLBa3BB-
1535B+BHB1B+
1630BBB2B
1725B-BLB3B-
1820CCC+CCCHCaa1CCC
1915CCCCCCCaa2CCC
2010CCC-CCCLCaa3CCC
215CCCCCaDDD
220DDCDD
Sheet7
Cell Formulas
RangeFormula
R6R6=AGGREGATE(15,6,SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)/ISERROR(SEARCH("N",M6:P6)),1+(COUNTIF(M6:P6,"*N*")<2))


I assume that any value in M6:P6 that has an "N" in it is a non-value. Be sure not to use #N/A by itself because Excel interprets that as an error and will skew the results. Empty or invalid codes in M6:P6 will also skew the results.
 
Upvote 0
OK, try this:

Book1
ABCDELMNOPQR
1ScoreRTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
2100AAAAAAAaaAAA
395AA+AAHAa1AA+
490AAAAAa2AA
585AA-AALAa3AA-RTG_SPRTG_DBRSRTG_MOODYRTG_FITCHComposite Score
680A+AHA1A+#N/A Invalid SecurityAALA3A75
775AAA2A
870A-ALA3A-
965BBB+BBBHBaa1BBB+
1060BBBBBBBaa2BBB
1155BBB-BBBLBaa3BBB-
1250BB+BBHBa1BB+
1345BBBBBa2BB
1440BB-BBLBa3BB-
1535B+BHB1B+
1630BBB2B
1725B-BLB3B-
1820CCC+CCCHCaa1CCC
1915CCCCCCCaa2CCC
2010CCC-CCCLCaa3CCC
215CCCCCaDDD
220DDCDD
Sheet7
Cell Formulas
RangeFormula
R6R6=AGGREGATE(15,6,SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)/ISERROR(SEARCH("N",M6:P6)),1+(COUNTIF(M6:P6,"*N*")<2))


I assume that any value in M6:P6 that has an "N" in it is a non-value. Be sure not to use #N/A by itself because Excel interprets that as an error and will skew the results. Empty or invalid codes in M6:P6 will also skew the results.

Sir, I salute you and thank you SO MUCH! I think this works! I've been scratching my head for days on how to do this. I'm not familiar with the aggregate function but it clearly works. I'll have to do my homework on that. Also, if I want to ignore all ratings that include a "N" like you did but also any that include a "W". Could I replace the Countif by countifs and do multiple criterias? What about the search function, how should I adjust that part?

Thank you again so much!
 
Upvote 0
Well, believe it or not, checking for an N or a W really ramps up the difficulty level. Consider:

Book1
ABCDELMNOPQRS
1ScoreRTG_SPRTG_DBRSRTG_MOODYRTG_FITCH
2100AAAAAAAaaAAA
395AA+AAHAa1AA+
490AAAAAa2AA
585AA-AALAa3AA-RTG_SPRTG_DBRSRTG_MOODYRTG_FITCHComposite Score
680A+AHA1A+A+asdfB3BBB+2565
775AAA2A
870A-ALA3A-
965BBB+BBBHBaa1BBB+
1060BBBBBBBaa2BBB
1155BBB-BBBLBaa3BBB-
1250BB+BBHBa1BB+
1345BBBBBa2BB
1440BB-BBLBa3BB-
1535B+BHB1B+
1630BBB2B
1725B-BLB3B-
1820CCC+CCCHCaa1CCC
1915CCCCCCCaa2CCC
2010CCC-CCCLCaa3CCC
215CCCCCaDDD
220DDCDD
Sheet7
Cell Formulas
RangeFormula
R6R6=AGGREGATE(15,6,SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)/(MMULT({1,1},--ISNUMBER(SEARCH({"N";"W"},M6:P6)))=0),1+(SUM(SIGN(MMULT({1,1},--ISNUMBER(SEARCH({"N";"W"},M6:P6)))))<2))
S6S6=AGGREGATE(15,6,SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)/(COUNTIF(OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)>0),1+(SUM(COUNTIF(OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6))>2))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


The formula in R6 is my first shot at it, and it works fine, but it's long and complicated. I had to use MMULT to account for some cases where there might be an N and a W in the same cell. My next idea to simplify it a bit was to ask if there is a limited number of values like "NR", "#N/A Invalid Security", "W code" that we could put in a table and use MATCH with. Then I had another idea where instead of checking for values to ignore, I check to see if the values in M6:P6 actually exist in the Credit_Ratings table. That turned out to be slightly longer, but I think it works better. I'll have a think and maybe I can improve on it a bit.
 
Upvote 0
If you change the A22 value to 1 instead of 0, this is equivalent to the S6 formula and a bit shorter:

=AGGREGATE(15,6,1/(1/SUMIFS(Credit_Ratings[Score],OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6)),1+(SUM(COUNTIF(OFFSET(Credit_Ratings[Score],0,{1,2,3,4}),M6:P6))>2))

also with Control+Shift+Enter.
 
Upvote 0

Forum statistics

Threads
1,214,374
Messages
6,119,162
Members
448,870
Latest member
max_pedreira

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