Excel - use a range of values without the zeros - excel

I am using a column of values that has a mix of positive numbers and zeros. I want to use various functions like MIN, MAX, AVERAGE, etc that calculates the result of just the nonzero numbers. Without making any changes to the data, is there a way to get functions to calculate this?
Ideally, there would be like a MINIF(range,">0") type of function. But I do not believe those exist. I would like to avoid using VBA as well.
Thanks!

You need to use an array formula like so:
=MIN(IF($A$1:$A$10<>0,$A$1:$A$10))
Hold CTRL+SHIFT+ENTER in the formula bar to make this an array formula.
You can do the same thing with the MAX and AVERAGE functions.
NOTE: Array formulas are inside { } - this is how you know you did it right.

As long as you have Excel 2007 or later you can use AVERAGEIF for averaging without zero, e.g.
=AVERAGEIF(Range,">0")
....but for MIN the normal approach is an array formula as AxGryndr suggests, and that same approach can be used for other functions, although non-array options are available, e.g. for smallest non zero value
=SMALL(Range,COUNTIF(Range,0)+1)
For MAX you can presumably just use a regular MAX function because that will be the same with or without zeroes, i.e.
=MAX(Range)

Related

Excel - Array Formula Extend

I am using this array formula which works fine
=IF(ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>J"),"",INDEX(accounts_table[Account Name],SMALL(IF(accounts_table[§]<>"J",ROW(accounts_table[§])-ROW(Ledger!$H$17)+1),ROWS($K$62:K62))))
However, I need to extend this for multiple COUNTIF Criteria:
accounts_table[§],"<>J"
accounts_table[§],"<>T"
accounts_table[§],"<>P"
I haven't been successful in doing this. I have tried this but doesn't work:
=IF(OR(ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>J"),ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>T")),"",INDEX(accounts_table[Account Name],SMALL(IF(OR(accounts_table[§]<>"J",accounts_table[§]<>"T"),ROW(accounts_table[§])-ROW(Ledger!$H$17)+1),ROWS($K$62:K62))))
You have to make two adjustments to the formula:
(1) I was talking total rubbish previously, it is correct that the easiest thing to do is to use Countifs. You could subtract the two separate counts of J and T from the total, but it's longer.
(2) You can't use AND or OR in array formulas - they only give you one result for the entire array instead of iterating over the cells like you want them to. Instead you have to use multiply (*) or add (+). Here you are trying to include cells which are both not equal to J and not equal to T, so again you need AND logic, therefore you want to multiply.
=IF(ROWS(K$62:K62)>COUNTIFS(accounts_table[§],"<>J",accounts_table[§],"<>T"),"",INDEX(accounts_table[Account Name],SMALL(IF((accounts_table[§]<>"J")*(accounts_table[§]<>"T"),ROW(accounts_table[§])-ROW(Ledger!$H$2)+1),ROWS(K$62:$K62))))
Extending it to more variables is left as an exercise for the reader...unless you have a real lot of values to exclude in which case another approach might be needed.

How to Use Excel SUMIFS with Greater Than Or Equal Operator When Numbers Stored as Text

I have a table where underlying database stores numbers as text. In this case, the greater than or equal operator doesn't capture the first value.
This formula ignores the first row of the data in the result where AcctNum=123. The formuula returns 11 when it should return 21.
=SUMIFS(Table1[Balance],Table1[AcctNum],">='123'", Table1[AcctNum],"<='500'")
Things I have tried:
1. "*" wildcard.
2. Many combinations of T() and TEXT() Function.
Things I don't want to do:
1. Use arrays.
2. Add columns to my table that are converted to numeric, because not all AcctNum's are formatted the same way, which is why they must remain text.
3. Use SUMPRODUCT because readability of formula is important in this case.
I have written a custom function to work around the problem, but I would like to know if there is a natural Excel solution. I have read SUMIF and SUMIFS do not work well when numbers are stored or retrieved from database as text. I am using Excel 2016.
Try SUMPRODUCT with double minuses to convert the text and booleans to numbers.
=SUMPRODUCT(--(--Table1[acctnum]>=123), --(--Table1[acctnum]<500), Table1[balance])
What do you mean by 2. Add columns to my table that are converted to numeric, because not all AcctNum's are formatted the same way, which is why they must remain text?
You can do this with an array or a helper column, other than that, not sure if it's possible using SUMIFS.
If you use Sumproduct, you can explicitly convert the text to numbers.
=SUMPRODUCT(Table1[Balance],--(Table1[AcctNum]+0>=123),--(Table1[AcctNum]+0<=500))

Using SUMPRODUCT and OFFSET on multiple rows in Excel

I have a question on using OFFSET in Excel.
For instance, I have a table with values varying by years.
Then, I have a table with some values varying by year/months.
!!Click here for the tables!!
I would like to write a formula e.g.
=SUMPRODUCT((E2:E37)*OFFSET(A1,C2:C37,1),E2:E37)
but it returns #VALUE!
In short, I would like to use an array of values in C2:C37 i.e. {1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3} to obtain the array {0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,}, and this array is then used in the SUMPRODUCT function.
Can someone help me solve the #VALUE! issue?
Thanks in advance!
Apparently (I didn't know this) Offset is unusual because it can return a set of range objects when used with an array as the second argument. Most functions can't handle this if you pass it to them. But if you put it through the N function, you get the right answer.
=SUMPRODUCT((E2:E37)*N(OFFSET(A1,C2:C37,1)))
or
=SUMPRODUCT((E2:E37),N(OFFSET(A1,C2:C37,1)))
Note that these appear to give an array of #Value! errors when you run them through Evaluate Formula but these resolve after passing through the N function.
Of course it would be more common to do this the easy way and use Index or Vlookup with a helper column. My first thought when trying to do it in a single Array formula without using Offset was this:-
=SUM(E2:E37*MMULT(N(C2:C37=TRANSPOSE((ROW(A2:A4)-1))),B2:B4))
I would think that the Offset way is easier and more efficient.
But in this particular case where there are only a small number of categories you could use this array formula which is perhaps the simplest approach:-
=SUM(CHOOSE(C2:C37+1,0,B2,B3,B4)*E2:E37)
The above formulae only work for the special case where the 'key' is the same as the row number in the lookup column. The offset method can easily be adapted to incorporate a lookup:-
=SUM((E2:E37)*N(OFFSET(A1,IFERROR(MATCH(C2:C37,A2:A4,0),0),1)))
See this reference

Using SUMIFS with multiple AND OR conditions

I would like to create a succinct Excel formula that SUMS a column based on a set of AND conditions, plus a set of OR conditions.
My Excel table contains the following data and I used defined names for the columns.
Quote_Value (Worksheet!$A:$A) holds an accounting value.
Days_To_Close (Worksheet!$B:$B) contains a formula that results in a number.
Salesman (Worksheet!$C:$C) contains text and is a name.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
I want to SUM Quote_Value if Salesman equals JBloggs and Days_To_Close is equal to or less than 90 and Quote_Month is equal to one of the following (Oct-13, Nov-13, or Dec-13).
At the moment, I've got this to work but it includes a lot of repetition, which I don't think I need.
=SUM(SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Oct-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Nov-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Dec-13"))
What I'd like to do is something more like the following but I can't work out the correct syntax:
=SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,OR(Quote_Month="Oct-13",Quote_Month="Nov-13",Quote_Month="Dec-13"))
That formula doesn't error, it just returns a 0 value. Yet if I manually examine the data, that's not correct. I even tried using TRIM(Quote_Month) to make sure that spaces hadn't crept into the data but the fact that my extended SUM formula works indicates that the data is OK and that it's a syntax issue. Can anybody steer me in the right direction?
You can use SUMIFS like this
=SUM(SUMIFS(Quote_Value,Salesman,"JBloggs",Days_To_Close,"<=90",Quote_Month,{"Oct-13","Nov-13","Dec-13"}))
The SUMIFS function will return an "array" of 3 values (one total each for "Oct-13", "Nov-13" and "Dec-13"), so you need SUM to sum that array and give you the final result.
Be careful with this syntax, you can only have at most two criteria within the formula with "OR" conditions...and if there are two then in one you must separate the criteria with commas, in the other with semi-colons.
If you need more you might use SUMPRODUCT with MATCH, e.g. in your case
=SUMPRODUCT(Quote_Value,(Salesman="JBloggs")*(Days_To_Close<=90)*ISNUMBER(MATCH(Quote_Month,{"Oct-13","Nov-13","Dec-13"},0)))
In that version you can add any number of "OR" criteria using ISNUMBER/MATCH
You can use DSUM, which will be more flexible. Like if you want to change the name of Salesman or the Quote Month, you need not change the formula, but only some criteria cells. Please see the link below for details...Even the criteria can be formula to copied from other sheets
http://office.microsoft.com/en-us/excel-help/dsum-function-HP010342460.aspx?CTT=1
You might consider referencing the actual date/time in the source column for Quote_Month, then you could transform your OR into a couple of ANDs, something like (assuing the date's in something I've chosen to call Quote_Date)
=SUMIFS(Quote_Value,"<=90",Quote_Date,">="&DATE(2013,11,1),Quote_Date,"<="&DATE(2013,12,31),Salesman,"=JBloggs",Days_To_Close)
(I moved the interesting conditions to the front).
This approach works here because that "OR" condition is actually specifying a date range - it might not work in other cases.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
You can use OR by adding + in Sumproduct. See this
=SUMPRODUCT((Quote_Value)*(Salesman="JBloggs")*(Days_To_Close<=90)*((Quote_Month="Cond1")+(Quote_Month="Cond2")+(Quote_Month="Cond3")))
ScreenShot
Speed
SUMPRODUCT is faster than SUM arrays, i.e. having {} arrays in the SUM function. SUMIFS is 30% faster than SUMPRODUCT.
{SUM(SUMIFS({}))} vs SUMPRODUCT(SUMIFS({})) both works fine, but SUMPRODUCT feels a bit easier to write without the CTRL-SHIFT-ENTER to create the {}.
Preference
I personally prefer writing SUMPRODUCT(--(ISNUMBER(MATCH(...)))) over SUMPRODUCT(SUMIFS({})) for multiple criteria.
However, if you have a drop-down menu where you want to select specific characteristics or all, SUMPRODUCT(SUMIFS()), is the only way to go. (as for selecting "all", the value should enter in "<>" + "Whatever word you want as long as it's not part of the specific characteristics".
In order to get the formula to work place the cursor inside the formula and press ctr+shift+enter and then it will work!
With the following, it is easy to link the Cell address...
=SUM(SUMIFS(FAGLL03!$I$4:$I$1048576,FAGLL03!$A$4:$A$1048576,">="&INDIRECT("A"&ROW()),FAGLL03!$A$4:$A$1048576,"<="&INDIRECT("B"&ROW()),FAGLL03!$Q$4:$Q$1048576,E$2))
Can use address / substitute / Column functions as required to use Cell addresses in full DYNAMIC.

How can I make Excel's MIN function ignore zeroes in a set?

In Excel, I have the following formula =(MIN(H69,H52,H35,H18)*(1/H18))*10 that is supposed to return the MIN of a range, and divide it by the current cell (*(1/H18) ), then multiply by 10.
I am having difficulty with adding a type of NULLIF statement. I want to be able to have (the possibility for) blank rows, and have the MIN function ignore zero/blank fields while selecting the next lowest value (all are between 1.0-0.1).
Is there a modifier i can apply to the MIN function to make it not compare zeroes in the MIN set? Is there a better function than MIN to use?
Here is the arrangement:
Please remember to include the syntax for where the MIN's set goes
The reason for the H69,H52,H35,H18 using commas is that these are embedded, individual cells that are arranged for visual presentation as well. Using a range, or colon/semi-colon operators don't appear to work for this purpose (see pic).
This is to prevent the following situation: users will need to eliminate fields that are zeros from the form, theres 2 formula edits per entry, averaging 4 entries per use, so 8 possible errors per form use...
You can use an array formula:
=MIN(IF(A1:A100>0,A1:A100))
You will need to hit ctrl+shift+enter to activate this formula.
You could use
=SMALL(A1:A3,COUNTIF(A1:A3,0)+1)

Resources