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

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.

Related

How do I find the largest numbers in a area, and then find the value of a number in the same row?

I cannot find a way to do this, is it possible (with excel functions or VBS)?
For example, these would be the initial values:
Number
Value
101
234
102
324
103
345
104
325
105
437
106
443
107
806
108
476
109
538
110
546
And after taking the three highest numbers, this would be the output:
Number
Value
107
806
110
546
109
538
The data is constantly updating, so that might cause some issues.
You can use FILTER in combination with LARGE function to achieve this:
Columns A and B represent sample data. Cell D2 can contain this formula:
=FILTER($A$2:$B$9,$B$2:$B$9>=LARGE($B$2:$B$9,3))
If data is constantly updating, better to have an Excel Table (I named TB_NumVal), so the range index get automatically updated.
In cell: J2:
=SORT(FILTER(SORT(TB_NumVal,2), (ROW(TB_NumVal[Number])-1)
> ROWS(TB_NumVal[Number])-3),2,-1)
Here is the output:
Explanation
We sort the data, then since we start on row 2 (row 1 is the header) we substract 1. So
ROW(TB_NumVal[Number])-1
will provide the row number starting from one.
ROWS(TB_NumVal[Number])
is the total number of rows, in our case 10.
Using a filter condition like this:
(ROW(TB_NumVal[Number])-1) > ROWS(TB_NumVal[Number])-3)
ensures only the last three row will be selected, then finally sorted the filtered result by value in descending order to match the result of the screenshot of the question.

How to compare 2 massive/huge/long lists and output any non matching results in one field

I have 2 massive columns filled with studentids
Column 1(SID) has 110,000 rows
Column 2(SID2) has 100,000 rows
How do I make a check of column 1 = column 2 or vice versa and then finally place it all in one field!
Current Results
SID SID2
45 45
142 142
237 218
238 441
410 410
440 442
452 237
452
Final Expected output
SID SID2 Check
45 45
142 142
237 218
238 441 238,441
410 410
440 442 440
452 237
452
238,441,440
As you can see, all the ids that dont match should be placed in one field so I can easily spot them rathen than looking though 100,000 rows
Looks like SolarMike answered assuming that the test is A2=B2, but I think you're asking if A2=[Anything in Column B] and if B2=[Anything in Column A]. Here's how I'd test that:
Column C:
=IFERROR(IF(MATCH(A2,B:B,0)>1,"",A2),A2)
Column D:
=IFERROR(IF(MATCH(B2,A:A,0)>1,"",B2),B2)
Column E (very crude, but effective):
=IF(AND(C2="",D2=""),"",CONCATENATE(C2,",",D2,","))
Now, your real problem is getting it all into one single cell. The only way I know how to do this is to use Concatenate, but it requires you to select EACH CELL individually.
=CONCATENATE(E2,E3,E4,E5,E6,E7,E8,E9,E10)
For 10000 rows, that doesn't seem feasible. Also, that output isn't very flexible, but I digress.
If you want to concatenate everything together in one cell, you have two options.
A) Use the VBA code here (it's pretty simple, this seems like a viable option): Concatenate Excel Ranges with VBA
B) Hope that you have Office 365 with TEXTJOIN() See Support article here.
You could use match() with iferror() and if():
=IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",A1)
see:
To get both fields back use:
=IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",A1)&" , "&IF(IFERROR(MATCH(A1,B1,)>0,0),"ok",B1)

Why does a specific arrayformula not work in google sheets but works fine in excel

This is in continuation to how to calculate XIRR dynamically in excel and in google sheets
The proposed array formula** solution (mentioned below) works perfectly fine in excel
=XIRR(INDEX(F:G,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2)))))),N(IF(1,{1,2}))),CHOOSE({1,2},INDEX(A:A,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2))))))),TODAY()))
but the same solution refuses to work in google sheets with the error
In XIRR evaluation, the value array must include positive and negative numbers.
Any idea why this is not working in google sheets and how to make it work?
Source data
PurchaseDate Script No.ofunits PurchNAVrate NetAmount ForXIRR TotalReturn
17/11/2014 A 2241 33 75000 -75000 96000
8/1/2015 B 53 649 35000 -35000 43000
14/1/2015 B 75 658 50000 -50000 61500
14/10/2014 C 2319 32 75000 -75000 108000
8/1/2015 D 318 109 35000 -35000 40000
14/1/2015 D 450 110 50000 -50000 57000
8/6/2015 D 175 114 20000 -20000 22000
Values for Fund A should be around 14%
Values for Fund B should be around 13%
Values for Fund C should be around 21%
Values for Fund D should be around 8%
It appears that the the constructions which allow us to generate an array of returns from INDEX, i.e.:
N(IF(1,,,
or
N(INDEX(,,,
are valid in Excel but not in Google Sheets, in the latter both resolving to just a single (i.e. the first) element in the array passed.
For example, in Excel, the following:
=SUM(INDEX(A1:A10,N(IF(1,{1,2,7}))))
or:
=SUM(INDEX(A1:A10,N(INDEX({1,2,7},))))
will sum the values in A1, A2 and A7, though in Google Sheets both will sum only the value in A1.
I do not know enough about Google Sheets to know why this is the case. It may be possible to reconstruct my formula using the volatile OFFSET. I will have a look and get back to you.
Update: It appears that even an OFFSET-based solution, i.e.:
=XIRR(N(OFFSET(F2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),CHOOSE({1,2},N(OFFSET(A2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),TODAY()))
is not possible. Again, it works fine in Excel but not in Google Sheets, for reasons similar to those given above (the arrays passed to OFFSET do not resolve as required).
I think this requires an explanation by someone well-versed in Google Sheets.
References:
https://excelxor.com/2014/09/05/index-returning-an-array-of-values/
Regards

SUMIF dynamically change summing column

I am using SUMIFS and want the sum_range dynamically to change according to the name I have of a column.
I have a table with about 100 columns. Say one of these columns is Paid_BC_items. I want a formula that looks for which column Paid_BC_items is in and somehow insert that into the SUMIF here where the Sheet4!J:J part is. I have a few other criteria here too which are fixed so they don't need to be dynamic.
=SUMIFS(Sheet4!J:J,Sheet4!$C:$C,Sheet2!$D$3,Sheet4!$E:$E, Sheet2!$C6, Sheet4!$G:$G, Sheet2!$D6)
If for example I changed the column heading to something else I want the SUMIF then to look for that column in the big tables and return that.
I know it has something to do with indexing, matching and indirects but I just can't figure it out right now.
Year Week Total Orders Paid_BC_items Free_BC_items
2014 1 971 147 104
2014 2 1565 339 213
2014 3 1289 391 209
2014 4 1171 389 228
2014 5 1163 375 240
2014 6 1298 405 330
2014 7 1233 404 292
Try using this in place of the sum range
INDEX(Sheet4!A:DZ,0,MATCH("Paid_BC_Items",A1:DZ1,0))
when you use INDEX with 0 as the row argument you get the whole column....and MATCH picks the right column based on the header
Whole formula becomes:
=SUMIFS(INDEX(Sheet4!A:DZ,0,MATCH("Paid_BC_Items",A1:DZ1,0)),Sheet4!$C:$C,Sheet2!$D$3,Sheet4!$E:$E, Sheet2!$C6, Sheet4!$G:$G, Sheet2!$D6)
to make dynamic & be able to drag across for all column headings
MATCH(indirect(d$1),A1:DZ1,0))

Rounding in Excel Formula using complex conditions

Hi I need to round up the numbers (last 2 digits, no decimal) based on following conditions:
If from 0 to 64 should be 49
If from 65 – 89 set at 79
If from 90 – 129 set at 99
If from 130 – 164 set at 149
If from 165 – 189 set at 179
If from 190 – 229 set at 199
and so on until 989
Then:
If value is from 989 – 1099 set at 999
If value is from from 1100 – 1249 set at 1199
If value is from from 1250 – 1349 set at 1299
If value is from from 1350 – 1449 set at 1399
and so on until 5000
I would appreciate some info and help how to get a formula to work for this.
Thanks
Harmz
This is not really a rounding problem but more a conversion problem. because there seems to be no pattern to your number groups I don't think it is therefore something you can calculate and therefore you will have to do a lookup.
If you want to do it all in one formula you could use and array inside of a vlookup like the partial example below:
=VLOOKUP(C1,{0,49;65,79;90,99;130,149;165,179},2,TRUE)
Otherwise do it as a normal vlookup. All you need is a two column table table, the first column contains the lower bound of you ranges and the second column contains the value that you want it to be. The important thing is that the vlookup has the final parameter of true, this makes the vlookup find the nearest match.

Resources