i want to find the percentage of the values in range. for eg : if value between 10 & 20 then display the 20% of value, if value between 20.01 & 50 then display the 10% of value.
a sheet is attached here for more clarification.
https://docs.google.com/spreadsheets/d/1HlIflx8GkoCesl2jWdoHe30PzzAbuXUQE9XGasE7Iys/edit?usp=sharing
I have added three sheets to your sample spreadsheet.
The sheet called "Erik Help - Option 1" is self-contained. See the stand-alone array formula in cell B1:
=ArrayFormula({"UPDATED PRICE"; IF(A2:A="","",IFS(A2:A<=7,9.95, A2:A<=10,11.45, A2:A<=20,A2:A*20%, A2:A<=50,A2:A*10%, A2:A,A2:A*5%))})
This formula creates a virtual array by using curly brackets { }. First, the header is placed. Then a simple IF statement checks for whether there is anything in each cell of Column A. If there is not, then Column B will be null; if there is, then Column B will check the value of each cell in Column A against the elements of the IFS function.
The second sheet, entitled "Erik Help - Option 2," relies on the third sheet, entitled "Values." This would allow you more ease in changing assigned values.
The array formula in cell B1 of "Erik Help - Option 2" is as follows:
=ArrayFormula({"UPDATED PRICE"; IF(A2:A="","",IF(VLOOKUP(A2:A,Values!A2:C,3,TRUE)>=1,VLOOKUP(A2:A,Values!A2:C,3,TRUE),A2:A*VLOOKUP(A2:A,Values!A2:C,3,TRUE)))})
This works the same as the previous formula except that instead of referencing IFS for values, this formula references the sheet "Values" with a LOOKUP.
After checking for null values, another IF statement checks to see if the lookup value from Values!C2:C >=1 (i.e., whether it is a dollar amount or a percentage):
If this is TRUE (i.e., if the corresponding Values!C2:C value a dollar amount), the VLOOKUP runs again, comparing values from 'Erik Help - Option 2!'A2:A with the values in Values!A2:A and returning the value in Values!C2:C.
If this is FALSE (i.e., if the corresponding Values!C2:C value is a percentage amount), the values from 'Erik Help - Option 2'!A2:A are multiplied by the corresponding values in Values!C2:C.
As you can see, the results from "Erik Help - Option 1" and "Erik Help - Option 2" are identical. So it comes down to preference. If you want a self-contained option and feel comfortable editing the formula itself in the future if values change, use Option 1. If you prefer the ease of changing the values in chart form, use Option 2 with the Values chart.
NOTE: In my sheets, I also applied currency formatting (Format > Number > Currency) to all cells that contain or might contain dollar values.
I'm learning basic =ARRAYFORMULA usage for a finance spreadsheet:
https://docs.google.com/spreadsheets/d/12cAGuUBzIo0LPbmtqWJZNFgjt94f1ybGoj6x2g0c2Y0/edit?usp=sharing
First, I used =GOOGLEFINANCE at B1 to pull up stock prices for a given date range in Column C
=GOOGLEFINANCE(A1,"price",DATE(2020,1,1),DATE(2020,5,30),"DAILY")
Then, I used simple arithmetic to multiply by number of shares at D2 and dragged the formulas down to get a nice column of values
=C2*20
Then, I used INDEX and COUNTA to pull out the last value of Column D at F3 === Great!
=INDEX(AAPL!D2:D,COUNTA(AAPL!D2:D),1)
Next, I turned my arithmetic formula into an ARRAYFORMULA at G2 === Cool!
=ARRAYFORMULA(C2:C103*20)
Of course, the problem with that ARRAYFORMULA is that I would have to manually change the array name in G2 every time the date range updated.
That is, instead of C2:C103, I would need to change the reference to C2:104 to get the columns to match === Rookie mistake!!!!!
So, I got smart with an ARRAYFORMULA containing a IF(ISBLANK(),...,...) at J2
=ARRAYFORMULA(IF(ISBLANK(B2:B),"",C2:C*20))
Column J stays fully populated with the correct values for any date range === !!!!!!!
But now the =INDEX(AAPL!J2:J,COUNTA(AAPL!J2:J),1) at L3 can't find the last value in Column J
Whaaat???
I've tried everything I can think of
It works if I use =INDEX(AAPL!J2:J104,COUNTA(AAPL!J2:J104),1) but that would defeat the purpose, since the reference J:J104 is going to change as the dates change
WHY???
I get the same results in both cells "L3" and "L5" when using:
=ARRAYFORMULA(IF(ISBLANK(B2:B),,C2:C*20))
Check that you are not returning a blank string ("") in your IF like: "=ARRAYFORMULA(IF(ISBLANK(B2:B),"",C2:C*20))" doing so will fill the cells up to the last row in the sheet with empty strings, thus when you use COUNTA(AAPL!J2:J),1) you get a lot more cells than you would expect, these extra cells are the ones you filled with blank strings in the array formula.
On the contrary when you limit the =INDEX(AAPL!J2:J104,COUNTA(AAPL!J2:J104),1) to cells with numbers only it doesn't mix strings and numbers in the calculation and you are naturally get the expected results.
How to create a Google Spreadsheet sum() which always ends on the cell above, even when new cells are added? I have several such calculations to make on each single column so solutions like this won't help.
Example:
On column B, I have several dynamic ranges which has to be summed. B1..B9 should be summed on B10, and B11..B19 should be summed on B20. I have tens such calculations to make. Every now and then, I add rows below the last summed row , and I want them to be added to the sum. I add a new row (call it 9.1) before row 10, and a new raw (let's call it 19.1) before row 20. I want B10 to contain the sum of B1 through B9.1 and B20 to contain the sum of B11:B19.1.
On excel, I have the offset function which does it like charm. But how to do it with google spreadsheet? I tried to use formulas like this:
=SUM(B1:INDIRECT(address(row()-1,column(),false))) # Formula on B10
=SUM(B11:INDIRECT(address(row()-1,column(),false))) # Formula on B20
But on Google Spreadsheet, all it gives is a #name error.
I wasted hours trying to find a solution, maybe someone can calp?
Please advise
Amnon
You are probably looking for formula like:
=SUM(INDIRECT("B1:"&ADDRESS(ROW()-1,COLUMN(),4)))
Google Spreadsheet INDIRECT returns reference to a cell or area, while - from what I recall - Excel INDIRECT returns always reference to a cell.
Given Google's INDIRECT indeed has some hard time when you try to use it inside SUM as cell reference, what you want is to feed SUM with whole range to be summed up in e.g. a1 notation: "B1:BX".
You get the address you want in the same way as in EXCEL (note "4" here for row/column relative, by default Google INDIRECT returns absolute):
ADDRESS(ROW()-1,COLUMN(),4)
and than use it to prepare range string for SUM function by concatenating with starting cell.
"B1:"&
and wrap it up with INDIRECT, which will return area to be sum up.
REFERRING TO BELOW ANSWER from Druvision (I cant comment yet, I didn't want to multiply answers)
Instead of time consuming formulas corrections each time row is inserted/deleted to make all look like:
=SUM(INDIRECT(ADDRESS(ROW()-9,COLUMN(),4)&":"&ADDRESS(ROW()-1,COLUMN(),4)))
You can spare one column in separate sheet for holding variables (let's name it "def"), let's say Z, to define starting points e.g.
in Z1 write "B1"
in Z2 write "B11"
etc.
and than use it as variable in your sum by using INDEX:
SUM(INDIRECT(INDEX(def!Z:Z,1,1)&":"&ADDRESS(ROW()-1,COLUMN(),4))) - sums from B1 to calculated row, since in Z1 we have "B1" ( the 1,1 in INDEX(...,1,1) )
SUM(INDIRECT(INDEX(def!Z:Z,2,1)&":"&ADDRESS(ROW()-1,COLUMN(),4))) - sums from B11 to calculated row, since in Z2 we have "B11" ( the 2,1 in INDEX(...,2,1) )
please note:
Separate sheet named 'def' - you don't want row insert/delete influence that data, thus keep it on side. Useful for adding some validation lists, other stuff you need in your formulas.
"Z:Z" notation - whole column. You said you had a lot of such formulas ;)
Thus you preserve flexibility of defining starting cell for each of your formulas, which is not influenced by calculation sheet changes.
By the way, wouldn't it be easier to write custom function/script summing up all rows above cell? If you feel like javascripting, from what I recall, google spreadsheet has now nice script editor. You can make a function called e.g. sumRowsAboveMe() and than just use it in your sheet like =sumRowsAboveMe() in sheet cell.
Note: you might have to replace commas by semicolons
NOTE
After testing this answer, it will only work if the sum is in a different column due to a circular dependency error. Otherwise, the solution is valid.
It's a bit of algebra, but we can take advantage of Spreadsheets' lower right corner drag.
=SUM(X:X) - SUM(X2:X)
Where X is the column you are working with and X2 is your ending point. Drag the formula down and Sheets will increment the X2, thus changing the ending point.
*You mentioned that you had tens of such calculations to make. So in order to fit your exact need, we would subtract your last summation to get that "middle" range that we wanted.
e.g.
B1..B9 should be summed on B10, and B11..B19 should be summed on B20
Because of the circular dependency error mentioned earlier, I can't solve it exactly and put the sum on the same line, but this could work in other cases where the sum needs to be stored in a different column.
=SUM(B:B) - SUM(B9:B) //Formula on C10 (Sum of B1..B9)
=SUM(B:B) - SUM(B19:B) - B10 // Formula on C20 (Sum of B11..B19)
This is based on #PsychoFish, here is the solution:
=SUM(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","")&"3:"&ADDRESS(ROW()-1,COLUMN(),4)))
Simply replace the "3:" for the row to start sum.
#PsychoFish is correct but cannot be dragged and copied since the column is literal and hard coded, and #Druvision was in the right direction but was wrong... basically ended up with the same issue of having to re-enter the ranges and then sliding the formulas over and over.
You guys are making this harder than you have to. I just leave a couple of empty rows above by "sum" row (you can format them to be filled with color or something to keep them from being inadvertently used), then just add your new rows just above those special rows.
Agree with what user7255446 said that everyone is overcomplicating. Keep one row blank before your sum row. And then whenever you want to insert a new row, click on your blank row and use "Insert row ABOVE" instead of "insert row below". Your sum formula will automatically adjust.
Example: I want to sum from B1 to B19. I leave row 20 blank. In cell B21, put =SUM(B1:B20). Then if you ever need to insert a new row, click on row 20 and choose "Insert row above". The sum formula automatically changes to =SUM(B1:B21) for you. And of course your sum cell is now B22.
General syntax:
=SUM(INDIRECT(cell_reference_as_string1 &":"& cell_reference_as_string2)
with for example:
cell_reference_as_string1 = ADDRESS(ROW(),COLUMN(),4)
cell_reference_as_string2 = ADDRESS(ROW()-1,COLUMN(),4)
I like how #abernier describes the general solution. So far only alphabet-based A1 notation (A being first column, 1 being first row) are being used. It keeps confusing me, especially when thinking of number of columns left of another column. I like the number-based R1C1 notation much better. To use R1C1 notation for INDIRECT, you need to pass FALSE like so:
=SUM(INDIRECT("R1C"&COLUMN()&":R"&(ROW()-1)&"C"&COLUMN(), FALSE))
I hope you find that helpful, too.
OFFSET() can be used/abused for this purpose. Give it the absolute address of the top left of the range, 0 and 0 for the row/column offsets, and the height/width of the range. Let OFFSET() be the argument to SUM(), SUMIF(), etc.
ROW() and COLUMN() are handy when computing the desired height/width. Be sure to remember to subtract one to exclude the current row/column, or else you're liable to end up with a circular reference. If you have header rows/columns, subtract for them too.
For example, to sum everything from A2 down, excluding the current row, try:
=SUM(OFFSET($A$2,0,0,ROW()-2,1))
To sum everything to the left of the current cell, wherever it may be, try:
=SUM(OFFSET(INDIRECT("RC1",FALSE),0,0,1,COLUMN()-1))
Now let's flip things upside down, to show that this works in the other direction. Suppose you want to sum the B column, starting below the current row, until (and including) row #10. Try this:
=SUM(OFFSET($B$10,ROW()-9,0,10-ROW(),1))
You can avoid negative offsets, while still summing column B:
=SUM(OFFSET(INDIRECT("RC2",FALSE),1,0,10-ROW(),1))
Remove the "2" to instead sum the current column:
=SUM(OFFSET(INDIRECT("RC",FALSE),1,0,10-ROW(),1))
(Credit to Tom Sharpe, who commented above.) INDEX() can be used in a range expression. You might prefer this over OFFSET(), so I'm putting it here. The following sums everything from G1 down to the row above the current:
=SUM(G1:INDEX(G:G,ROW()-1))
Here's how I do it.
This formula does not require you to edit or enter anything about the particular column you would like to sum
=SUM(INDIRECT(CONCATENATE(address(1,column(),4),":",LEFT(address(1,column(),4),1))&ROW()-1))
The answer by #PsychoFish led me in the correct way.
The only issue that I had to rewrite the formula again from each column and each sum. So here is the improved formula, which sums the previous 9 cells on the same column, without hardcoding the column or row numbers:
=SUM(INDIRECT(ADDRESS(ROW()-9,COLUMN(),4)&":"&ADDRESS(ROW()-1,COLUMN(),4)))
The only issue is that I had to rewrite the formulas if someone adds or deletes a row. In this case I should change 9 to 10 or 8 corrspondingly.
I cannot have VLOOKUP to properly work if it has to match computed values.
Please see this example:
In test sheet, row 1 tests data in computed sheet, where B2 cell is the result of =RIGHT(A1, 4).
Value 1234 is not found
Meanwhile, on row 2 of test, if 1234 is the hardcoded value of the cell — sheet hardcoded —
Value is found.
Is this a bug?
Is it enough for you to change your formula to =value(RIGHT(A1,4)) ?
I'd say not a bug (Excel behaves the same way). Use of =RIGHT has automatically output as a string. If instead you had had =1233+1 you should not have had any problem.
I have a Google sheet for tracking my weight. I have two columns: Date and Weight. While the goal is to have the weight column sorted in descending order, that doesn't always happen in reality...
The data essentially looks like this (weights changed to far lower values, of course):
Date |Weight
04/01/10|195
04/02/10|194
04/03/10|190
04/04/10|198
etc.
Anyway, I have a cell in another spot on the sheet that shows the minimum value from the weight column using this formula
=(Min(B:B))
What I would like to do is display the corresponding date cell for whatever the minimum value from the weight column is. So, with this dataset, I want to show 190 for weight and 04/03/10 for date. Is there any way to get that corresponding cell? I looked through the function reference for Google docs, but can't get anything going. I tried using some of the functions from the Lookup category, but got nowhere. Most want a cell reference, but the min() function returns a value. I think I need to somehow get min() to give me a cell reference, but I don't know how to do that. HLOOKUP() sort of seemed like it might be appropriate, but the docs were a bit spotty, and it didn't do anything but error out the cell.
Of course, I may be barking up the wrong tree entirely.
Thoughts?
I would use the following two formula's:
MIN(B2:B)
FILTER(A2:A;B2:B=minimal value)
If there are more results, they need to be included as well.
See example file I've created: Getting Corresponding Cell In Google Docs Spreadsheet?
Not barking up the wrong tree, actually very close:
=index(A:A,match(min(B:B),B:B,0))
should meet your requirement.
Working inside out: min(B:B) (as you had) returns the lowest weight (ie 190) in ColumnB.
match then finds the position of that value relative to the start of the range in which the value is searched for. So assuming Date is in A1, that returns 4, being the fourth row in ColumnB, where 190 is. The 0 in the formula is to ensure that only the position of an exact match is returned.
Now we know we need the content of the fourth row we can go looking for the value there in ColumnA with index, returning 04/03/2010.
Not all is ideal however. It is possible that a weight of 190 was achieved on separate days. It is the nature of match that where an exact match is required and found the function stops looking for any further instances. Hence as things stand 04/03/2010 will be returned for 190 however often that is the weight for a day after 04/04/2010 - unless other steps are taken, such as to delete/remove/ignore data from 04/03/2010.
You need to change the order of the column as the search column (the weight should be the first in the search array. Then you can use the VLOOKUP formula:
=VLOOKUP(C7,A:B,2,false)
C7 holds the MIN formula that you used: =(Min(A:A)) - note the column order change
one-cell solution to get minimal value with the latest day:
={MIN(B:B), TO_DATE(VLOOKUP(MIN(B:B), SORT({B:B,A:A}, 2, 0), 2, 0))}
to get all minimal values with dates:
=QUERY(A:B, "select B,A where B matches '"&MIN(B:B)&"' order by A desc", 0)