Conditional AGGREGATE/Median in Excel 2010 - excel

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))))

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 CountIfs with an or condition on Dates

Looking to try and find the following in Excel but am having issues getting this to work.
I have Dates in Column A which need to be checked against Dates in the Query Column to compare. I want to count all records where the comparison column is greater than the date in A5 or is an empty cell. There are other conditions that I will also want to check but cannot seem to get this to work.
=COUNTIFS(Query1[Purchased Date],OR(Query1[Purchased Date]="",Query1[Purchased Date]>A5))
use:
=SUMPRODUCT(--((Query1[Purchased Date]="")+(Query1[Purchased Date]>A5)>0))
You can use an array function instead of countif.
Suppose your dates are in the range A2:A25 and your reference date is in cell B2.
If you type in any other cell
=SUM((A2:A25>B2)+(A2:A25=""))
and hit Ctrl+Shift+Enter it will give you the count you want.
This happens because Excel will resolve the first inner parentheses (A2:A25>B2) as an array of TRUE/FALSE, and does the same to the second (A2:A25=""). Next it will sum them, which is equivalent to the OR operation, and yields as a result an array of zeros (FALSE) and ones (TRUE). It wraps up by summing this array (with the function sum), all in one cell.
Perhaps this is more of a comment than an answer, but in this particular case you can just add the two separate totals:
=COUNTIF(Query1[Purchased Date],"")+COUNTIF(Query1[Purchased Date],">"&A5)
because the conditions are mutually exclusive.
Whether this helps or not depends on what additional criteria you want to add.
BTW there are two issues with your original formula:
(1) If you are combining lists of values with OR logic, you have to use addition instead (as in the two answers which use Sum or Sumproduct).
(2) The syntax of a Countif or Countifs where the range has to be kept separate from the criteria won't let you do what you want to do, so this again leads you to Sum or Sumproduct.

COUNTIFS with unique values Excel

I am trying to produce a count of the number of times different strings come up in an Excel table. An example table, currently in SHEET1, would be this:
I have another table in another spreadsheet where I want to indicate, for each letter on the left in Table 1, how many entries for "za", "zc" or "zd" come up on the right. However, I would only like to only consider one entry of each.
The end result, on row B of SHEET2, would have to be something like this:
At the moment I am using a combination of SUM and COUNTIFS to do the job.
More specifically, applied to the example, I am using the following formula:
=SUM(COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
The formula is doing some of what is intended. However, it is not counting each entry just one time. Instead, its is counting, for each letter on the left, every entry of "za","zc" or "zd". The table that the formula is returning is as follows:
How can I change the formula so that it does what I intend?
Thank you.
My initial thought would be:
=SUM(MIN (1,COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
but I’m not where I can test if the MIN will apply properly to the COUNTIFS array of results. ;-)
EDITED: The MIN function is taking minimum of 1 or all of the items in the COUNTIFS array, rather than minimum of 1 and each item in the COUNTIFS array, which is what I was afraid of. Using
=MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"za"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zc"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zd"),1)
will gain the desired results. It is a little clunky, but simpler than an array formula. If you want an array formula, you can use:
=SUM(FREQUENCY(IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),""),IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),"")))
This uses the FREQUENCY function to take a set of values and see how many items in another set of values fall within each of the data ranges. Since you need text instead of numbers, we use the MATCH function to find out the first time the value occurs in your list, returning "" with the IFERROR function if it doesn't. (We only need the first occurrence since you don't want to know how many occurrences there are). Since it is text, we use the same input for both arguments for FREQUENCY.
Therefore, if you need to change the values you are looking for or the ranges in which you are searching, make sure to change both! Alternately, you could list the values out somewhere, say in F1:F3, and make a named range for this, another one for A1:A18, and another for B1:B18. Your formula would then look something like this:
=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))
Then you need only change your named range definitions and your formulas would update. :-)
NOTE: Since this is an array formula, you must close out of the cell by pressing CTRL+SHIFT+ENTER rather than only ENTER. When you look at the formula bar, you should see
{=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))}
It does NOT work to enter the curly braces yourself. ;-)
You can use this formula at B1 and fill down:
B1:
=SUMPRODUCT(((Sheet1!$A$1:$A$18=A1)*(Sheet1!$B$1:$B$18= {"za","zc","zd"}))/
COUNTIFS(Sheet1!$A$1:$A$18,Sheet1!$A$1:$A$18,Sheet1!$B$1:$B$18,Sheet1!$B$1:$B$18))

Excel array formula with wildcard

I have an array formula that refers to a drop down cell ($AG$7) to determine which cells to evaluate. This works well, however, I need to include an additional item in the drop down which is "All".
When this is selected, I want the array formula to use "*" to return all instances from the array, but i can't get it to work.
This is the formula I'm currently using;
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")=$AG$7),1,0))}
I've tried using
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7),1,0))}
and
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7&"*"),1,0))}
But these don't work.
Does anybody have any ideas?
Thanks
A explicit = comparison cannot use wildcards. COUTIFS and SUMIFS can. As far as I see, you want to count only (conditional sum 1 and 0).
Problem is, COUTIFS and SUMIFS will not deal with INDIRECT ranges. But INDIRECT can and should (because of its volatile bahavior) often replaced by INDEX- MATCH.
So:
=COUNTIFS(tblSkillsMatrix[role],[#role],INDEX(tblSkillsMatrix,,MATCH($V$2,tblSkillsMatrix[#Headers],0)),"*"&$AG$7)
If $AG$7 is empty then it counts independent of the column named in $V$2.
Btw.: Within a table (ListObject) this needs not be entered as a array formula.
This is not 100% replacement of your formula since it not works if $V$2 is empty and so no table column title is given. Your formula will then look at all columns but this is not possible using COUNTIFS where each additional range must have the same number of columns as the criteria_range1 argument. So if $V$2 shall also can be empty, then this will not work.
If so then you could use
{=SUM((tblSkillsMatrix[role]=[#role])*(LEFT(INDIRECT("tblSkillsMatrix["&$V$2&"]"),LEN($AG$7))=$AG$7))}
Advantage: both $V$2 and $AG$7can be empty.
Disadvantage: Volatile behavior of INDIRECT and this formula then must be a array formula even in a ListObject-table. It must be confirmed using Ctrl+Shift+Enter.

How do I sum multiple "IF" statements without "Sumifs"

I have to put together a weekly reporting system in Excel. I need to report on the month to dale sales results and the completed week (Fri-Thu). This is collected from multiple sales agents in sales documents stored in Sharepoint.
For this, I've used "SUMIFS" to collect the data, the following way:
=SUMIFS('SHAREPOINTREF/FILE.xlsm'!SalesResults[One off],'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],">="&B7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],"<="&C7)
(B7 is a cell reference which determines the start date of the week, with C7 being the end of the week)
The trouble with SUMIFS, as well as SUMIF, COUNTBLANK, COUNTIF and COUNTIFS, is that they don't work when the sourcing document is closed. Microsoft has a workaround here: https://support.microsoft.com/kb/260415?wa=wsignin1.0
I can't seem to figure out how to adapt the workaround methodology recommended to apply not just to a simple IF statement, but to multiples. I assume I would need to use an "AND" statement, but I keep getting errors when I'm trying.
I have about half a dozen different calculations to make, but I am pretty confident if I can solve this one, the others should start to gel a bit better.
Try this:
=SUM(IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7,IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])))
Entered using Ctrl+Shift+Enter.
Non-Array formula equivalent:
=SUMPRODUCT(--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7),--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7),'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])
But both seems to return #REF! when source WB is closed even though the link provided in the question claims otherwise.
Edit1:
After more digging, above will work but you need to use a Normal Range and not a Table Range.
The only problem is, you loose the advantage of Table's Dynamic Data Range.
So something like this will work even if the source is closed:
=SUMPRODUCT(--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11>=B7),--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11<=C7),'SHAREPOINTREF/[FILE.xlsm]Sheet1'!$B$2:$B$11)
The recommended solution is to use array formulas. Those are a special type of formula that, when typed, must be activated by pressing Ctrl + Shift + Enter in the formula bar. Such a function works by applying a function that would normally accept a single cell (such as IF() ) to a range. You will need to wrap the result in an aggregating formula such as SUM() or COUNT(). Here's an example:
=SUM(IF($A$1:$A$10="Apple", $B$1:$B$10, 0))
This formula would check each cell from A1 to A10 and compare it to "Apple", if it is true it will return the corresponding row from $B$1:$B$10. The result would be an array of values of column B where column A is "Apples" with zeros where it is not. The surrounding SUM() aggregates the array and gives the equivalent of SUMIF().
As I mentioned, you would need to enter Ctrl + Shift + Enter after typing the formula for it to work as an array formula. Otherwise, it will work as a regular formula.

Resources