I'm trying to mod a formula in google sheet to substract a value based on the value of another column
Column E has the amount of hours: 3, 4, 5, 9 for example
If the hours are between 4 and 5 I need to substract 0.25 , if between 5 and 6 - 0.50 and if > 8 - 0.75
this is what I did:
=ArrayFormula(if(len(E2:E) ,(ifs((E2:E=0),IFERROR (1/0),AND(E2:E > 4 , E2:E < 6 , E2:E-0.25) or (E2:E > 6,E2:E < 8 ,E2:E-0.5) OR (E2:E > 8,E2:E-0.75)))))
could anyone please help me figuring out what I'm doing wrong? thank you
You can easily achieve this with vlookup.
Build a static array {} of two columns with your limits and results for the vlookup range:
={4,-0.25;5.0001,-0.5;6.0001,0;8.0001,-0.75}
Then a vlookup to test inputs. My input figs are in col G, and the vlookup is in an arrayformula in cell H1:
=arrayformula(if(G1:G<>"",iferror(vlookup(G1:G,{4,-0.25;5.0001,-0.5;6.0001,0;8.0001,-0.75},2,1),),))
You can then add the result to your existing formula.
UPDATE
This takes the hour value from col E and makes the required subtraction. Add this formula to cell F1 and clear all cells below:
=arrayformula({"Adjusted hours";if(E2:E<>"",E2:E+iferror(vlookup(E2:E,{4,-0.25;5.0001,-0.5;8.0001,-0.75},2,1),),)})
Related
I want to use Sparkline for a spreadsheet to show a trend of the last 5 soccer matches, where A and B are the goals, and C are the resulting points.
In column C, the points are only generated if values are entered for the goals and goals conceded, i.e. the columns are not empty.
A (Goals)
B (Conceded)
C (Points)
4
4
1
4
4
1
4
4
0
3
4
4
1
0
4
0
As you see, in row 3, column c is empty.
What I basically try to achieve, is to create a list where the last 5 entries which are not empty / null, are listed:
C (Points)
1
1
3
1
0
Is used this formula, but it somehow does not work
=query(J15:J114,"select * offset "&count(J15:J114)-5)
shorturl.at/gHPY9 (example result picture)
Tried to find a solution myself, but am stuck.
Best,
Feal
Use query() with a where clause, like this:
=query(
J15:J114,
"where J is not null
offset " & max(0, count(J15:J114) - 5),
0
)
I struggling to get the sum total of the top X values for a Row.
Let say top 3 in this case.
A
B
C
D
E
1
john
1
4
3
2
2
Mary
4
5
1
2
So the total of the top 3 values would be
name
Total
John
9
Mary
11
I can get a single LARGE number but can't figure out how to get the top 5 in the row (and then sum). Most examples have the values in COLS but my data is in ROWS
Answer:
Sum of top 5 in a row:
=ARRAYFORMULA(SUM(IFERROR(LARGE(A1:1, {1, 2, 3, 4, 5}), 0))
Rundown of this formula:
Use the array notation to denote the first, second, third, fourth and fifth highest in the row with {1, 2, 3, 4, 5}
Set this array as the n parameter for a LARGE formula, with the row as the range parameter
If the LARGE throws an error for whatever reason, return the value 0 for that value of n
SUM all answers
Wrap inside an ARRAYFORMULA so that LARGE gets all array values and not just the first.
References:
Using arrays in Google Sheets - Docs Editors Help
LARGE - Docs Editors Help
IFERROR - Docs Editors Help
SUM - Docs Editors Help
ARRAYFORMULA - Docs Editors Help
I have a table in my Google Spreadsheet that looks like this :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
4
day 1
8
5
day 2
7
6
day 3
9
7
total
Where I can have multiple "day rows", but I don't know how many. It can be only 1 like it can be 20 "day rows". And I want the "total row" to automatically do a SUM of the "day rows" above.
Result expected :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
15
4
day 1
8
5
day 2
7
6
day 3
9
7
total
24
Where B3 is equal to SUM(B1:B2) and B7 is equal to SUM(B4:B6)
I am trying to do that without the App Script, just using Spreadsheet native functions.
I think I should be using the SUM function or the Query function, but I don't know how to dynamically get the right range. Do you have any idea how to do that ?
Thank you
In your example, column B would be a mixture of constants and formulas. That would require a script to deposit the formulas. However with an extra column, you can avoid scripts. In C2 enter:
=if(A2<>"Total","",sum($B$1:$B1)-sum($C$1:C1))
and copy downwards:
Basically we add column B and subtract any previous Totals in column C.
Another approach is to place the following single array formula in C1:
=ArrayFormula(IF(A:A="",, SUMIF(IF(ROW(A:A),ROW(A:A)), "<="&ROW(A:A),B:B) - SUMIF(IF(ROW(A:A), ROW(A:A)),"<="& VLOOKUP(ROW(A:A)-1, FILTER(ROW(A:A), A:A="total"), 1, TRUE), B:B)))
If you only want to see the values for the "total" rows, change the opening
IF(A:A=""
to
IF(A:A<>"total"
The short version of how it works is that a sum is made of all values up to the current row in B:B, and from that is subtracted any values up to the last listing of the word "total" in A:A.
paste in each cell in B column where A column = total
=INDEX(SUM(IFERROR(1*INDIRECT(ADDRESS(MATCH(INDEX(
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()})-1, ROW()+1, 1),
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()}), 0), 2)&":"&
ADDRESS(ROW()-1, 2)), 0)))
I have a spreadsheet that works properly in Excel. However, when I import it to Google Sheets it gives me the #DIV/)! error. I am at a loss for how to fix this.
I am trying to rank the items based on the number in column P. I would like for the highest number in column P to be ranked 1, then 2, 3, etc. If two numbers in column P are the same I would like for them to both be ranked the same. However, I don't want the formula to then skip the next number in the ranking order. Also, I am not sure if it matters, but column P displays a number but is technically filled with a formula to obtain that number. Example:
Points column is populated using the following formula:
=SUM(H2,J2,L2,N2,O2)
Points Rank
5 3
3 4
8 1
3 4
6 2
2 5
=SUMPRODUCT((P2 < P$2:P$36)/COUNTIF(P$2:P$36,P$2:P$36))+1
Any ideas?
Add the opposite of the numerator to the denominator to ensure you never receive #DIV/0!.
=SUMPRODUCT((P2 < P$2:P$36)/(COUNTIF(P$2:P$36,P$2:P$36)+(P2 >= P$2:P$36)))+1
When (P2 < P$2:P$36) is false, the numerator will be zero so it doesn't matter what the denominator is as long as it isn't zero.
I have a ascending sorted list of irregular dates in Column A:A:
A B C D (A:A,A2:A) E (A:A,A3:A)
2017-11-09 10 10 NA NA
2017-11-10 11 21 1 NA
2017-11-14 15 36 4 5
2017-11-15 22 58 1 5
Column C:C is a rolling sum of B:B. I'm trying to get arrayformula in D:D/E:E to find the datedif between current row (starting date) and X rows above (end date):
=ArrayFormula(DATEDIF(B:B-(X Rows),B:B,"D"))
The goal is to find range of change in D:D over X amount of days:
D:D - D:D-rowX / datedif (A:A-rowX, A:A)
i.e for 2 days on row C4:
(C4-C2) / datedif(C4-2,C4,"D")
(58-21) / datedif(C2,C4,"D")
37 / 5 = 7.4
for 5 days on row C10:
(C10-C5) / datedif(C10-5,C10,"D")
for 15 days on row C20:
(C20-C5) / datedif(C20-15,C20,"D")
I'm trying to calculate X for 1,2,3,4,7,28 rows up which means the array has to start that 1,2,3,4,7,28 rows down.
Right now, the array bugs out to bad reference because the first starting date is DATEDIF(B-X,B1,"D") where B-X is a invalid negative reference. Arrayformulas with bad values instead of bad references seems to just skip past errors and starts working once input are valid. But I can't figure out how to skip bad references. I've tried forcing start date with INDIRECT but can't get it to recognize value as a date. I also tried DATEDIF(B:B, B:B+X,"D"), which spits out the correct numbers but results are offset by X rows. I've tried reverse sorting A:A, =ArrayFormula(if(len(A:A),DATEDIF(SORT(A2:A,1,0),SORT(A:A,1,0),"D"),"")) it produces a reverse orders list of correct answers that I can't figure out how to flip back.
Seems like I'm missing something obvious?
EDIT: tried to clarify original post
Is there a easy way to displace an entire column?
Alternative Solution?
The formula roughly works but is not aligned to the correct row:
C D E
1 2 3
1 2 3
1 2 3
1 2
1
I just need it to display
C D E
1
1 2
1 2 3
1 2 3
1 2 3
To get things aligned, I can put in cell on row2 of Column F:
=array_constrain(ARRAYFORMULA(D:D),COUNT(A:A)-2,1)
Or cell in row3 of Column G:
=array_constrain(ARRAYFORMULA(E:E),COUNT(A:A)-3,1)
But if I try trigger teh formula from row1 via:
=arrayformula(if(row(A:A)>=2,array_constrain(D:D,COUNT(A:A)-2,1)))
It label everythign >=2 row false and still render D:D without displacing the cells the proper number of rows:
C D
1 false
1 2
1 2
1 2
1
EDIT: I'm closing the request, ended up just using vlookup(B:B-X) which provided an approximate enough result to work for my needs.
Short answer
Add the following formula to D1
=ArrayFormula({"N/A";ARRAY_CONSTRAIN(DATEDIF(A:A,A2:A,"D"),COUNT(A:A)-1,1)})
And the following formula to E1
=ArrayFormula({"N/A";"N/A";ARRAY_CONSTRAIN(DATEDIF(A:A,A3:A,"D"),COUNT(A:A)-2,1)})
Explanation
The solution use ARRAY_CONSTRAIN to return just the required result values and use a the array notation to add the required N/A values for the rows that as it don't have a pair to calculate the date difference.
REMARK:
Please note that the DATEDIF functions use the column A for the references as this column is the one that holds the date values.