Excel: Cannot average blanks determined by formula - excel

I have some data in B1:B10 (values) and in C1:C10 (strings) that I want to average.
My values are (from row 1-10):
B | C
-----
1 | Approved
1 | Approved
1 | Approved
1 | Approved
| N/A
| N/A
| N/A
1 | Approved
1 | Approved
0 | Disapproved
When I enter the following formula in A1 to average the data in column B, I get a result (0.857143), no problem:
=AVERAGE(B1,B2,B3,B4,B5,B6,B7,B8,B9,B10)
When I instead enter the following formula in D1, I get a #VALUE! error instead, though from what I can tell, the logic is the same (replacing N/A's with blanks):
=AVERAGE(
IF(C1="Approved",1,IF(C1="Disapproved",0,IF(C1="N/A","",""))),
IF(C2="Approved",1,IF(C2="Disapproved",0,IF(C2="N/A","",""))),
IF(C3="Approved",1,IF(C3="Disapproved",0,IF(C3="N/A","",""))),
IF(C4="Approved",1,IF(C4="Disapproved",0,IF(C4="N/A","",""))),
IF(C5="Approved",1,IF(C5="Disapproved",0,IF(C5="N/A","",""))),
IF(C6="Approved",1,IF(C6="Disapproved",0,IF(C6="N/A","",""))),
IF(C7="Approved",1,IF(C7="Disapproved",0,IF(C7="N/A","",""))),
IF(C8="Approved",1,IF(C8="Disapproved",0,IF(C8="N/A","",""))),
IF(C9="Approved",1,IF(C9="Disapproved",0,IF(C9="N/A","",""))),
IF(C10="Approved",1,IF(C10="Disapproved",0,IF(C10="N/A","","")))
)
What gives, and what do I need to change in order to get 0.857143 as a result in the formula for the strings values in column C?
Also tried changing the "if true" and "if false" parts for N/A with VALUE("") and VALUE(0). With VALUE("") it still results in #VALUE! error, and with VALUE(0) it still counts the blank into the average, which is not desired as I only want an average on the 1's and 0's
Additional info: If I split up the formula for the strings to evaluate each one on a separate line, THEN pull an average on THAT range, it works fine.. Though, considering the data set I am working with, I would rather not add them all separately, as it clutters the work space enormously.

AVERAGE won't work with text-strings in a given range of numbers. It might skip empty cells (as per your first example), but surely will error out on comparing text in a numeric equation (your second example). So try this instead:
=COUNTIF(C1:C10,"Approved")/SUM(COUNTIF(C1:C10,{"Approved","Disapproved"}))
This will leave N/A out of the equation.

Related

excel conditional formating with multiple date ranges

I have looked for proper formula that would solve my problem but I couldn't find anything.
I have a table with multiple date ranges and I want to highlight all dates in my calendar between these ranges. I've tried to use formula AND
=AND(F5>=$A$6,F5<=$B$6)
however the formula highlights only dates between 1st range. I tried to put array ($A6:$A$9 and $B6:$B$9) but it doesn't work.
Column A Column B
row 6 | 05/01/2018 | 12/01/2018
row 7 | 03/04/2018 | 16/04/2018
row 8 | 06/05/2018 | 17/05/2018
row 9 | 01/11/2018 | 05/11/2018
My calendar starts in cell F5 and ends in AP16.
Regards,
Adrian
You need to wrap your AND's within an OR:
=OR(AND(F5>=$A$6,F5<=$B$6),AND(F5>=$A$7,F5<=$B$7), AND(...))
or, in a more compact but equivalent form:
=SUMPRODUCT((F5>=$A$6:$A$9)*(F5<=$B$6:$B$9))
or
=OR((F5>=$A$6:$A$9)*(F5<=$B$6:$B$9))
Each of the equality arrays returns an array of 1's or 0's. Multiplying them together is the equivalent of AND and will return a 1 if and only if both values in the same position are TRUE. Adding the arrays (the equivalent of OR) will then show if any result is a 1.
Although Excel 2016 will accept an OR in the conditional format formula, I seem to recall that some earlier versions will not, hence I have also supplied the equivalent SUMPRODUCT formula.
Or once again you can use countifs
=COUNTIFS($A$6:$A$10,"<="&F5,$B$6:$B$10,">="&F5)

Excel: Find out if cell contains/includes value from a range of cells

I have a list of job titles (A) and list of phrases (B). For each title in A I want to check if it contains a phrase (any phrase, I don't care which) from B.
| 1 |-----Example Column A------|----Example Column B----
| 2 | Head of Marketing | Senior Developer
| 3 | Lead Product Engineer | Marketing Manager
| 4 | Sales Development | Sales Development
| 5 | Senior Marketing Manager |
In the above example, I want to know that the last two cells in column A contain cells in column B.
I found lots of examples online of how to do the reverse, using * to find if a value is contained in a range. I also found the following three examples offered as solutions for problems similar to mine, but none worked for me.
{=MAX(ISNUMBER(SEARCH($B$2:$B$4,A2))+0)}
{=MATCH(A2,$B$2:$B$4&"*")}
=IFERROR(LOOKUP(2^15,SEARCH(B:B,A2),B:B),"")
I've also tried writing the contents of each cell in column B to start and end with an asterisk (*Senior Developer *, etc.), trying VLOOKUP, SUMPRODUCT, COUNTIF without success.
Is it possible to do what I want?
Solution
Slightly modified Mrig's formula:
=SUMPRODUCT(ISNUMBER(FIND(B$2:B$4,LOWER(A2)))*1)
Try this
=SUMPRODUCT(ISNUMBER(FIND($B$2:$B$4,$A2))*1)
This formula will return the number of phrases matched.
You can put this formula in IF if you don't want the count.
=IF(SUMPRODUCT(ISNUMBER(FIND($B$2:$B$4,$A2))*1)>0,"Exist","Does Not Exist")
See image for reference
EDIT: After sorting Column A in descending order output I get is:
Put the following formula in col C for each row in col A (starting at C2)
=IF(ISNA(INDEX(B$2:B$4,MATCH(A2,B$2:B$4,0))),"","x")
This is a combination of the INDEX and MATCH functions. INDEX returns a cell within a range based on a count, which in this case is provided by the MATCH function which returns the position of a cell within an array by matching against a criteria string.
The ISNA function is there to hide the "N/A" output in any non-matching cells and display "x" against any matching cells.
Have a look here for a more in-depth explanation.
UPDATE
As per the comment below, in order to see if Col A contains the text in Col B (rather than being a direct match) then use this formula in col C for each row:
=IF(SUMPRODUCT(COUNTIF(A2,"*" & B$2:B$4 & "*"))>0, "X", "")

Excel average with missing values

I have data like the following in cells A1:F4.
Quarter | FY15Q4 | FY16Q1 | FY16Q2 | FY16Q3 | FY16Q4
Company A | 0.34% | 0.48% | 0.55% | 0.68% | ------
Company B 0.32% 0.36% 0.34% 0.35% 0.35%
Company C | 1.18% |------ |----- |----- |
I'm trying to find the average of the most recent non-missing value from last 4 columns in each row. So for:
FY15Q4, I want the average of 0.34%, 0.32%, and 1.18%
FY16Q1, I want the average of 0.48%, 0.36%, and 1.18%
FY16Q2, I want the average of 0.55%, 0.34%, and 1.18%
FY16Q3, I want the average of 0.68%, 0.35%, and 1.18%
FY16Q4, I want the average of 0.68% and 0.33% (Company C has no data for the most recent 4Qs, so it is to be ignored from the calculation of the average)
The following array formula works as I want for FY16Q3...
{=AVERAGE(IF(COUNT(B2:E2)=0,"",INDIRECT(ADDRESS(ROW(B2:E2),MAX((B2:E2<>"")*COLUMN(B2:E2))))),IF(COUNT(B3:E3)=0,"",INDIRECT(ADDRESS(ROW(B3:E3),MAX((B3:E3<>"")*COLUMN(B3:E3))))),IF(COUNT(B4:E4)=0,"",INDIRECT(ADDRESS(ROW(B4:E4),MAX((B4:E4<>"")*COLUMN(B4:E4))))))}
But for FY16Q4, the same formula structure...
=AVERAGE(IF(COUNT(C2:F2)=0,"",INDIRECT(ADDRESS(ROW(C2:F2),MAX((C2:F2<>"")*COLUMN(C2:F2))))),IF(COUNT(C3:F3)=0,"",INDIRECT(ADDRESS(ROW(C3:F3),MAX((C3:F3<>"")*COLUMN(C3:F3))))),IF(COUNT(C4:F4)=0,"",INDIRECT(ADDRESS(ROW(C4:F4),MAX((C4:F4<>"")*COLUMN(C4:F4))))))
returns the #VALUE error value.
It seems that the AVERAGE function, which usually deals well with blank cell ("") values, is struggling because of the added complexity of the array formula.
Any suggestions on how I can make this work without either (i) using find-and-replace to replace "" with a truly blank cell; or (ii) using VBA?
Surely there must be a way to make this work using only formulas...
One method without array formulas is to use helper cells. I set up another table with the same column/row headers.
Then in the first cell I put:
=IFERROR(INDEX($A:$F,MATCH($A12,$A:$A,0),IF(MATCH(1E+99,INDEX($A:$F,MATCH($A12,$A:$A,0),1):INDEX($A:$F,MATCH($A12,$A:$A,0),MATCH(B$11,$1:$1,0)))<=MATCH(B$11,$1:$1,0)-4,NA(),MIN(MATCH(1E+99,INDEX($A:$F,MATCH($A12,$A:$A,0),1):INDEX($A:$F,MATCH($A12,$A:$A,0),MATCH(B$11,$1:$1,0))),MATCH(B$11,$1:$1,0)))),"")
Then drag it across and down to fill in the table with the correct number:
Then it is just a simple AVERAGE() formula:
=AVERAGE(B12:B14)
Which when dragged over will ignore the blank cells.
A few caveats put out by #Jeeped and #XOR LX.
This only works if the "Blank" are NOT 0 formatted as something else.
As companies and quarters are added the reference table will need the same columns and rows added.

VLOOKUP with IF conditions are met

I have this problem at work to populate the worksheet with the right case number.
Sheet 1: (Report)
SSN | Service Date
123456 | 10/01/2014
Sheet 2: (Data)
SSN | Case Number | Start Date | End Date
123456 | 0000000 | 01/01/2010 | 12/31/2012
123456 | 1111111 | 01/01/2013 | 05/31/2014
123456 | 2222222 | 06/01/2014 | 11/10/2015
How can I do a VLOOKUP based on the Service Date to be within the "range" of the Start and End Date of another sheet?
In this case I would like to lookup the SSN and return case number 2222222 because that is the case active for such date of service.
I was looking online and found "MATCH". I am able to match the first result of the case matches the SSN, but how to go to the next case if it does not match?
=IF(E2>=INDEX('CASE NUMBERS'!A:F,MATCH(C2,'CASE NUMBERS'!A:A,0),4)&E2<=INDEX('CASE NUMBERS'!A:F,MATCH(C2,'CASE NUMBERS'!A:A,0),5),"YES","NO")
I am using Excel 2013 on Windows 7 at work.
You will need 3 conditions. a) Is the start date less than the Service Date b) Is the End Date greater than the Service Date and c) do the SSN numbers match?
Use the newer AGGREGATE¹ function to force any non-matches into an error state while using the ignore errors option (e.g. 6) to discard errors.
=INDEX(Sheet2!$B$2:$B$9999, AGGREGATE(15, 6, ROW($1:$9998)/((Sheet2!C$2:C$9999<=B2)*(Sheet2!D$2:D$9999>=B2)*(Sheet2!A$2:A$9999=A2)), 1))
      
For all intents and purposes, a worksheet formula treats FALSE as zero (e.g. 0) and TRUE as one (e.g. 1). Any number multiplied by zero is zero and any number multiplied by one is the same number. The AGGREGATE function is retrieving the row position of the first match within Sheet2!B2"B9999. That row position will be a number somewhere within ROW(1:9998). Any of the rows that do not match all three condition will have at least one zero multiplied by the denominator. This makes the denominator zero. Anything divided by zero forces a #DIV/0! error and AGGREGATE will discard those from the result set. AGGREGATE's 15 option is the SMALL and the last 1 is the k ordinal for SMALL (the very smallest). So of all the rows that match all three conditions, AGGREGATE returns the lowest one to the INDEX function which retrieves the value from Sheet2!B2"B9999.
Tighten the ranges up to a maximum of 5 rows and use the Evaluate Formula command to step through the formula and gain a better understanding.
It may be worthwhile to note that it is very easy to convert this formula to retrieve the second, third, etc. matches as well since it only requires sequencing the k ordinal up.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.
If SSN is in A1 of both sheets and your Case Numbers are numeric (other than 0000000) then you might try:
=SUMIFS(Sheet2!B:B,Sheet2!A:A,A2,Sheet2!C:C,"<="&B2,Sheet2!D:D,">="&B2)
SUMIFS is explained here (and elsewhere!).
This array-formula will always print the last match:
=INDEX(Sheet2!B:B,MAX((Sheet2!A:A=A2)*(Sheet2!C:C<=B2)*(Sheet2!D:D>=B2)*ROW(A:A)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
It works if there are multiple solutions which fit the criteria
It also works with every kind of data you want to show (values/dates/strings)
! However, you should cut the range as short as possible. (its a huge calculation for the entire sheet)

vba code to find and replace text across columns in excel

I have spent the day trying to learn vba code and searching other questions for the same example but have been unable to crack this so help would be greatly appreciated.
I have worked out how to do it in vlookup but only to a single row.
This code from kutools is the closest i could find and almost does what i need but is only reading single digits in my range (which goes up to 700) so the value i return is multiples of the value string. This would need to be modified to only search and replace the specific value. http://www.extendoffice.com/documents/excel/1873-excel-find-and-replace-multiple-values-at-once.html
I have 3 columns: A has a random list of numbers, many repeating; B has a list of reference numbers which correlate to a place name in C.
A | B | C
1 | 1 | Melbourne
1 | 2 | Adelaide
1 | 3 | Sydney
2 | 7 | Auckland
2 | |
3 | |
7 | |
The code should result in the number in column A being replaced by a place name from column C by first finding the matching number in column B. Note: There are less rows in columns B&C than there are in column A.
There are thousands so i need a code to do this.
Thanks in advance.
Well first off I'd place the VLOOKUP data into a new column so to preserve your original data set, but here's the code that you should be looking for:
=VLOOKUP(A1,$B$1:$C$4,2,FALSE)
Here's the syntax of a VLOOKUP:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
Now for each part. The lookup_value is what you're using as a reference to search for, this will be your information for columb A. The table_array is a static reference of where to look for this value, and then the resulting values you want to display, so in your sheet you'll make this all of columb B and C. The col_index_num represents the index of the table_array you chose previously, so since the name of the cities is in the second column of this table, we put 2. range_lookup is whether or not you want an exact match. We do, so we set it to true. And then you can just replicate this value down a column to have the results for everyone.
That should be exactly what you're looking for. I even created a test sheet to try it out. In the future I suggest posting the code you've already tried.

Resources