using OFFSET with an array of columns then SUMPRODUCT - arrays

i have this formula and it works fine:
=OFFSET(INDIRECT(CELL("address";INDEX(INDIRECT($F6&"!C:C");MATCH($G$2;INDIRECT($F6&"!C:C");0))));0;14;1;1)
i give it name of a sheet and a value in a certain column in that sheet and it returns the number in the 14th column in front of that target value. the value in that cell is in fact sum of 12 values beside it (12 values for 12 months of the year).
the hot point:
;14;1;1)
now i want to change the formula so that it returns an array of 12 values so that I can then sumproduct them with another array. actually I want to be able to choose which months to be included in the final sum operation. I changed the above formula to the following:
SUMPRODUCT(OFFSET(INDIRECT(CELL("address";INDEX(INDIRECT($F6&"!C:C");MATCH($G$2;INDIRECT($F6&"!C:C");0))));0;{2;3;4;5;6;7;8;9;10;11;12;13};1;1);$E$52:$E$63)
the changed part:
SUMPRODUCT( ..... ;{2;3;4;5;6;7;8;9;10;11;12;13};1;1);$E$52:$E$63)
a simple change, apparently, but it returns zero.
thanks for help

The first argument in SUMPRODUCT returns an array of references. As such, you'll need to obtain the values from those references by "de-referencing". One way would be to pass the array of references to the N() function. So your formula should be as follows...
=SUMPRODUCT(N(OFFSET(INDIRECT(CELL("address",INDEX(INDIRECT("'"&$F6&"'!C:C"),MATCH($G$2,INDIRECT("'"&$F6&"'!C:C"),0)))),0,{2;3;4;5;6;7;8;9;10;11;12;13})),$E$52:$E$63)
Note that my version of Excel uses the comma as a list separator. Therefore, adjust the formula accordingly.

Related

How to use a string from a single cell as an array in a function without VBA

How do I convert a string from a cell to a text array inside of a function, that should use the array, without using VBA and without adding the array into any other part of the document? It will be one of these arrays on more than 1000 rows. The string format is ^[a-zA-Z0-9.,-]*$ with "," as delimiter.
This is the functionality I would like to achieve
I have an excel table with the following columns
A: ID numbers to compare, separated by comma (delimiter can be changed if needed). About 100 ID's would be good to support at least.
B: ID (Each value on the rows in the column are unique but not sorted and can't be sorted because sorting is needed based on other criterias)
C: Value (Several rows in the column can have the same value)
D: Output the one ID of the comma separated ID's that has the highest value on its row
The problem part of the output
So far I have made a function which find the correct ID in column B based on the values in column C but only if I enter the string from column A as an array constant manually within the function. I have not managed to get the function to create the array itself from column A, which is required.
Working part of the code
In this code I have entered the values from column A manually and this is working as it should.
=INDEX({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},MATCH(MAX(INDEX(C$10:C$20,N(IF(1,MATCH({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},B$10:B$20,0))))),INDEX(C$10:C$20,N(IF(1,MATCH({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},B$10:B$20,0)))),0))
Note that the start row is not the first row and the array is used 3 times in the function.
Code to try to convert the string to a text array
Not working but if wrapped in SUMPRODUCT() it provide an array to the SUMPRODUCT() function, of course not usable since I then can't pass on the array. The background to this code can be found in question Split a string (cell) in Excel without VBA (e.g. for array formula)!.
=TRIM(MID(SUBSTITUTE(A10,",",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(A10)-LEN(SUBSTITUTE(A10,",",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(A10)-LEN(SUBSTITUTE(A10,",",""))+1)))=1),99))
The second code output the first item of the array and inserted in the first code do not change this result as it did when wrapping the second code in SUMPRODUCT().
Here is a picture of my simplified test setup in Excel for this case, identical to what is described above.
Simplified test setup
I'm not really sure what you are doing with your formula.
But to convert contents of a cell to a comma separated text array to be used as the array argument to the INDEX or MATCH functions, you can use the FILTERXML function. You'll need to educate yourself about XML and XPATH to understand what's going on, but there are plenty of web resource for this.
For example, with
A10: "1.01-1","1.01-3","1.08-1","1.01-1-1A"
The formula below will return 1.08-1. Note the 3 for the row argument to the INDEX function.
=INDEX(FILTERXML("<t><s>" & SUBSTITUTE(SUBSTITUTE(A10,"""",""), ",", "</s><s>") & "</s></t>", "//s"),3)

How can I find and pass a cell reference into the StDev.P command in Excel 2010?

I would like to pass a cell reference into the STDEV.P function in Excel, but when I do this I keep getting a #DIV/0 error.
I have two columns in Excel. Column A contains a list of dates starting Jan-1-2012 and going to the current date. Column B contains a list of integers. I have over 800 rows of data and it's possible that integers in column B are repeated somewhere in the 800 rows of data.
I want to find the STDEV of an array of values in Column B. The array is determined by a begin date and an end date. The end user can decide which begin and end dates are to be used. For example, if the begin date is 1/1/2015, I want to find the corresponding integer in column B for this date and pass the CELL REFERENCE into the STDEV formula. I want to do the same for the end date. The end result is a STDEV calculation that uses the array of integers determined by user supplied begin & end dates.
I've been able to find the cell location (e.g. value .332 is in cell D45) using the MATCH, INDEX and ADDRESS functions, but when I try to pass D45 into the STDEV function, I get the error. Help!
Many users believe that an INDEX(MATCH(...)) pair only returns a cell value in a lookup but in fact it can be used to return a cell reference without the INDIRECT function's overhead. Two of them can even be joined with a colon to form a valid cell range to be used in any number of formulas.
        
The formulas in F2:H2 are,
=STDEV(INDEX(B:B, MATCH(D2,A:A, 0)):INDEX(B:B, MATCH(E2,A:A, 0))) ◄F2
=STDEV.P(INDEX(B:B, MATCH(D2,A:A, 0)):INDEX(B:B, MATCH(E2,A:A, 0))) ◄G2
=SUM(INDEX(B:B, MATCH(D2,A:A, 0)):INDEX(B:B, MATCH(E2,A:A, 0))) ◄H2
I've included a simple SUM function so that you can quickly verify that the method used is returning the correct cell range without doing the math on a StDev.
Of the many lookup functions, this is an INDEX function trait. The VLOOKUP function or HLOOKUP function cannot be used in this manner as they are only returning the values.
Assuming your start date is in D1 and your end date in D2 please try:
=STDEV.P(INDIRECT("B"&MATCH(D1,A:A,0)&":B"&MATCH(D2,A:A,0)))
As long as the dates are unique it should not matter that the other values are not.

How to use arithmetic operators to get cell location

I'm trying to perform math within an Excel formula to specify the end of an array. Here is a simple version of what I want to do:
A B C
1 =COUNTA(A1:A5)-1 =SUM(A1:A(1+B1))
2
3
4
5
The first column is my data array. The second column counts the number of entries in that array (so if it isn't full, it returns a value less than 5). The third column sums the array starting with the first value and ending with the last entered value. Obviously with the SUM function it doesn't matter if there are zeroes, but I am trying to use the MATCH function and I don't want it to return a zero just because there are blank entries in the array I'm looking up.
So I want to modify the information within the SUM function to produce a variable array length based on the return value of B1. I hope this is clear. Thanks for any help!
One way is to use INDEX like this
=SUM(A1:INDEX(A:A,B1+1))
you can use the range defined by
A1:INDEX(A:A,B1+1)
in other functions like MATCH
Like this?
=SUM(INDIRECT("A1:A"&(1+B1)))

Excel arrays count totals using criterias from multiple ranges (or sheets)

What I would like to do is to count the amount of lines that matches criterias to be verified in two arrays.
I can't use VBA, add new columns (for instance a new column with VLOOKUP formula) and preferably use arrays.
I have two separate ranges, each with a ID column for the identifier and other fields with data.
For instance, range 1:
Range 2:
If I had only to check the first range I would do:
={SUM((D4:D7="Red") * (E4:E7="Big"))}
But I don't know how to check also using data from the other range.
How, for example, to count the number of items that are Red, Big and Round by using both Ranges ?
Put this in the cell F4:
=IF((VLOOKUP(C4,$C$11:$D$12,2)="Round")*(D4="Red")*(E4="Big"),1,"")
Note that the behavior of VLOOKUP is that it finds the value up to the first parameter. Since there's no 1 in your second dataset, this first cell is going to show "#N/A", which I don't know how to solve, but when you extend this formula down to also compare the other sample data in the first set, the ID numbers 2 and 4 will show up as "yes" for you.
Edit: You wanted a count of this list. So after this, it should be easy to get a count of cells in this column using the COUNT function.
Try this array formula
=SUM((D4:D7="Red")*(E4:E7="Big")*ISNUMBER(MATCH(C4:C7,IF(D12:D13="Round",C12:C13),0)))
The last part is the added criterion you want - the IF function returns {2,4} [IDs where Data 3 is "Round"] and then you can use MATCH to compare C4:C7 against that. If there is a match you get a NUMBER (instead of #N/A) so you can then use ISNUMBER to get TRUE/FALSE and that feeds in to your original formula - result should be 2

Sumproduct formula returns a #VALUE! error when the last array refers to a column with formulas in every row. MS Excel 2010

I am trying to find an easy way to calculate commissions off of sales on multiple sheets within a workbook. Each month, I need to find the total net profit for only items sold within the specified month.
The formula I am currently using is:
=SUMPRODUCT((TEXT('Sheet Name'!$P$3:P24,"MY")=TEXT($G$4,"MY"))*'Sheet Name'!$M$3:M24)
Column P shows the Sold Date,
Column M includes a formula in each row to calculate the net profit, and
cell G4 is where I would enter the month & year I am currently working with.
I have come to the conclusion that it only gives me the #VALUE! error because of the formula in each row of Column M (example: =IF(OR(F15=0,G15=0)," ",(F15-L15)) ).
When I reference a different column (in place of Column M) that does not contain formulas it works perfectly (example: =SUMPRODUCT((TEXT('Sheet Name'!$P$3:P24,"MY")=TEXT($G$4,"MY"))*'Sheet Name'!$G$3:G24) ). Also, changing the astrisk to a comma causes the formula to calculate incorrectly and add the (--(TEXT double negative does not fix the problem.
How to I get this array to calculate without removing the formulas from Column M?
Thanks for your attention.
I presume it is giving you a #VALUE error because your formula results in text (a space) and it errors when trying to multiply a space by a number (aka True or False). I think you would be better served changing your M column formula to =IF(OR(F15=0,G15=0),0,(F15-L15)). Do you have a specific reason to not make it evaluate to 0? Also is there a reason you are converting to text to do your month/year check?
Try something like this: =SUMPRODUCT(--(MONTH('Sheet Name'!$P$3:P24)=MONTH($G$4)),--(YEAR('Sheet Name'!$P$3:P24)=YEAR($G$4)),'Sheet Name'!$M$3:M24). Of course this is dependent on entering the dates as actual dates. The -- is used to change a logical/boolean (true/false) into a 1 or 0. It won't do anything useful to text. For example, it should also work as =SUMPRODUCT((MONTH('Sheet Name'!$P$3:P24)=MONTH($G$4))*(YEAR('Sheet Name'!$P$3:P24)=YEAR($G$4))*'Sheet Name'!$M$3:M24) since the multiplication converts the truthy statements to numbers. The trick is to make sure when everything else evaluates, you have =sumproduct(numbers,numbers,numbers). Your instance is one array of =sumproduct(numbers/text).

Resources