How to test the values of two different cells in excel? - excel

How can I test to make sure that the values between two cells are both non-zero?
This may be an exercise of my rustiness in certain areas of math but I have two columns of values in an excel spreadsheet. In a third column to the right, I'm taking 80% of one and 20% of another and getting the sum. However, this is throwing off the calculation I'm trying to do often because the value in several cells is zero in one but not the other. How can I only apply the 80% or 20% when both values are not zero?

If your columns are A and B, the following will work in column C:
=IF(AND(A1<>0,B1<>0),(0.8*A1)+(0.2*B1),"A value equals zero")
In plain language:
If A and B are both not equal to zero, apply the calculation.
Else, warn the user that a value in column A or B equals zero.
Edit:
In response to the comment:
=IF(AND(A1<>0,B1<>0),(0.8*A1)+(0.2*B1),SUM(A1:B1))
In plain language:
If A and B are both not equal to zero, apply the calculation.
Else, sum the two values. The sum is equal to the non-zero value in column A or B.

Related

Finding the AverageIf of the highest three numbers

I am trying to find the average of column G based on the three largest numbers in column B.
The formula I've tried is:
=AVERAGEIF(B7:B131,LARGE(B7:B131,{1,2,3}),G7:G131)
The problem is it does not average the three, but rather it only displays the column G equivalent to the largest number in column B.
Does anybody know the correct formula to use in this instance?
If the numbers are all different in column B, as you say, then you can do this most easily by averaging column G for any number in column B that's greater than or equal to the 3rd largest, i.e.
=AVERAGEIF(B7:B131,">="&LARGE(B7:B131,3),G7:G131)
If you want to get matching values (from the same row) from different columns, you can use either VLOOKUP or INDEX\MATCH, as I did here.
From that point it gets trivial. Let me know if it works for you:
=AVERAGE(INDEX(G:G,MATCH(LARGE(B:B,1),B:B,0),1),
INDEX(G:G,MATCH(LARGE(B:B,2),B:B,0),1),
INDEX(G:G,MATCH(LARGE(B:B,3),B:B,0),1))
(Please notice I assumed the values in column B are unique, as you've mentioned in your comment.)

Excel calculated values sum Discrepancy

I have found that using the SUM() function to add a column of calculated values provides a different result than using the SUM() function against raw values. The following screen shots show a 1cent discrepancy between the sum of two columns that appear identical, except one is a calculated column and the other is raw data entry:
Note sum on column c is 1 cent different than column d
See the sum formula in row 22 is a simple sum
This is because the calculated values are not rounded to the 2nd decimal, they are just shown that way. But some of numbers may show 9.98 but really be 9.978.
If you want to see what I mean increase the decimal shown in those cells to four or more places.
To avoid this you can wrap the formulas in the range with =ROUND(...,2), where he ... is your formula. This will round the results to two places and then the two sums will match.

SUMIF date in column B is less than date in column C

I have a list of values in Column A and want to sum these values where the date in Column B is less than Column C.
Example
In this example the correct value would be 2100.
I have previously had to complete this task with reference to a single date (e.g. the date contained in C3) and used the formula:
=SUMIF(B2:B11,"<="&C3,A2:A11)
However in this instance I need each date in B to be less than or equal to the date in C. I have tried:
=SUMIF(B2:B11,"<="&C2:C11,A2:A11)
But I get a value of 0. Any ideas?
Option A - Helper column
The simplest approach for any scenario requiring working out on a row by row basis whether to do something or other - be it a sum, Lookup, etc - , is to use a 'helper' column alongside your data that uses a formula to work out whether it should or should not be included, typically returning 'True' if to be included.
With your data layout, in column D add a calculation that works out the difference and therefore whether the row should be included, such as:
=C2-B2 or =C2>B2 dragged down
The SUMIFS calc then becomes =SUMIFS(A2:A11,D2:D11,">0") or, for the general case with more complex criteria, =SUMIFS(A2:A11,D2:D11,TRUE)
This approach is excellent if you have a large number of complex criteria, perhaps varying by rows or perhaps requiring multiple AND() OR() and other logical evaluations (is a product ID x and is a customer ID y and is the value > z and is the days between purchase order being submitted and goods received more than 30 days) etc, to determine whether a row should be included in some further function.
Option B - Array formula
Alternatively, you can avoid the need for a working column by using an array formula that performs the comparisons in the formula. Under the data above this would be like:
=SUM(IF(B2:B11<C2:C11,A2:A11,0)) entered with Ctrl + Shift + Enter

If, Then, Duplicate Excel Formula

Column "A" is a numbering column for each Row, some numbers are the same, ie..
A1 is 1
A2 is 3
A3 is 1
A4 is 3
I need a formula that will show how many cells with content are in this column without counting duplicates, as above would be 2. I was figuring an "If-Then" formula but am unable to get it straight. Any help out there? Thank you in advance!
If you're using Excel 2013, I want to say that there's a count distinct function. Nonetheless, you can do it like this:
=SUM(IF(FREQUENCY(A1:A4,A1:A4)>0,1))
EDIT: Adding an explanation. The FREQUENCY function gets the frequency of the unique values within the array A1:A4 (first parameter), binning it using the values within A1:A4 (second parameter). The IF checks to see if that returns anything, i.e. if the frequency is greater than 0, in which case it returns 1 for each unique value it finds. Then the SUM adds the number of 1s returned by the IF statement, in turn giving you the number of unique values within the array A1:A4.

Excel- finding min value of multiple items

Column A represents serial numbers of different parts, but these parts come from different suppliers so they have different prices. Column B holds the price for each part.
I need a macro that will essentially go down Column A, compare the column B price for duplicates, and return the min price for the part in column C.
Alternatively, you could:
Create a pivot table, selecting columns a and b as your source
Set serial number as a row field (drag it to the left of the table)
Set price as a data field (drag it to the middle)
Choose to display min of price rather than sum (the default)
Working out the formula was much more entertaining, though!
You can do this without even needing array formulas:
=SUMPRODUCT(($B$1:$B$5)*($B$1:$B$5=MIN($B$1:$B$5+(A1<>$A$1:$A$5)*MAX($B1:$B5))))
/SUMPRODUCT(1*($B$1:B$5=MIN($B$1:$B$5+(A1<>$A$1:$A$5)*MAX($B1:$B5))))
The important insight here is that you can do array operations inside a SUMPRODUCT, and inside functions inside a SUMPRODUCT. The first SUMPRODUCT gives the sum of all the prices that are equal to the minimum price for each component, and the second one gives the number of listings that have that price. Divide one by the other and you have the minimum price for each component!
First SUMPRODUCT:
($B$1:$B$5) is a column vector of your prices.
We're then creating another column vector whose entries will be coerced to 1 if the corresponding entry in $B$1:$B$5 is equal to MIN($B$1:$B$5+(A1<>$A$1:$A$5)*MAX($B$1:$B$5)) and zero otherwise.
The part inside the MIN function starts out as the original vector of prices, but if the serial number from each row of column a is not the same as the one in the current row, we add on the largest price from anywhere in column B to the current row in column B.
This prevents any parts with different serial numbers from being counted as having the minimum price while leaving all prices for the current part unchanged.
This means we've constructed a column vector where all the entries are either zero or equal to the lowest price for the component in the row of the cell in which the formula is entered.
The second SUMPRODUCT is similar to the first, except this time we just add up the number of times the condition is met without multiplying by the price.

Resources