I have old Excel table that I need to manually fill and I made new Excel table where I used CTRL+T to fill in data automatically when typing formula in first row under the header/title cell.
My data is vertical in old:
Numbers Average (for last 10 Numbers from Left Row)
5,780.00
5,730.00
6,600.00
7,300.00
6,120.00
5,250.00
5,210.00
5,100.00
5,770.00
6,370.00 5923.00
6,000.00 5945.00
5,480.00 5920.00
5,120.00 5772.00
4,990.00 5541.00
This is how it should look, this is how I made it manually.
Formula is:
=IF(L11<>"",AVERAGE(L2:L11),"")
Where forumula is in M row (Average) and checking and calculating for L row (Numbers).
But for Table to auto-fill till last row, formula has to be made in first row, then Excel auto-fills.
Average:
5923.00
is from this numbers:
Numbers
5,780.00
5,730.00
6,600.00
7,300.00
6,120.00
5,250.00
5,210.00
5,100.00
5,770.00
6,370.00
How can Average formula for 10 vertical numbers from L row be inserted into any cell above 5923.00 in Average - M Row.
I do know how to fill row, I could copy formula, press CTRL + SHIFT + DOWN to find end of my table and paste formula, but when new data comes (imported CSV that updates), new data would not be filled, I need Excel to auto-fill it.
Here is answer for all if needed, if you have by dates, old data up and new down, then average of first 10 items, can't be calculated in first 10 rows without issues where you have Average.
Here is solution for one way direction:
=IF(AND((ROW())>=11,L2<>""),AVERAGE(OFFSET(M2,-9,-1,10)),"")
What Offset does, is goes up +9 places from current cell M2, then it goes 1 cell left, and from there takes 10 down to mark the range.
IF if statement is wrong it doesn't go left and up, thus no error, after and including ROW 10 it's true statement.
And this is more complicated to use with Table in Excel, when you have sorting by date, when newest date is on top, bottom is data that you can use for average:
=IF($A$2>$A$3,AVERAGE(OFFSET(M2,0,-1,10)),IF(AND((ROW())>=11,L2<>""),AVERAGE(OFFSET(M2,-9,-1,10)),""))
I have first IF (A2>A3) that checks how is table sorted:
- if sorted newest - oldest (1st case) then it takes average from first row on the left, and down 10 places
- if sorted opposite, it goes as said: left one place, and up 9, then takes 10 range.
Works like a charm, bit long, but it works!
You could add a test for which row the formula is in and only return a result if it's 11 or higher. Then you could enter it in the entire column table and it would fill automatically:
=IF(AND(ROW()>=11,L11<>""),AVERAGE(L2:L11),"")
ROW() returns the number of the row the fomula is in.
EDIT: Ok, here's a better one. Put this in M2 and copy down:
=IF(AND(ROW()>=11,L2<>""),AVERAGE(OFFSET($L$1,ROW()-10,0):OFFSET($L$1,ROW()-1,0)),"")
Related
This is the formula :
=IF(A674=1,CONCATENATE(Sheet1!A7,"(",Sheet1!B7,")"),0)
where, when I am pasting this formula on every n+7 row, the value is incrementing by 7(obviously). I need to paste this formula but increment by only one on every n+7 row.
PS: This task if from company where i am involved in making the test case for my development, but there are around 1200 objects :(.
To get incrementation of one for every 7 rows, divide row number by 7 and round up. For example:
=ROUNDUP(ROW(A1)/7, 0)
The above formula will return 1 for range A1:A7, 2 for range A8:A14, etc. - use it within your formula to get the desired incrementation.
I'm learning to use array formulas and have been successful doing simple things like adding 2 columns together in a third column. For example, I can put =arrayformula(B:B+C:C) in D1 and it adds B and C for each row.
But now I have a situation where I want to subtract two numbers in the same column. I want to take the value of that column in the current row and subtract the previous row's value from it. Without array formulas this is simple: in O7 I put =N7-N6 and cop that down so O8 gets =N8-N7, etc. But that requires copying down every time - can I do the same thing with an array formula?
Basically, can I do something like =arrayformula(B:B+(B-1):(B-1)) ?
Context: column N is a monthly account balance. I would like to calculate how much that balanced changed each month. So for row 7, =N7-N6 gives me that difference. But I'm changing the entire spreadsheet to array formulas so I can stop pasting all of the formulas and I'm stuck on this one since it's comparing the same column.
I'm trying to get everything into Row 1 so my values and calculations can start in Row 2. For example, here's one of my formulas in Row 1:
arrayformula(if(row(A:A)=1,"Total gross income",if(LEN(B:B),B:B+C:C,"")))
Unfortunately, in Column O (the one I asked about originally) if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N2:N-N:N,""))))
Or this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),offset(N:N,1,0)-N:N,""))))
Every row is off by 1 - the result that should go in Row 3 goes in Row 2, etc. And if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N:N-offset(N:N,-1,0),""))))
Then it gives me an error because the offset function is trying to evaluate something out of range (possibly it starts with N1 and tries to grab a value 1 row above N1?)
Any advice on how to handle that out-of-range error?
I think the error is because of offset range N:N which starts from N1 and you are trying to shift it -1 or one cell up, which brings the formula out of sheet.
Try this formula instead:
=arrayformula(
{"Amount saved this month";
if(LEN(N2:N),N2:N-offset(N2:N,-1,0),"")})
It uses {} to make an array. See more info:
https://support.google.com/docs/answer/6208276?hl=en
Bonus. There is no reason to check row number now.
I have two different sheets with 300,000 data in Excel.
First sheet contains:
S2_Symbol Start_Pos End Position
STE 254857 267891
PRI 748578 758962
ILA 852741 963369
VIS 789456 796325
Second:
S1_Location
789460
852898
748678
My output should be like this:
S1_Location Symbol
789460 VIS
852898 ILA
748678 PRI
I have to find that S1_location falls in which S2_location and its corresponding Symbol. I have used INDEX formula in Excel but for each cell, I have to change the reference cell manually. I couldn't do it 300,000 data.
How can I do in an in Excel or should I use a script?
This solution assumes the following:
Start and End Positions for each S2 Symbol are unique (i.e. there is no intersection between the ranges allocated to each symbol)
Data in first sheet is located at A1:D17 (adjust ranges in formulas as needed)
Data in second sheet is locate at A1:B300010 (adjust ranges in formulas as needed)
The solution requires:
To add a working column in worksheet one. Enter this formula in D2 and copy till last record.
=ROWS($A$1:$A2)
Fig. 1
Then in second worksheet enter this formula at B2 and copy till last record.
=INDEX( Sheet1!$A$1:$A$17,
SUMIFS( Sheet1!$D$1:$D$17,
Sheet1!$B$1:$B$17, "<=" & $A2, Sheet1!$C$1:$C$17, ">=" & $A2 ) )
Fig. 2
It took aprox. less than 14 seconds to copy downwards and calculate the formulas in sheet 2.
As it can be seen in figures 1 and 2 none of the tables need to be sorted.
Assuming both sheets start in A1, and First sheet ColumnB is sorted ascending, in Second sheet B2 please try:
=INDEX(First!A:A,MATCH(A2,First!B:B))
copied down to suit. It relies on inexact matching.
Assuming we have a Sheet1 like this:
note, the Sheet1is sorted by Start_Pos, End_Pos in ascending order.
and a Sheet2 like this:
Then the formula in Sheet2!B2 downwards could be:
=INDEX(Sheet1!A:A,IF(MATCH(A2,Sheet1!B:B)>IFERROR(MATCH(A2-(10^-10),Sheet1!C:C),0),MATCH(A2,Sheet1!B:B),NA()))
See MATCH: https://support.office.com/en-us/article/MATCH-function-e8dffd45-c762-47d6-bf89-533f4a37673a
The idea is: MATCH without exact matching (without parameter match_type) gets the row of the largest value which is smaller or equal the search value. So in the Start_Pos column it will get the row from which we can get the S2_Symbol. But from the End_Pos column it should get one row beforehand if the value is not outside the given ranges.
There is only one exception. If the value is exact the value in the End_Pos column, then it will return the same row as in the Start_Pos column. Considering this exception, we can search in the End_Pos column with a little bit smaller value. Thanks to Tom Sharpe for his comment.
The formula in Sheet2!D2 downwards is:
{=INDEX(Sheet1!A:A,MIN(IF($A2>=Sheet1!$B$2:$B$300000,IF($A2<=Sheet1!$C$2:$C$300000,ROW(Sheet1!$A$2:$A$300000),2^20+1))))}
this is an array formula which is exactly formulated respecting the requirements. But this is very bad in performance for using in much many cells. But using this, the Sheet1 is not required to be sorted.
Benchmark test:
Have the following Sheet1:
Formulas:
A2:A300002: ="S"&(ROW(A1)-1)*10&"-"&(ROW(A1)-1)*10+7
B2:B300002: =(ROW(A1)-1)*10
C2:C300002: =B2+7
and the following Sheet2:
Formulas:
A2:A300002: =RANDBETWEEN(0,3000007)
B2:B300002: =INDEX(Sheet1!A:A,IF(MATCH(A2,Sheet1!B:B)>IFERROR(MATCH(A2-10^-9,Sheet1!C:C),0),MATCH(A2,Sheet1!B:B),NA()))
Note the -10^-9 instead of -10^-10 in previous version. This is because we have only 16 digits precision. In previous version this was maximum 6 digits integer part and then 10 digits decimal part. Now it is maximum 7 digits integer part and then 9 digits decimal part.
Calculation after pressing F9 in Sheet2 takes ca. 2 s. (Excel 2007, Windows 7, 4 core processor).
I would have gone for something like this which gives you the first match if there is one:-
=INDEX(First!A:A,MATCH(1,(First!B:B<=A2)*(First!C:C>=A2),0))
assuming keys and start and end values are in a sheet called First and lookup values start in A2.
Array formula which must be entered with CtrlShiftEnter
In response to the question from #pnuts about how long it will take, I have set up a similar benchmark with 300,000 rows in each sheet and it has reached 1% after 90 minutes, so it should take about 150 hours to reach 100% or roughly one week. This is to be expected as the number of computations required is (rows in sheet 1) X (rows in sheet 2)
300,000 X 300,000
but in fact because the multiplication applies to complete columns, I believe it is more correctly
300,000 X 1,048,576
i.e. > 300 billion.
A practical version which gives good response for smaller ranges is as follows:-
I define three named ranges Range1, Range2 and Range3
=First!$A$1:INDEX(First!$A:$A,MATCH("ZZZ",First!$A:$A))
=First!$B$1:INDEX(First!$B:$B,MATCH(9.9E+307,First!$B:$B))
=First!$C$1:INDEX(First!$C:$C,MATCH(9.9E+307,First!$C:$C))
and the modified formula is
=INDEX(Range1,MATCH(1,(Range2<=A2)*(Range3>=A2),0))
I was thinking of deleting this answer, but would rather it stood as a counter-example.
I have a spreadsheet with data in a single row. The data is arranged by year with the earliest date in the right most cell and the latest date in the far left cell.
What I need is a formula that will begin looking at the cells beginning on the right (earlier date) and move to the left toward a later date skipping the empty cells. As soon as it finds data in one of the cells I need it to stop and show the value in that cell.
I have attached a picture as an example, in that picture I need it to begin at the cell for 2003 and begin moving left ignoring empty cells until it finds a cell with data. In this case the cell for 2005 contains data. I need it to copy that value ($2.43) and place it in the cell marked earliest value.
In the pictue I manually entered 2.43 in the cell for 2005 to show what i need.!
You can use LOOKUP function to get the last value in a row, so if you have years in A1:J1 and dollar amounts in A2:J2 just use this formula to get the last numeric value from A2:J2
=LOOKUP(9.99E+307,A2:J2)
9.99E+307 is [almost] the largest value that Excel allows, when you use that "big num" as lookup value the result is the last number in the range
I made two ranges, starting E4 to J4, I place 1,2,3,4,5,6. Below (thus range: E5-J5) I placed 6,5,4,3,2,1.
In a random cell I placed this formula:
=INDEX(E5:J5,MATCH(MIN(E4:J4),E4:J4,0))
This look in E4:J4 for the number that matched MIN(E4:J4), thus the lowest number. Then selects that value, matching the index, in the range E5:J5.
As follows from your image - year should be less than 10 yr history. In that case try following formula (I suppose that your data ( years and values) are in B3:X4 range):
=HLOOKUP(MIN(IF((B4:X4<>"")*(B3:X3>YEAR(NOW())-10),B3:X3)),B3:X4,2,0)
Note, that it is an array formula, so you need to press CTRL+SHIFT+ENTER to evaluate it.
If you don't need to use condition year should be less than 10 yr history, just remove *(B3:X3>YEAR(NOW())-10) from the formula:
=HLOOKUP(MIN(IF(B4:X4<>"",B3:X3)),B3:X4,2,0)
and press CTRL+SHIFT+ENTER to evaluate it.
I have a sheet with rows of data, with many columns. I am looking for help on a formula that will extract the sum of the smallest 3 numbers in a row based on the last 5 values entered. Note that not all the rows will have values for each column, so the first value found on each row will may be found in a different column.
To determine the sum of the smallest 3 I am using the formula =SUM(SMALL(B3:R3,{1,2,3})), Unfortunately, that formula is looking at the entire range. Again, I am looking for help that with a formula that will select only the last 5 values posted.
Here is simple example. The results for each line show the totals that should be determined. Again, it needs to look for the sum of the smallest 3 based on the last 5 posted (in the example below the range would be col. 1 thru 10, with col 10 having the latest postings).
Ex.
1.....2.....3......4......5.....6.....7.....8......9.....10...... Result
31.........44....51....36..........44...34....36....38.......106 (34+36+34)
35..31...44...40.....38...52..........42....37...............115 (37+38+40)
Hope this is understandable. I am looking for a formula solution vs a VBA macro solution because of my users. Thanks for any help!!
Now that you clarified the question, I have an answer for you. This is fairly ugly but it gets the job done. You might want to hide the columns with the intermediate results - or you could get adventurous and "nest" the expressions. This makes it really hard to understand / debug though. If there's a smarter way to do this I am always open to learning.
Assuming you have the data in columns A through J, starting in row 2, put the following in cell L2:P2:
=MATCH(9999, A2:J2,1)
=MATCH(9999,OFFSET($A2,0,0, 1, L2-1)) ... copy this by dragging right to the next 2 columns
=MATCH(9999,OFFSET($A2,0,0, 1, M2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, N2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, O2-1))
The first line finds the last cell with data in it; the next ones find the last cell "not including the last cell", and so they work backwards. The result is a number corresponding to the columns with data. For your example, this gives
10 9 8 7 5
9 8 6 5 4
Now we want to find the sum of the smallest 3 of these: put the following equation in cell Q2:
=SUM(SMALL(INDIRECT("RC["&P2-17&"]:RC["&L2-17&"]",FALSE),{1,2,3}))
Working from the inside out:
RC["&P2-17"] results in RC[-12], which is "the cell 12 to the left of this one".
That is the first of the "last five cells with data", cell E2
RC["&L2-17"] results in RC[-7], the last cell with data in this row
FALSE use "RC" rather than "A1" indexing
INDIRECT turn string into an address (in this case a range)
SMALL find the 3 smallest values in this range
SUM and add them together.
This formula did indeed give me 106, 115 for the example you provided.
I would hide columns L through P so you only see the result (and not the intermediate stuff).