Shortening Long Nested Formula

F4TMAN

New Member
Joined
Jun 29, 2020
Messages
25
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Looking for a possibility of making this formula shorter, any ideas? Thanks

Excel Formula:
=IF(AND(INDEX('Tab2'!$F:$M,MATCH($F$3,'Tab2'!$J:$J,0),7)=0,INDEX('Tab2'!$F:$M,MATCH($F$3,'Tab2'!$J:$J,0),8)>0),INDEX('Tab2'!$F:$M,MATCH($F$3,'Tab2'!$J:$J,0),1),"")

This formula is producing this
The active cell is A6. I'm looking to include a formula in A6 that will give me this result.
Lookup Division (F3), and in sheet2 under (column J) IF you find a match , look in the same row under Actual (Column L). IF under Actual shows Zero and then look under Budget , IF budget shows a
number greater than zero, then return the value listed under Code (column F)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
If you do not expect to have multiple matches in the Division column on sheet2 (column J), then this might work for you. This approach takes each of your conditions, and if all are true, then the corresponding value in the Code column on sheet 2 (column F) is returned. I'm assuming the Code "values" are numbers, but you didn't say. If they are text, then modifications are needed. If the multiplication of the arrays results in a 0, or if a 0 is found in the Code column on the same row of interest (that matches the Division), then the result will show as 0 rather than a blank. Again, if you want a blank, then modifications would be necessary. Also...note that I eliminated the whole column references...those can slow down the worksheet.
MrExcel20210214.xlsx
ABCDEF
1
2Division
3B
4
5Code
62000
F4TMAN
Cell Formulas
RangeFormula
A6A6=SUMPRODUCT((sheet2!$J2:$J100=$F$3)*(sheet2!$L2:$L100=0)*(sheet2!$M2:$M100>0)*(sheet2!$F2:$F100))


Sample sheet2 for testing:
MrExcel20210214.xlsx
FGHIJKLM
1CodeDivisionActualBudget
21000A1110
32000B020
43000C3330
54000D4440
6
sheet2
 
Upvote 0
Thank you very much for your prompt response. To answer, the Divisions are unique there shouldnt be any duplicate divisions, and yes Code values contain only numbers. For some reason I'm getting the #VALUE on the formula. Any thoughts where I might be going wrong?

Thanks


010.jpg


020.jpg
 
Upvote 0
Yes. You've specified a range that includes text instead of numbers...specifically this is the only one that matters...('Tab2'!$F1:$F25). This is related to my caveat earlier about text appearing in this column. SUMPRODUCT is throwing the error when it attempts to multiply the values in the first three arrays with the text value (which is the heading "Code" in cell F11 on Tab2). For a quick test, just delete "Code" from that cell to confirm that you get what is expected. Do you need the ranges to begin in row 1...or can they be changed to refer to the ranges between rows 12:16 on Tab2?
 
Upvote 0
As an alternative, you could slightly modify the last array expression by wrapping it within the N function and placing a unary plus operator (+) inside to coerce an array return from the N function...as shown below. This will return numbers when there are numbers and a 0 when there is text.
Excel Formula:
=SUMPRODUCT(('Tab2'!$J1:$J25=$F$3)*('Tab2'!$L1:$L25=0)*('Tab2'!$M1:$M25>0)*N(+'Tab2'!$F1:$F25))
 
Upvote 0
Yes. You've specified a range that includes text instead of numbers...specifically this is the only one that matters...('Tab2'!$F1:$F25). This is related to my caveat earlier about text appearing in this column. SUMPRODUCT is throwing the error when it attempts to multiply the values in the first three arrays with the text value (which is the heading "Code" in cell F11 on Tab2). For a quick test, just delete "Code" from that cell to confirm that you get what is expected. Do you need the ranges to begin in row 1...or can they be changed to refer to the ranges between rows 12:16 on Tab2?

Perfect it Worked! Must've missed that. I'll make the changes accordingly this was only a test so I'll be applying this to a much larger sheet with data. Thank you!
 
Upvote 0
Great! See my second suggestion about using the N function, just in case you might encounter text in column F. Glad to help.
 
Upvote 0
Great! See my second suggestion about using the N function, just in case you might encounter text in column F. Glad to help.
I might be pushing it but could i had another condition, instead of having L1:L25 = 0 can we say that, if L1:L25>0 or if M1:M25>0 then return the Code value? In other words if the any of the cells unders Actual or Budget has a value greater than zero then return the code value. and if both the Actual and Budget have zero values then return a "" blank space. Thanks a million
 
Upvote 0
If you are using your Excel 365 and there will be at most one row that matches the conditions then a possibility might be as follows.
I'm using the ranges more aligned to what you showed in post #3 but you can adjust those as required.

Excel Formula:
=FILTER('Tab2'!$F$12:$F$25,('Tab2'!$J$12:$J$25=$F$3)*(('Tab2'!$L$12:$L$25>0)+('Tab2'!$M$12:$M$25>0)),"")
 
Upvote 0
Sure...as Peter's solution in 365 illustrates, the OR condition implies which conditions are added together. In Excel 2019, following the earlier approach I described and accounting for potential text in the Code column, the formula would look like this...
Excel Formula:
=SUMPRODUCT(('Tab2'!$J1:$J25=$F$3)*(('Tab2'!$L1:$L25>0)+('Tab2'!$M1:$M25>0))*N(+'Tab2'!$F1:$F25))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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