Excel Array formulas details and guidance needed (INDEX,MATCH and SUM/COUNTIF) - arrays

So I'm having difficulties understanding fully how arrays works and when they are used by excel and specifically what happens in the background.
From reading the past few hours I understand that one of the reasons my Index Match doesn't work without array is simply because its a multicriteria Match that I use as below:
{=INDEX(D30:E36,MATCH(F33&G33,B30:B36&C30:C36),2)}
From what I understand the reason is that Match returns a {x,y} result which classifies it as an array formula. But considering the point is to get a row number, if the row I'm looking for is 5 then Match will return a {5,5} for row number for Index. And then Index interprets this as just 5? or what exactly happens in the background here?
Then I found an article which showed how to circumvent the array formula and not need ctrl+shift+enter as shown below. How does the below change things and what happens in the background?
=INDEX(D30:E36,MATCH(F33&G33,INDEX(B30:B36&C30:C36)),2)
The below is a an array SUM/COUNTIF formula which counts unique cells only which does not work without array brackets. Why is that and how does it work? It involves maths so I'm not sure.
{=SUM(1/(COUNTIF(A1:A5,A1:A5)))}
Thank you!

Related

Array Formula Confusion

I am struggling with an array formula, that logically seems sound, however it doesn't appear to be working correctly. I have been working on a complex sheet, that is not to include VBA, which has made it formula heavy, and using arrays instead.
In the image below, the first part is the problem, for the data shown in columns A-F, I wish to get a sum of the values that match the values in I1:K1.
The formula I have used to begin with can be seen in the first image also, this evaluates, pressing F9, to give me the desired output 20,40 & 50. However when I add the SUM around the formula, I only get the first result out.
I think this is an issue with me not seeing the wood for the trees on this one.
Thanks in advance.
This array formula seems to work:
=SUM((IFERROR(MATCH(A1:F1,I1:K1,0),0)>0)*A2:F2)
There are probably multiple better formulas to achieve the same thing.
But to talk about why this fails:
It is because of the OFFSET function returns a reference rather than a value. And so used in this array formula it returns an array of references {B2,D2,E2} instead of an array of values {20,40,50} which leads to the problem.
If you are using:
=SUMPRODUCT(OFFSET(A2,0,MATCH($I$1:$K$1,$A$1:$F$1,0)-1))
then using Evaluate Formula, you will get:
SUMPRODUCT({#VALUE,#VALUE,#VALUE})
in next to last step and 0 as the result. So the OFFSET leads to error values because of it returns an array of references which will not be dereferenced automatically and so will become #VALUE error each.
If you are using
=SUMPRODUCT(N(OFFSET(A2,0,MATCH($I$1:$K$1,$A$1:$F$1,0)-1)))
then it works and returns 110. So the N dereferences the references of each OFFSET and so the whole formula leads to an array of values {20,40,50} in sum.
{=SUM(N(OFFSET(A2,0,MATCH($I$1:$K$1,$A$1:$F$1,0)-1)))}
works too.
These problems occur using funktions like OFFSET and INDIRECT, which returns references rather than values, in array formulas. And having a dereferencing function around the OFFSET or INDIRECT stops the problems.
It is the same with:
=SUMPRODUCT(INDIRECT("R2C"&MATCH(I1:K1,A1:F1,0),FALSE))
versus
=SUMPRODUCT(N(INDIRECT("R2C"&MATCH(I1:K1,A1:F1,0),FALSE)))

SUM with IF conditions for cells containing both strings and numbers

I've got a bigger table with one column that I want to focus on, containing designation and a number. I want to simply sum the numbers that meet the criteria based on a designation.
For the simplification, I made an exercising sheet (on the pic) where I split second column into two - one string and one numeric. Since my file is quite large with many columns that would need this it would be inconvenient.
In the left column it's easy to solve the problem, it could be even easier with simple SUMIF function, but an array SUM(IF... function is, at least I think, only viable option here.
So I solved the first table with array function, but what confuses me is how to modulate the TRUE statement. Simple replacement of C:C
with
VALUE(MID(F:F;4;4))
which would format my cells to get the numbers from string does not work that way - returns zero in E12 field. F12 is just application of string to number for last cell, F10.
THIS formula does not work, even adapting to different versions of the tool.
I could use VB but if possible anyhow I would like to avoid it since parts will be shared on mobile phones.
Any ideas? Thanks a lot!
Left table was split, right original format
The array formula which you used can be replaced by the SumIf formula like below...
=SUMIF(B:B,"B",C:C)
Also without the helper column, you can use the Sumproduct formula to achieve the desired output.
But don't refer the whole column in the formula like in the above SumIf formula.
Try this..
=SUMPRODUCT((B1:B10="B")*MID(F1:F10,FIND(",",F1:F10)+1,255)*1)
Change the ranges as per your requirement but remember to make them equal in size.

Excel: How to use an Array to concatenate strings that are next to a criteread section (If function)

Good Day Everyone
I have an Excel sheet as bellow in two columns. I know how to use an array if function with sum to add up all values next to a column that has met the criterea as in {=sum(if(A1:A5="YES",B1:B5)} but how to go about doing it with strings and concatenate so that they show the result as below
Thanks for Any Help
The Excel array
Edit: I know there is a easy VBA solution, but was wondering if there is an excell way since there is an easy solution if it was values and not strings.
If I'm assuming you don't want the relatively easy VBA solution where you recurse through the initial list and concatenate the answers then you could put the following into B8:
=IFERROR(INDEX(Sheet1!$A$1:$A$6,SMALL(IF(Sheet1!$B$1:$B$6=$A8,ROW(Sheet1!$B$1:$B$6)-ROW(Sheet1!$B$1)+1),COLUMNS($B1:B1))),"")
You'd have to drag it across as it'll put them in separate columns but then you should be able to concatenate them into a single column afterwards.
You have to have Ctrl and Shift held down when inputting as it's an array formula.
Activate iteration in the options. The maximum number of iterations must be equal to or greater than the number of lines.
Add =IF(D1=100;1;D1+1) to cell D1
This is the formula in cell E1 for the Stark houses:
=IF(D1=1;"";IF(D1-1>COUNTIF(B:B;"Stark");E1;E1&INDEX(A$1:A$100;SMALL(IF(B$1:B$100="Stark";ROW($1:$100));D1-1))))
(I hope that I got the English names of the functions correctly.)
I missed one information: You must enter the function as an array function.
Thanks go to http://www.excelformeln.de/formeln.html?welcher=155
Was really Strugling to get it right and eventualy got an answer from a stackoverflow question on how to concatenate whole columns.
Sorted the data via B and then used =TRANSPOSE(A4:A6)
Then Used F9 on the function to get this line ={"Mansion1","Mansion 2","House 3"}
Copied and Concatenate and just remove the {
But this was not ideal as the data set I want to use this on is 2500+ lines :(
Manualy did it though :( :( but will try the above answers for future use.

How to arrange table data differently by using if, match, and index?

As shown in the attached image, I need to convert A2:D10 to the format of A12:E17. The 4 tables from F1 to AB12 are my experiments using if, match, and index. Same formula gets different results and it seems to be dependent on the row position of the tables. In My previous question, I was trying to pinpoint the problem to the if function.
What am I doing wrong here?
Thanks,
Lu
enter image description here
Again, as I said in your last question: The formula has not been array entered. Array formulas need to be confirmed with Ctrl-Shift-Enter.
Without that, the first array in the IF statement does not get resolved and the Match does not return the correct result.
Make use of the Evaluate Formula tool and step through the formula.
The merged cells don't help with the cell referencing. Unmerge the cells and fill in all the labels in row 1, then use this slightly amended formula and confirm it with Ctrl-Shift-Enter. Then copy across and down.
I hope that I get the English names of the functions right:
In D14 and following cells:
=INDEX($C$1:$C$5;MATCH(1;MMULT(($B$3:$B$10=$A14)*($A$3:$A$10=B$13);1);0))
The MATCH function tells which value (by number counted from the top) matches both conditions. The INDEX function returns this value from C1:C5.

Nested OR with AND and IF - Excel

Simple question that I wasn't able to figure out. Trying to calculate counts and medians of arrays with a conditional that depends on numbers in two columns in Excel, as seen below.
=MEDIAN(IF(AND($D$3:$D$1216=1,OR($B$3:$B$1216=3,$B$3:$B$1216=6,$B$3:$B$1216=9,$B$3:$B$1216=12)),$M$3:$M$1216))
Please see above for the function, which I input as an array. All I'd like to do is scan Column D for all 1s and then 3/6/9/12 in Column B.
The function works but only returns zeroes for all relevant values in Column D, which I find strange.
Thank you for your help!
Is 0 in fact the most common element in $M$3:$M$1216? i.e., are a lot of those cells just blank?
When I keep the range large, but only enter a few values, I get the same result as you. When I shrink the range to something more manageable, and fill in the values, the function returns what I'd expect.
Also, here's a somewhat simpler syntax for the same result:
=MEDIAN(($D$3:$D$5=1)*OR($B$3:$B$5=3,$B$3:$B$5=6,$B$3:$B$5=9,$B$3:$B$5=12)*($M$3:$M$5))

Resources