=INDIRECT(ADDRESS(ROWS(ADF$1:ADF1642),MATCH(sheet2!$C$25:$C$29,sheet1!1:1,0)))
That formula returns {"$AFX$1642";"$AJR$1642";"$AKF$1642";"$AJD$1642";"$AIP$1642"} without the Indirect, and the values in those cells with the Indirect prefix. I need to sum them all, but it only returns the first: $AFX$1642.
There are indeed similar topics, but their solutions do not include the lookup nature of matching an array from sheet 2, to the array in sheet 1 that has a multitude of columns to quote, unquote, "exclude".
Halp!
I'm not particularly fond of your current set-up, I have to say (a worksheet which references up to column AIP?!), nor of the current formula you are using (there is almost always a better alternative to constructions using INDIRECT/ADDRESS). However, without knowing precisely what you are trying to achieve, and not being able to see an actual workbook, it's difficult to suggest improvements.
The coercion you require with your current construction is:
=SUMPRODUCT(N(INDIRECT(ADDRESS(ROWS(ADF$1:ADF1642),MATCH(Sheet2!$C$25:$C$29,Sheet1!1:1,0)))))
Regards
Related
I've been retooling some older spreadsheet tools for filtering and formatting dynamic data outputs using Excel's newer Dynamic Array Formulas functionality. This has been helping remove some of the need for pre-allocating cells and lower amounts of helper columns (which has allowed for reduced file sizes and snappier performance).
One function type I am struggling to replace is pulling out dynamic, running duplicate counts.
For instance, say I have a column B of 20 names that can vary in length from a handful to say 200 names. There is also related data in columns C, D, etc that similarly varies in size. For use of filtering the Data in the later columns, we currently use a helper column in A consisting of the running count of the duplicates in A with a formula using semi-anchored ranges(ie. Beginning the range with an anchored cell that expands as the formula is copied down the helper column akin to the solution here with CountIf() and a semi-anchored range). The drawback here vs the new dynamic array formulas is that the helper column needs to be pre-allocated for the data.
Despite attempts with Index(), Aggregate(), Filter(), and a few more involved notations like Sumproduct(--(...)), the most straightforward method I can find to make helper column A seems to be by creating the running count via semi-anchored ranges, which unfortunately does not seem to translate well to the new dynamic array Formulas.
Has anyone had any luck adapting the use of semi-anchored ranges and formulas for use in dynamic array formulas?
To use the dynamic array formula we need to use OFFSET which is volatile.
=COUNTIFS(OFFSET(A1,0,0,SEQUENCE(COUNTA(A1#))),A1#)
Appreciate this is an old post, but for future reference (I personally at least couldn't find an answer elsewhere), the below seems to work as a non-volatile formula alternative.
=LET(InputArray,A1#,
RowCount,ROWS(InputArray),
Temp,1*(InputArray=TRANSPOSE(InputArray)),
MMULT(TRANSPOSE(IF(SEQUENCE(RowCount,1)>SEQUENCE(1,RowCount),0,Temp)),SEQUENCE(RowCount,1,1,0)))
I'd like to know if it's possible to use the SUMIF function with implicit or "nested" arrays. With "implicit" array I mean a matrix which data isn't in it's final form in any rank of the spreadsheet, but it's function of some other array. For example, lets say that we have data of an independent variable (which values, all integers, range from 0 to 5) in the rank A1:A100, and data of a dependent variable in B1:B100. With the SUMIF function we may calculate easily, for example, the sum of the dependent variable when the independent is 4. But if we want to know the sum of the SQUARES of the dependent variable it's not that easy, indeed, the SUMIF function gives an error if we write SUMIF(A1:A100;4;B1:B100^2) no matter how we enter it (as array or as a simple formula).
Is there any way to do this without having to waste an entire column for the squares of the values of column B?
I know that for this very example the function SUMPRODUCT((A1:A100=4)*B1:B100^2) would do the job, what I don't know is how to "nest" arrays (which is very useful) in general.
The answer is no, I'm afraid. The ranges used in COUNTIF(S)/SUMIF(S)/AVERAGEIF(S) must be either:
1) References to worksheet ranges
2) Constructions which resolve to references to worksheet ranges
One example of the former:
=SUMIF(A1:A10,"A",B1:B10)
And two of the latter (which just happen to be identical to the above):
=SUMIF(A1:INDEX(A:A,10),"A",B1:INDEX(B:B,10))
=SUM(SUMIF(OFFSET(A1,{0,1,2,3,4,5,6,7,8,9},),"A",OFFSET(B1,{0,1,2,3,4,5,6,7,8,9},)))
Here SUMPRODUCT has the advantage over this group of functions, in that constructions may be passed which do not necessarily resolve to worksheet ranges.
However, it might well be the case that a more efficient set-up is achieved by, as you suggested, first using an additional column within the worksheet to compute the squares and then referencing that column within a SUMIF, not least since one of the major advantages that COUNTIF(S), SUMIF(s), etc. can claim over SUMPRODUCT is that arbitrarly large references can be passed with no detriment to calculation performance. For example, the difference in performance between:
=SUMIF(A:A,"A",B:B)
and:
=SUMPRODUCT(0+(A:A="A"),B:B)
is enormous, the latter, having to process all 1,048,576 cells within that range (whether they are technically beyond the last-used cells or not), being not at all recommendable.
Regards
I am interested in spreadsheet functions, not VBA solutions, to be included in a single cell formula.
[A1:A15 contain numeric values from 1 to 127, B1:B15 contain integers from 1 to 7 that set a divisor.]
Given the function:
=SUMPRODUCT(MOD(FREQUENCY(A1:A15;A1:A15);B1:B15))
FREQUENCY(A1:A15;A1:A15) gives a 1-column array of 15+1 rows, whereas the second part (B1:B15) is a 1-column array of 15 rows.
I would like to change the resulting array given by FREQUENCY (only in memory -not explicit in sheet-) from a 1-column 16 rows array to a 1-column 15 rows array with the first 15 cell values of that array.
[FREQUENCY documentation: https://support.office.com/en-us/article/FREQUENCY-function-44e3be2b-eca0-42cd-a3f7-fd9ea898fdb9 NB: for Excel, second remark states number of elements that depend on bins_array. ]
I would appreciate suggestions.
Thus, both arrays within MOD will have the same dimensions and SUMPRODUCT will not find cells with error values. I can disregard error values using IF and ISERROR within SUMPRODUCT, but I'd rather disregard the non-relevant part of the FREQUENCY resulting array if it is possible.
It has been thought that making it more specific might be more helpful, so it has been heavily reduced and simplified.
With external help, I have been able to fine-tune a way to solve my problem using INDEX in array formula mode. I am posting the answer in case it helps others.
One way: Put FREQUENCY(A1:A15;A1:A15), or any formula that produces an multi-cell array, within INDEX and have 2nd and/or 3rd arguments as array of consecutive values which will represent rows/columns.
INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(FREQUENCY(A1:A15;A1:A15)-1));1)
First argument within INDEX is the resulting array coming from a formula to shrink (from 16x1 to 15x1), which would be a multi-cell array formula if explicitly entered; second argument is the array 1..15 given by row numbers from 1 to the number of total rows of the "array from formula to shrink" MINUS 1: the first 15 (out of 16) values in the array from a formula; 3rd argument is the column of the shrank array (if need be, more than one could be selected using an analogue to the second argument).
In the particular case of FREQUENCY, because it is known that we are interested in the "bins" part of the function, the formula can be simplified by including the total rows of the "bins"/"intervals" array inside FREQUENCY (its second argument). We will have
INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(A1:A15)));1)
and the complete formula would become
SUMPRODUCT(MOD(INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(A1:A15)));1);B1:B15))
Now, both dividend and divisor of MOD have exactly the same dimensions (15x1) and because B1:B15 includes integers greater than 0 there are no errors.
Thanks all for helping me in making question more concise and better formatted.
ADDITIONAL INFORMATION: As pointed out correctly in comments by XOR LX, this does not seem to work in the widely popular spreadsheet software Excel. It has been developed for an INDEX function inside SUMPRODUCT as used in Open Office Calc which I had mistakenly thought 100% equivalent to Excel's version. A more complete answer perhaps using other functions would be appreciated.
In the previous answer, XOR LX points out very correctly that this formula cannot work in Excel, due to row_num/column_num argument behaviour. Very kindly XOR LX has shown me how that approach can work, and also thanks and credit for supplying a good answer: "INDEX can be used to redimension array (even dynamically created ones) if the row_num/column_num array is coerced to take an arbitrary array with the right dimensions, as shown on this blog entry " The following formula has been checked in Excel 2010 and has the expected results:
SUMPRODUCT(MOD(INDEX(FREQUENCY(A1:A15,A1:A15),N(INDEX(ROW(INDIRECT("1:" & ROWS(A1:A15))),,)),1),B1:B15))
NB: row_num argument of first INDEX, a ROW generated auxiliary array, has been nested inside N(INDEX([...],,)); at least one comma is necessary to account for the two arguments minimum of the nested INDEX. It is in itself interesting the discussion that applies generally to INDEX's arguments, and other functions', that need to be coerced to take arrays (see, here and here at XOR LX's blog). For Open Office users it might be worth stressing the point made at the blog
Unlike OFFSET, (...) for which the first parameter must be a
reference (...) in the worksheet, INDEX can also accept –
and manipulate – for its reference arrays which consist of values
generated e.g. via other subfunctions within the formula. XOR LX's blog
That would be indeed the case in changing the dimension in an array as in this question, but also useful in reversing or displacing the values in an array, for example. Open Office accepts arrays as row_num/column_num, so the coercion is not needed and some formulas rely on this, but without it, these formulas are unlikely to work when files are open in Excel.
Regrettably, this type of coercion is not passed correctly to Open Office, and formula need to be "decoerced" to work, at least in my casual tests.
In order to use a formula that would work in both spreadsheet programs regarding shortening arrays, the only thing I have managed is the following (required: arrays must be single-column)
SUMPRODUCT(
(COLUMN(INDIRECT("R1C1:R"& ROWS(vals_to_mod) &"C"& ROWS(FREQUENCY(vals_for_freq,vals_for_freq)),FALSE))
-ROW(COLUMN(INDIRECT("R1C1:R"& ROWS(vals_to_mod) &"C"& ROWS(FREQUENCY(vals_for_freq,vals_for_freq)),FALSE))
=0)
*MOD(TRANSPOSE(FREQUENCY(vals_for_freq,vals_for_freq)),vals_to_mod)
)
(it "shortens" one array to the shortest of the pair, by creating an auxiliary array with TRUE/1s on the diagonal starting top-left and FALSE/0s elsewhere, therefore disregarding all defined values outside the square section of the array. Thus, SUMPRODUCT adds values within the diagonal of the square section which are the product of the corresponding values up to the last value of the shorter array.)
I'll try to explain the problem I'm facing best as I can.
A have a set of data that contains multiple duplicates extracted as an excel file. Within this data are "keys" that I want to use to filter out relevant data from another workbook.
I start by removing duplicates from the list of keywords and I think I got this working kind of satisfactory. I then try to extract and calculate the minimum from the values using the following array formula:
=MIN(VLOOKUP(Blad1!D2:D8,Blad2!A3:D9,2))
However, this doesn't work as expected. The value returns the minimum value from the target range, but seems to ignore the provided keywords. Instead it simply finds the minimum value of the entire range.
I am far from a professional when it comes to excel so any suggestions on how this could be done in a more efficient way are welcome.
Here is a link to a sample document.
These array formulas should be what you need.
'MINIF in F2,
=MIN(IF(COUNTIF($D$2:$D$8, Blad2!$A$2:$A$9&""), Blad2!$B$2:$B$9))
'MAXIF in G2
=MAX(IF(COUNTIF($D$2:$D$8, Blad2!$A$2:$A$9&""), Blad2!$C$2:$C$9))
'AVERAGEIF¹ in H2
=AVERAGE(IF(COUNTIF($D$2:$D$8, Blad2!$A$2:$A$9&""), Blad2!$D$2:$D$9))
Array formulas need to be finalized with Ctrl+Shift+Enter↵.
Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum.
The results are 15, 35 and 23.6.
¹Note that this is NOT the native AVERAGEIF function or AVERAGEIFS function but an array formula. This approach was chosen due to the large number of criteria.
I have a vector array that contains Time values in an asceding order. With relational expressions I can obtain subset values from that array, after that I need the first value of that subset without creating new variables.
For example.
Time is an column vector, then I can use Time(something==X) to get a subset values of Time, but then I need the first value of Time(something==X), I can't use Time(something==X)(1) like some programming languages u.u
Unfortunately with MATLAB you need to use temporary variables. It doesn't support this kind of indexing, though it is quite natural and I would love if they supported it.
You would have to do this:
x = Time(something==X);
y = x(1);
Octave does have the ability of doing this kind of indexing though. The only way I can think of you escaping this is if you use cell arrays. However, if you want to use a normal vector, then you're SOL.
EDIT: May 13th, 2014 - Referencing David's comment, it is possible to do this without a temporary variable, but readability is very poor. In the end, a temporary variable is still the better way for readability and reproducibility. Check the following SO post that he has referenced:
How can I index a MATLAB array returned by a function without first assigning it to a local variable?