Using Indirect with SumProduct - excel

Following this question, I am trying to implement the SUMPRODUCT(ABS()) formula to include an INDIRECT. The reason for this is that I want to run the calculation for each combination of employees. Row 2 now contains a list of all employees and column A contains the same list of all employees. I'm attempting the following formula in cell B3. I am getting a #VALUE error:
=SUMPRODUCT(ABS(INDIRECT("Sheet1!J"&ROW(A3)-1&":BB"&ROW(A3)-1)-INDIRECT("Sheet1!J"&COLUMN(B2)&":BB"&COLUMN(B2))))

ABS in older version outside Office 365 does not like to use arrays and as such we must "force" it to use arrays with N().
Also avoid INDIRECT if possible as it is volatile and will cause calc slow down.
=SUMPRODUCT(ABS(N(INDEX(Sheet1!J:BB,ROW(A3)-1,0)-INDEX(Sheet1!J:BB,COLUMN(B2),0))))

Related

Aggregating Price using IFERROR/SUMIF

Problem
Unable to sum prices for different part numbers using the combo of formula mentioned below
What Am I Trying To Accomplish?
I am trying to sum up prices for various part numbers in a different sheet. They are in millions
My Formula
I am using a combination of IFERROR and SUMIF
What my desired result should look like
Note
When using the combo of IFERROR and SUMIF I am considering both Part num and ALT Part so that if either of the two exists, it should sum the price for both
Thanks
Perhaps you may try using SUMPRODUCT() Function,
• Formula used in cell C2
=SUMPRODUCT((--ISNUMBER(MATCH($G$2:$G$9,A2:B2,0)))*($F$2:$F$9))
To explain the above Formula.
• We are using MATCH() Function to find the positions of the both Part Numbers in the range G2:G9
=MATCH($G$2:$G$9,A2:B2,0)
The above on evaluating returns
{1;#N/A;#N/A;#N/A;2;#N/A;#N/A;#N/A}
• Next we are wrapping this within an ISNUMBER() Function to exclude the #N/A and to take only numbers.
ISNUMBER(MATCH($G$2:$G$9,A2:B2,0))
Which returns
{TRUE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE}
• Using double unary to convert the Boolean values to 1's and 0's
{1;0;0;0;1;0;0;0}
• Next we are then doing a matrix multiplication of the 1's with the corresponding range i.e. F2:F9
(--ISNUMBER(MATCH($G$2:$G$9,A2:B2,0)))*($F$2:$F$9)
Which returns,
{5000;0;0;0;5000;0;0;0}
• Lastly we wrapping the whole within an SUMPRODUCT() Function to get the SUM
=SUMPRODUCT((--ISNUMBER(MATCH($G$2:$G$9,A2:B2,0)))*($F$2:$F$9))
Hence we are not using and IFERROR() here since IFERROR() function is relatively inefficient and makes calculations slow, if there was no option then we could have used it perhaps when there is way why not use the formula as shown in the screenshot.
Also note to change the ranges in the formulas as per your suit.
If I’m understanding this right, the formula you are probably looking for is
=iferror(sumif1,0)+iferror(sumif2),0)

Excel Sumifs to where "sum_range" is the product of two ranges?

I'm trying to get this line of code to work:
=SUMIFS($A$30:$A$5141*$B$30:$B$5141,$C$30:$C$5141,1)
But Excel doesn't accept this as a valid formula.
However, if I create a dummy "SPILL range," I can get this to work.
I.e. if I put this code in cell "D1"
=$A$30:$A$5141*$B$30:$B$5141
Then this SUMIFS works fine:
=SUMIFS(D1#,$C$30:$C$5141,1)
Why don't SUMIFS work with dynamically created ranges? Other Excel functions seem to work okay.
Is there any way to compress the SUMIFS into one formula without using a help column or a helper SPILL function?
I'm using Excel 365.
Not all functions that take a range will also take an array - the VBA documentation makes this explicit in the case of SUMIFS() - the area to be summed must be a Range.
This SUMPRODUCT()-based formula may suit your purposes instead
=SUMPRODUCT(($A$30:$A$5141*$B$30:$B$5141)*(C30:C5141=1))

Why use INDIRECT in place of direct reference in excel

Why would one use INDIRECT(cell) instead of a direct reference to cell?
Eg, I see a sheet where there are many references
A B C
1 SHEET1 B1 =INDIRECT("'"&A1&"'!"&B1)
2 SHEET1 B2 =INDIRECT("'"&A2&"'!"&B2)
3 SHEET1 B3 =INDIRECT("'"&A3&"'!"&B3)
Why not just
A B C
1 =SHEET1$B1
2 =SHEET1$B2
3 =SHEET1$B3
Indirect vs Direct Cell Reference
does not generally auto update vs does update
example adding or removing columns
arithmetic to change row or column vs what you type is what you get
example indirect("A"&3+5) vs =A3+5 is totally different
If you want to organize your formula references and change them all on the fly it is easier with indirect (although even easier just using the naming feature) but the real reason you "need" indirect is how else are you going to change the reference in your formula without manually typing it (answer: indirect)?
use case - programmatically list and loop a range of worksheets:
sheet references using formulas and values useful for addressing cells at scale.
Build references to many different cells, worksheets or workbooks that follow a logic
The most common use of the INDIRECT function is probably when someone wants to reference to many cells which cell references follow a logical rule. For example, assume you have an Excel workbook with hundreds of sheets, one for each day and the sheet names are the dates. Now you would like to summarize some of the values in those sheets on an overview sheet. In this case, you can type in your starting date, drag it down to your final date (Excel will increment the dates). Using the INDIRECT function, you can now easily build up the references within seconds.
However, consider that INDIRECT is a volatile function which will slow down your workbook. Further, if you insert rows/columns, the INDIRECT function won’t adapt. It get’s even worse when you reference to external sheets. Since INDIRECT updates it’s value with every change in the workbook, you will get #REF errors as soon as you close the referenced sheets.
I personally avoid INDIRECT for such cases (either using VBA or by choosing a different design for my workbooks, so no INDIRECT function is necessary)
Lock a cell reference
If you have a cell reference like let’s say =A10, Excel will always adapt the reference when you insert new rows or columns (if you for example insert a row above row 10, the reference changes to =A11). You can use the INDIRECT function in order to always keep the absolute cell reference: =INDIRECT(“A10”).
With named ranges
INDIRECT can be handy with named references. Have a look at the example where you have three named ranges:
NorthAmerica: B2:B5
Europe: C2:C5
Asia: D2:D5
You can now combine the INDIRECT function with many other Excel functions like SUM, MIN, MAX and so on. In the example, the drop down selection in G1 is referenced using INDIRECT to perform the calculation for the selected range.
Dynamic dropdowns
A similar example where you can use the INDIRECT function are dynamic drop downs. In this example there are two named ranges:
Fruits: A2:A4
Vegetables: B2:B4
In cell D3, there is a dropdown where you can select “Fruits” or “Vegetables”. In E3, we have a dynamic drop down with the source =INDIRECT($D$3). If you choose “Fruits” in D3, you will have a list with the fruits in the drop down.
So, there are definitely some things where INDIRECT might be an easy solution. But as I said, it is a volatile function that locks the cell reference. In most cases you can find different, better solutions. The main reason people use it is probably the lack of knowledge of better alternatives. In addition, I assume that the average Excel user is not aware of possible problems you might run into when using INDIRECT.
Indirect is very useful with Tables. For example, I create a table tblFindings with 10 rows. Then I assign the list to =Indirect("tblFindings"). Now I add 5 rows to the table, the dropdown list automatically updates.

Excel SUMIFS - define sum_range by dynamically changing column

I would like to make a SUMIFS formula where I can change the sum_range parametr dynamically on the grounds of this formula where I get the column: SUBSTITUTE(ADDRESS(1;MATCH("aaa";1:1;0);4);1;"")
In other words, I want to replace B:B in this formula =SUMIFS(B:B;A:A;"abc") with the formula above. But I am not able to combine those...
I found one solution here: https://stackoverflow.com/a/25814571/10452645
but I'm not quite satisfied with it. Is there another possibility to solve this task by combining SUMIFS and ADDRESS formula.
In the above example, you can find the sum of abc from column aaa using one of the three formulas:
=SUMPRODUCT((B2:D13)*(B1:D1="aaa")*(A2:A13="abc"))
or
=SUMIFS(INDEX(B2:D13,,MATCH("aaa",B1:D1,0)),A2:A13,"abc")
or
=SUMIFS(INDIRECT(ADDRESS(2,MATCH("aaa",A1:D1,0))&":"&ADDRESS(13,MATCH("aaa",A1:D1,0))),A2:A13,"abc")
You can replace aaa and abc with a cell reference so you can "dynamically" change the SUMIFS criteria.
Please note, as mentioned by #ScottCraner
ADDRESS and INDIRECT are volatile and should be avoided. INDEX is the quickest most solid method.
Reason being a Volatile Function is one that causes recalculation of the formula in the cell where it resides every time Excel recalculates. This occurs regardless of whether the precedent data and formulas on which the formula depends have changed, or whether the formula also contains non-volatile functions. It means it could potentially slow down the calculation of your Excel workbook if it gets complicated overtime.
Having that said, choose the function that suits your preference.

Conditional AGGREGATE/Median in Excel 2010

I am currently trying to pull a median from a range of data that has two conditions. Essentially the equivalent of the below AVERAGEIFS(), which I have working fine.
The AVERAGEIFS():
=AVERAGEIFS(Analysis!$F:$F,Analysis!$F:$F,">=0",Analysis!$C:$C,Dashboard!C6,Analysis!$W:$W,Dashboard!B8)
I cannot figure a way to combine MEDIAN and IF(AND( to come up with a similar formula, but think AGGREGATE might be useful!
Any help or sanity checks are appreciated!
It's true that you can't do a conditional median with AGGREGATE function, not directly, but you can easily use function number 16 (PERCENTILE.INC) or function number 17 (QUARTILE.INC) with respectively k values of 0.5 and 2.
These functions allow arrays in AGGREGATE......and have the added advantage of automatically ignoring errors, so you can use this formula for the median with conditions
=AGGREGATE(17,6,Analysis!$F:$F/(Analysis!$C:$C=Dashboard!C6)/(Analysis!$W:$W=Dashboard!B8),2)
You are creating an Array formula with MEDIAN. So a couple of rules when using Array formulas:
Do not use full column References in Array type formula. Limit the references to the data set. We can do that automatically with $F$1:INDEX(F:F,MATCH(1E+99,F:F)) this will set the reference in Column F to F1 to the last row with a number in it.
AND() does not work in array formulas, either nest IF()s or use * between the Boolean test
The formula needs to be confirmed with Ctrl+Shift+Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
So the formula would be something like this:
=MEDIAN(IF((Analysis!$F$1:INDEX(Analysis!$F:$F,MATCH(1E+99,Analysis!$F:$F))>=0)*(Analysis!$C$1:INDEX(Analysis!$C:$C,MATCH(1E+99,Analysis!$F:$F))=Dashboard!C6)*(Analysis!$W$1:INDEX(Analysis!$W:$W,MATCH(1E+99,Analysis!$F:$F))=Dashboard!B8),Analysis!$F$1:INDEX(Analysis!$F:$F,MATCH(1E+99,Analysis!$F:$F))))

Resources