Why don't #N/A and MAX (or MIN) play well with each other and what can I do abut it - excel

I have a list of 12 cars and need to calculate MPG. I have the miles driven and fuel consumed, so MPG = miles / gallons of fuel is easy enough to program.
Then in the fourth column I want a "label" for the best and worst MPG and all others should just be blank. Here is my formula:
=IF(C1=MAX($C$1:$C$12),"MAX",IF(C1=MIN($C$1:$C$12),"MIN"," "))
Simple enough. A snippet of my data follows.
Miles Gallons
Driven Fuel MPG
1,145 101.936 11.2 MIN
1,277 91.226 14.0
4,561 376.270 12.1
3,655 236.647 15.4
2,598 204.620 12.7
2,948 222.591 13.2
2,384 153.914 15.5
1,808 127.940 14.1
3,034 168.387 18.0
3,763 234.053 16.1
3,237 196.615 16.5
1,530 72.812 21.0 MAX
Next Month
2,515 191.196 13.2
1,908 111.129 17.2
1,589 112.410 14.1
2,223 147.278 15.1
2,221 145.936 15.2
#N/A 142.165 #N/A
1,928 177.609 10.9
1,150 92.072 12.5
#N/A 67.651 #N/A
79 2.849 27.7
407 22.241 18.3
10,537 94.960 111.0
Obviously car 12 has bad data, but that's not my concern right now. What is giving me trouble is the #N/A values for cars 6 and 9. My handy dandy little formula
=IF(C1=MAX($C$1:$C$12),"MAX",IF(C1=MIN($C$1:$C$12),"MIN"," "))
returns #N/A for each vehicle. I have tried to use
If(NOT(ISNA(C1)),IF(C1=MAX($C$1:$C$12),"MAX",IF(C1=MIN($C$1:$C$12),"MIN"," ")),"#N/A")
and
If(ISERROR(C1),"#N/A" ,IF(C1=MAX($C$1:$C$12),"MAX",IF(C1=MIN($C$1:$C$12),"MIN"," ")))
with the same results.
Can my original equation be reworked to compensate for #N/A?

For Excel 2010 or later:
=IFERROR(LOOKUP(2,1/(C1=AGGREGATE({14,15},6,$C$1:$C$12,1)),{"MAX","MIN"}),"")

You may try using array formula
=IF(MAX(IF(ISERROR($C$17:$C$28), 10^-15, $C$17:$C$28))=C17,"MAX","")

This should give you what you want for Office 2010+:
=IFERROR(IF(C17=MIN(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MIN",IF($C17=MAX(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MAX",NA())),"")
If you're using Office 2007 or below, you want
=IF(ISERROR(IF(C17=MIN(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MIN",IF($C17=MAX(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MAX",NA()))),"",IF(C17=MIN(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MIN",IF($C17=MAX(IF(ISNUMBER($C$17:$C$28),$C$17:$C$28)),"MAX",NA())))
It's an array formula so you'll have to enter it with Ctrl + Shift + Enter

Related

Filtering discrepancies in duplicate measurements

I have a dataset with the following problem.
Sometimes, a temperature sensor would return duplicate readings at the exact same minute, where sometimes 1 of 2 of the duplicates is "reasonable" and the other is slightly off.
For example:
TEMP TIME
1 24.5 4/1/18 2:00
2 24.7 4/1/18 2:00
3 24.6 4/1/18 2:05
4 28.3 4/1/18 2:05
5 24.3 4/1/18 2:10
6 24.5 4/1/18 2:10
7 26.5 4/1/18 2:15
8 24.4 4/1/18 2:15
9 24.7 4/1/18 2:20
10 22.0 4/1/18 2:20
Line 5, 7 & 10 are readings that are to be removed as they are too high or low (doesn't make sense that within 5 minutes it will rise and drop more than a degree in a relatively stable environment).
The goal at the end with this dataset is to "average" the similar values (such as in line 1 & 2) and just remove the lines that are too extreme (such as line 5 & 7) from the dataset entirely.
Currently my idea to formulate this is to look at a previously obtained row, and if one of the 2 duplicates is +/- 0.5 degree, to mark in a 3rd column with TRUE so I can filter out all the TRUE values in the end. I'm not sure how to communicate within the if statement that I'm looking for a + OR - 0.5 of a previous number however. Does anyone know?
Here is a google sheet example that does what you want:
https://docs.google.com/spreadsheets/d/1Va9RjSeulOfVTd-0b4EM4azbUkYUb22jXNc_EcafUO8/edit?usp=sharing
What I did:
Calculate a column of a 3-item running average of the data using "=AVERAGE(B3:B1)"
Filter the list using "=IF(ABS(B2-C2) < 1, B2, )"
Calculate the average of the filtered list
The use of Absolute Value is what provides "+ OR -" that you were looking for. It is saying if the distance between two numbers is too much, then don't include the term.
So, A Simple Solution came to my mind. Follow the Following steps given below:
Convert Data to Table
Add a 4th column at the last
Enter the formula "Current Value - Previous Value"
Filter the Column with high difference values
Delete those rows of filtered data and you'll be left with Normal Values
Here's the ref. Image
Or If you want to consider the Same time difference only then do the following:
Convert your data to Table
Add 4th column at the end of table
Writhe the Following Formula to 4th Column
IF(Current_Time = Previous_Time, Current_Temp-Previous_Temp,"")
Filter and Delete the Data with high Difference
See the following Image:

Automate MIN and MAX temperatures for a certain date

I have big amount of data (60k rows) in Excel that is similar to this:
Temperature Humidity Date
20.1 68 22-dec-14
20.3 67 22-dec-14
20.4 65 22-dec-14
20.0 64 23-dec-14
20.5 64 23-dec-14
20.9 65 24-dec-14
21.4 64 24-dec-14
23.4 64 25-dec-14
23.8 65 25-dec-14
23.9 64 25-dec-14
18.4 64 25-dec-14
I created new columns outside this table that contains the individual dates and I want to extract the MAX, MIN and possibly the AVERAGE of that date
DATE MIN MAX AVG
22/Dez/14
23/Dez/14
24/Dez/14
25/Dez/14
I tried but I can't seem to find a way for Excel to work for me. Could you help me?
I suggest you try a PivotTable:
Suppose column A contains the dates, and column B the values. I've allowed 6 rows in each; extend as necessary.
Consider a sample date in $D$1. The formulas you need are:
MIN: =MIN(IF(D1=A1:A6,B1:B6,MAX(B1:B6))). (You need to enter this as an array formula).
MAX: =MAX(IF(D1=A1:A6,B1:B6,MIN(B1:B6))). (You need to enter this as an array formula).
Use AVERAGEIF out of the box.
Remember that you need to press Ctrl + Shift + Return to enter an array formula. Then it's a simple case of copying that formula downwards.
They return the minimum or maximum value of the entire sample if a given date is not present in the set, which might not be desirable. You could adjust this behaviour with a containing IF.
You can take care of the pseudo-MIN/MAX with the AGGREGATE¹ function using the 14 (LARGE) and 15 (SMALL) sub-functions together with the 6 (ignore errors) option and the AVERAGEIF function can take care of the rest.
      
The standard formulas in F2:H2 are,
=AGGREGATE(15, 6, ($A$2:$A$60000)/($C$2:$C$60000=$E2), 1)
=AGGREGATE(14, 6, ($A$2:$A$60000)/($C$2:$C$60000=$E2), 1)
=AVERAGEIF($C$2:$C$60000, $E2, $A$2:$A$60000)
Fill down as necessary. An advantage of this method is that you can get the second, third, etc smallest or largest simply by raising the 1 (k ordinal) number at the right end of the AGGREGATE formula.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Excel three column duplication and averaging

I need to average data (3rd column) corresponding to a specific latitude and longitude(1st and 2nd columns). The results are then outputted to columns 4,5,6.
Sample data and manual analysis is posted bellow. I think I need Index, Iferror or Vlookup. Most of the other questions dealing with this kind of work only typically consider 1 variable, not two.
Latitude Longitude Data UniqueLat UniqueLong Average of data
24.4000 -82.5000 13.1 24.4000 -82.5000 13.15
24.4000 -82.5000 13.2 24.4000 -82.4000 15.25
24.4000 -82.4000 17.8 24.5000 -82.4000 13.4
24.4000 -82.4000 12.7 24.5000 -82.1000 14.56
24.5000 -82.4000 13.4 24.6000 -82.0000 18
24.5000 -82.1000 16
24.5000 -82.1000 15.1
24.5000 -82.1000 13.3
24.5000 -82.1000 15.1
24.5000 -82.1000 13.3
24.6000 -82.0000 15.6
24.6000 -82.0000 20.4
I have a second problem related to this original question;
I need to compare my list of latitude/longitude (columns 4 and 5) with the values outputted from the Pivot table containing the latitude/longitude data (columns 1 and 2) and its associated data (column 3). This associated data I need to ascribe to the relevant latitude and longitude in column 6.
I have tried to use the index functionality etc but have had little luck.
Let me know if you can help at all with this second part.
DatabaseLat DatabaseLon Data Lat Lon CopiedData
31.2 -87.9 5 30.5 -87.1 3
31.9 -88.3 6 31.9 -88.4 10
31.9 -88.4 10 54 -87.1
31.1 -87.2 2 31.2 -87.9 5
30.5 -87.1 3
Just use a pivot table:
Select all the data (including headers) in columns Latitude, Longitude, and Data.
Choose Insert > PivotTable.
Drag Latitude and Longitude into the Row Labels section.
Choose PivotTable Tools > Design > Report Layout > Show in Tabular Form and Repeat All Item Levels. Also choose to turn off Grand Totals and Subtotals.
Drag the Data column into the Values section.
Hit the drop-down for Data and change the Value Field Settings... to average.
All said and told, the results should like this:
For the first part I would use an averageifs formula.
For the second part if you are guaranteed that the list you are looking up is unique (I think it is from what you said) you could just use a sumifs to then find the value next to that lat and long.

How do you find the average of numbers in excel based on criteria in other cells?

I have a fair bit of data I am trying to make smaller. My data is arranged in minutes following an event with associated sugar readings (see below):
469 13.3
471
474 13.5
479 14.1
484 14.3
489 14.3
494 14
499 13.9
504 14.2
509 13.9
514 13.7
519 13.4
524 13.5
529 13.8
534 14.1
539 14.3
544 14.1
549 13.8
554 13.2
559 12.9
564 12.9
569 12.8
574 12.4
579 12.1
584 11.9
589 11.7
594 11.7
599 11.8
604 11.7
The minute readings go up to ~4500. I was wondering if there is a way to find the average of the sugar readings based on time criteria - e.g. find the sugar average for every 20 minute group. I also have time data as well if this helps (e.g. 10/12/2013 13:53)?
Thanks for your help!
Alternatively is there a way to add in numbers between the minute values with blank spaces between the sugar values - that is:
Instead of this:
469 13.3
471
474 13.5
479 14.1
484 14.3
It would be this:
469 13.3
470
471
472
473
474 13.5
475
476
477
478
479 14.1
480
481
482
483
484 14.3
Thanks again
I don't understand the first part exactly, but in general, you can use Excel's AVERAGE function:
=AVERAGE(A1:A10)
=AVERAGE(A:A)
The first one will output the average of the values between A1 and A10 (inclusive), the second one will output the average of all values in the A column.
In the second part of your question, you ask to "expand" the time values with the measurement values. This is best done in a second sheet. Let's name the sheet with the data you have Data.
In the second sheet, write 469 in A1, 470 in A2 and then you can drag it down to the final measurement time.
Then, in B1 (of the second sheet we just started working on), add the following:
=IF(ISNA(VLOOKUP(A1, Data!$A$1:$B$200, 2, FALSE)), "", VLOOKUP(A1, Data!$A$1:$B$200, 2, FALSE))
Drag it down all the way to the last measurement time. You might have to change the two references to $B$200 to something higher, like $B$500 or whatever the highest row number is in the original Data spreadsheet.
This will add the measurement value for the corresponding time from the Data sheet, or it will just be an empty cell if there is no such value (e.g. no value for time 472).
Some explanations to that formula (skip if not interested). The heart of the formula is the following:
VLOOKUP(A1, Data!$A$1:$B$200, 2, FALSE))
VLOOKUP searches for a value at another place and then returns that row. In this case, we want to find the value A1 in Data!$A$1:$B$200, which is Excel's way of writing "the table A1 to B200 in the sheet Data". The $ signs guarantee that the values will not be changed as we drag the formula down, since Excel will automatically update regular cell references such as A1 in the formula.
So this will search for A1 in that area of Data and it will return a row. 2 specifies what cell's value we want to use, which is the measurement time right next to the value we just searched for (e.g. we found 564 in Data but we want to get the corresponding value next to it, i.e. 12.9).
VLOOKUP is a little dangerous in that it uses approximate values by default, which the last FALSE parameter prevents. To quote from microsoft.com [Source]:
If an exact match is not found, the next largest value that is less than lookup_value is returned.
And we really don't want that in this case. (It beats me why this is the default behavior, to be honest.)
VLOOKUP with no approximate search returns #N/A for values it can't find, and we don't want that all over our spreadsheet. This is why we test the function first:
=IF(ISNA(VLOOKUP(...)), "", VLOOKUP(...))
In other words, if VLOOKUP returns #N/A, let's just write nothing (""); otherwise, let's write what VLOOKUP returns to us.

Calculating a work week based on weekly time-sheet

I am trying to calculate work week hours which I want to match it with the company's paycheck earned amount. So far I have this:
7/12/2011 7.90
7/13/2011 8.03
7/14/2011 7.83
7/15/2011 7.97
7/18/2011 8.20
7/19/2011 8.12
7/20/2011 8.15
7/21/2011 6.07
7/22/2011 8.12
7/25/2011 8.13
7/26/2011 8.1
7/27/2011 8.4
7/29/2011 8.27
8/1/2011 8.33
8/2/2011 8.18
8/3/2011 8.22
8/4/2011 6.72
8/5/2011 7.57
8/8/2011 8.07
8/9/2011 8.28
8/10/2011 5.8
8/11/2011 8.8
8/15/2011 8.2
8/16/2011 7.95
8/17/2011 8.17
8/18/2011 8.1
8/19/2011 7.8
8/22/2011 8.18
8/23/2011 9.7
8/24/2011 8.17
8/25/2011 8.18
and want to match the total to this:
Check Date Earnings Start Earnings End Earn Type Earn Amount
8/10/2011 7/26/2011 8/10/2011 Salary 899.6
8/25/2011 8/11/2011 8/25/2011 Salary 888.28
The company's pay period varies, that's why these days don't follow.
So far I was using =SUMIFS functions but they are not giving the result I need.
Let me know if there's clarifications anyone needs!
You should be able to use =SUMIFS() to get the hours during the pay period.
=SUMIFS(B:B,A:A,">="&F4,A:A,"<="&G4)
Here,
column A contains the dates,
column B contains the hours,
cell F4 is the Earnings start date,
cell G4 is the Earnings end date.

Resources