An Excel formula, find maximum and check for multiple conditions - excel

I asked a similar question before this but it turned out that whatever formula I was using does not give me the correct result. So I have to reask the question and make it more specific.
Suppose I have the following spreadsheet:
I want a formula which gives me the latest date that have percentage change that is greater than zero and "Orange" is not mentioned in the "Comments" column. Only 1 of the percentage changes (Column Pct1 to Pct 5) needs to be >0. So the formula will output 11/20/2012 since it has % change that is greater than 0% and it is non-Orange.
I tried match, offset, max but it didnt give me the correct result. I am hoping to input this as a formula into VBA because I have a total of 20 excel files that I need to have the macro to check against. Please help me! Thanks!!

{=MAX((B2:F6>0)*(ISERR(FIND("ORANGE",UPPER(G2:G6))))*(A2:A6))}
Enter with Ctrl+Shift+Enter, not just Enter. Don't type the curly braces, Excel will insert them if you enter as an array formula.
The first section returns a matrix of TRUEs and FALSEs based on whether the percentages are greater than zero.
The second section returns TRUEs and FALSES based on whether FINDing "Orange" generates an error.
The last section returns an array of the dates.
When you multiply the arrays/matrices the TRUEs are 1, the FALSEs are 0 and you end up with an array of dates where all the conditions are TRUE. Finally, MAX picks the largest.

Related

Why is =SUMIF(C5:C19,NOT(ISFORMULA(C5:C19))) returning zero?

I have a spreadsheet that I track my hours. Each cell initially is populated with a formula, i.e. =IF(WORKDAY(B24-1,1,holidays2019)=B24,OFFSET(C24,-1,2),0)
and then as the month progresses I enter my actual time.
In the following excerpt all values through 5/10/2019 are entered.
The formula =SUMIF(C5:C19,NOT(ISFORMULA(C5:C19))) shows zero. I do not understand why this does not work.
I appreciate any help! Column B in my spreadsheet corresponds to the dates shown below and Column C to the time entries.
Expected Result: 48.9
=SUMPRODUCT(J6:J20,--NOT(ISFORMULA(J6:J20)))
The key to this solution is the -- in front of the NOT(). A boolean that is processed by a math operator gets converted to 1 or 0. --, +0, -0, *1, /1 would have all worked to do the conversion. So now you wind up with an array of values you may want to sum being multiplied by an array of 1 and 0 to indicate the ones you want. The 1 are manual entry and the 0 are your formulas entries.
Now SUMPRODUCT performs array like calculations. As a result avoid using full column/row references inside it or you will wind up with a lot of excess calculations. Adjust the ranges in the answer to suit your needs.
Here's the MSDN definition of the Criteria in =SUMIF
criteria Required. The criteria in the form of a number, expression,
a cell reference, text, or a function that defines which cells will be
added. For example, criteria can be expressed as 32, ">32", B5, "32",
"apples", or TODAY().
Important: Any text criteria or any criteria that includes logical or
mathematical symbols must be enclosed in double quotation marks (").
If the criteria is numeric, double quotation marks are not required.
So, the reason, why your SUMIF returns 0 is, because none of the cells match the criteria, as they return a number and meanwhile they expect FALSE
Another issue here being, that the ISFORMULA will return TRUE, even when a range contains a single formula while all the rest has none. So basically you need to drag the formula down for each cell individually and sum them up only when a value is TRUE
Starting from cell D1:
=ISFORMULA(B1)
And then you can simply sum them up with the formula you provided.
=SUMIF(D1:D16,TRUE,C1:C16)
Obviously, you can hide the column D to make it more aesthetically pleasing.
Your formula fails because the criteria you're matching against, is TRUE/FALSE. Obviously the values in C5:C19 don't contain any booleans, so the sum is 0.
To solve this, you can add the correct criteria in cell D5 and below: =ISFORMULA(C5)
Then use =SUMIF(D5:D19,FALSE,C5:C19) to sum the values in column C.

SUM numbers, but when 0, add 8 instead

I'm trying to write a SUM(IF(zero, add 8), A1:G1) kind of excel function.
What it should do:
If the cell contains a number, add that number to the sum.
If the cell contains a number = 0, add 8 to the sum.
if the cell is empty, add nothing to the sum
I have tried using SUMIF, but it only "adds the numbers if they meet a criteria", and I rather need "add this when the criteria is met"
You could just make a longer formula:
=SUM(A1:G1)+COUNTIF(A1:G1, 0)*8
The first sum will only do your numbers ignore blanks and 0's, the second part counts the number of 0's and multiplies it by 8.
You can do this with the following formula:
=SUMIF(A1:G1,">0")+8*COUNTIFS(A1:G1,0,A1:G1,"<>")
should be self-explaining :)
Method 1
If you can spare another column, just use an IF statement to replace all 0's by 8's and blanks by 0's (not really necessary) in a new column
=IF(A1=0,8,A1) and take a SUM of this column.
Method 2
Just SUM over your original data, count the number of zeros in your data and multiply this number by 8.
=SUM(A1:A10)+8*COUNTIF(A1:A10,"=0")
Note: The data is in A1:A10 in this case.

How to skip every nth row in Excel column Sum

I have a table which I have copied from the internet and pasted in Excel. The data pasted is however not clean. I want to add the 1st, 4th, 7th, 10th... row from the column, while skipping 2,3,5,6,8,9...th row. And I'd like that solution to be in one cell, that is without adding a helper column.
Here is a snapshot of my demo table. Hope this gives you an idea of what I am trying achieve.
I've searched the internet found this question on SO. But I just can't modify the formula to get around my solution. Any help is greatly appreciated.
Seeing you have a header in your column.
Enter the following formula in your desired cell where you want the sum value
=SUMPRODUCT((A2:A13),(--(MOD(ROW(A2:A13),3)=2)))
Explanation:
MOD(ROW(A2:A13),3)=2 Checks for rows where row_number %% 3 = 2 and returns an array of boolean(TRUE or FALSE for each match)
Output : =SUMPRODUCT((A2:A13),(--({TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE})))
The double negative converts the boolean values to numeric 1(TRUE) or 0(FALSE).
Output: =SUMPRODUCT((A2:A13),({1;0;0;1;0;0;1;0;0;1;0;0}))
SUMPRODUCT multiplies the above array with the data array of A2:A16 and adds the product result.
How about using sumproduct? This function is greatly versatile and should do the trick. The idea is that the double negative sign casts the boolean to a one or zero so your false elements (aka any n where n%3 <> 1) get multiplied by zero so they are, in effect, excluded from your sum.
=SUMPRODUCT(--(MOD(ROW(A1:A16), 3)=1), A1:A16)

Difference between 2 values in a row in excel formula

How to get this in excel
excel table
F column is the result column
For the following answer I am going to assume you only ever have two numbers in any row, but they can be in any cell along the row and they are always greater than 0.
If you just wish to find the difference between the two numbers without worrying about which number is bigger, a simple equation using maximum and minimum can be used, eg in Cell F1 you would have
=MAX(A1:E1)-MIN(A1:E1)
However, from your example, it seems more likely that you want to know the difference between the first number and the second number.
The difficulty here, is that the cells in columns B, C and D could contain either the first number, the second number, or no number! The solution is to use the following equation in Cell F1
=(MAX(A1:E1)-MIN(A1:E1))*IF(MAX(A1:E1)=INDEX(A1:E1,MATCH(0,A1:E1,-1)),-1,1)
This formula works as follows:
We still start off with the simple difference between the max and min, and then this is multiplied by 1 or -1 depending on which way around the numbers are.
MATCH(0,A1:E1,-1)
This part of the equation looks along the row for a 0, and assumes they are in descending order, so it will return the position of the second number.
This is then inserted into the INDEX function and checked to see if it is the same as the maximum number and the IF function returns either -1 or 1 as required.
Paste this formula on F1, then copy to F2 and F3
=INDEX(A1:E1,MATCH(TRUE,INDEX(A1:E1<>"",),0)) - LOOKUP(9.99E+307,A1:E1)

Sort without altering cell index

I am looking for a solution to following issue :
I want to know the sum of A/Cs 3, 4 and 5 all the time in H7 (In Picture).
But, I will also want to sort the date occasionally to verify the next due but without affecting H7
But, What actually happens when sorting in ascending order, the Cell index itself is getting changed and the value at H7 gives me the different value (which is not what I want).
Is it possible to freeze the Cell index during sort?
Use the formula to calculate total:
=SUMIFS(B4:B8,A4:A8,">=3",A4:A8,"<=5")
What this does is it adds the values in the range B4:B8 only when values in range A4:A8 is greater than or equal to 3 and less than or equal to 5.
Try a SUMIF function with OR criteria.
=SUM(SUMIF(A:A, {3,4,5}, B:B ))

Resources