Hi Everybody
I have this spreadsheet (attached for your convenience) that has a big array formula. It seems to work ok. However, when I use the same array formula as a part of an if conditon, it comes up with an error when the if condition is false. For example, in the attached spreadsheet, have a look at the formula in cell AA33 :-
=LARGE(OFFSET(INDIRECT("'DataFromXMLFiles'!"&ADDRESS((MATCH(CONCATENATE($B33,$C33,$D33,$A33),(CONCAT ENATE(INDEX(Table3[#Data],,1),INDEX(Table3[#Data],,2),INDEX(Table3[#Data],,3),INDEX(Table3[#Data],,6))),0)+ROW(Table3[#Data])-1),COLUMN(Table3[#Data]))),0,4,SUMPRODUCT(--(INDEX(Table3[#Data],,1)=$B33),--(INDEX(Table3[#Data],,2)=$C33),--(INDEX(Table3[#Data],,3)=$D33),--(INDEX(Table3[#Data],,6)=$A33)),1),AA$20)
This returns a numeric value as expected. No problems!
In the cells AB33 and AC33, the same formula has been entered as an if condition. In the cell AB33, the if condtion is false whilst in cell AC33 it is true. In AC33, the formula evaluates correctly to "Empty" whilst in AB33 is returns an error condition. Why?
These formulas are all array entered that is CSE confirmed.
Any suggestions, please?
Best regards
Deepak
Last edited by DonkeyOte; 06-28-2011 at 03:09 AM. Reason: Forgot the attachment D.O: modified title - missed original.
Deepak,
Given your use of XL2007(+) [.xlsm and use of Table object] you should be using SUMIFS/COUNTIFS rather than SUMPRODUCT - this holds true for your Array also.
Note: I've not altered the syntax from your original too much but embedded an INDEX to remove need for Array entry (arguably less efficient but perhaps a little more robust)Y25: =IFERROR(LARGE(OFFSET(INDEX(Table3[#Data],1,5),MATCH(CONCATENATE($B25,$C25,$D25,$A25),INDEX(CONCATENATE(INDEX(Table3[#Data],,1),INDEX(Table3[#Data],,2),INDEX(Table3[#Data],,3),INDEX(Table3[#Data],,6)),0),0)-1,0,COUNTIFS(INDEX(Table3[#Data],,1),$B25,INDEX(Table3[#Data],,2),$C25,INDEX(Table3[#Data],,3),$D25,INDEX(Table3[#Data],,6),$A25),1),Y$20),"") confirmed with Enter applied to matrix as appropriate
You might want to consider adding a key to your Tables that concatenates A, B, C & F in each row to simplify the match process.
Your #N/As were the result of your concatenated MATCH failing - hence the outer IFERROR.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Belatedly I realise I should have also shown the embedded IF approach which would:
a) remove Volatility (no OFFSET etc...)
b) improve efficiency (exiting the LARGE upon first False)
c) shorten formula
obviously Array entry is required ... note I reverted the INDEX to Table[Column]Y25: =IFERROR(LARGE(IF(Table3[CustomerState]=$B25,IF(Table3[FuelType]=$C25,IF(Table3[CustomerType]=$D25,IF(Table3[PeriodSpan]=$A25,Table3[Total])))),Y$20),"") confirmed with CTRL + SHIFT + ENTER (enter alone will not suffice) applied to matrix as appropriate
Last edited by DonkeyOte; 06-28-2011 at 01:59 AM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Hi DonkeyOte
Point taken - henceforth will try and make the thread title closer to the problem.
With reference to your first solution where you have suggeseted use of Countifs() function, no problem. Howerver, you said that error #N/A in cell AB33 is because of the Match() function failing, that is not correct. The Match() function doesn't fail - it does return the value of 123. Further, regardless of what the if condition in cell AB33 evaluates to (be it True or False), the Large() function, as either the True or the False part of the if condition, for some reason, returns #N/A. The Large() on its own in a separate cell would evaluate to 11. Now I am not so sure about why is this happening. It may be because the if condition, in this case, is a non array formula evaluation while the Large() function evaluation is an array formula evaluation and possibly the two don't mix - this is just my guess! I have even tried replacing the sumproduct() function in the if condtion with the Countifs() function - but it still gives the same result - #N/A. Any ideas why?
Your second solution, where you have used the Iferror() function, works ok, no problems with that. But, isn't it true that the if condition is inherently more inefficient than an equivalent Index() function. I appreciate that I could add a key to the table to simplify the concatenated match condtion which would eliminate the 3 if or the 3 Index() functions - but wouldn't it be better to use Index() function over If condtion? In both cases, the entire search range will need to be scanned as many number of times as the if condtion or the Index () function.
I may be wrong is what I may have said. Feel free to correct me if that is the case.
Best regards
Deepak
At work presently but will look later - I had not noticed the inconsistent formulas in your table.
Not really. INDEX is a slow function per se though I confess it's still my "favourite" given it's amazing versatility. The embedded IF approach is pretty efficienct because the evaluation ends at the point of any condition failiing.Originally Posted by agarwaldvk
To retierate: if as implied efficiency is important then the approach you previously adopted should be avoid for those reasons outlined previously.
SUMPRODUCT and Arrays are inefficient and should be used in moderation and in my opinion you should look to avoid using in volatile context given the potential for significant calculation overhead.
Last edited by DonkeyOte; 06-29-2011 at 04:56 AM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks