convert the values if it falls between specific number - google-sheets

I want to convert the values if it falls between specific number then convert them into specific number.
For Example
IF(AND(Cell>0.0, Cell<=0.25),0.25,"")
IF(AND(Cell>0.25, Cell<=0.50),0.50,"")
IF(AND(Cell>0.50, Cell<=0.75),0.75,"")
IF(AND(Cell>0.75, Cell<=1.0),1.0,"")
Is it possible to convert the values into given values i would appreciate your help thanks.
Sheet

updated answer:
=index(ceiling(A2:A22,0.25))
Alternative:
=index(lambda(z,xlookup(A2:A22,z,z,,1))({0.25,0.5,0.75,1,1.25,1.5}))

I wrote the solution in your sheet. You need to nest the if statements like this:
=IF(AND(A3>0,A3<=0.25), 0.25, IF(AND(A3>0.25,A3<=0.5), 0.5, IF(AND(A3>0.5,A3<=0.75), 0.75, IF(AND(A3>0.75,A3<=1), 1))))
It looks a bit messy but it works. I don't know what you wanted to be the result if the value was over 1 though...
The IF function works like this:
IF(statement, if it's true, if it's false)
So just check if it is between one interval, and then if it isn't then you check another interval.
Hope this helps:)

Related

I need ARRAYFORMULA() to use conditions in another row to decide what to calculate

Here is my formula in G5
=ARRAYFORMULA(IF(AND(J5:J17=true,H5:H17=false),E5:E17*F5:F17*1.075,IF(AND(J5:J17=true,H5:H17=TRUE),0,IF(and(J5:J17=false,H5:H17=false),E5:E17*F5:F17,IF(and(J5:J17=false,H5:H17=true),0)))))
This works if Cols H,I, and J are all false, however once I start setting anything in H,I,or J to true, the formula stops working.
Thanks for any help, Im really stumped on this one.
I think you can simplify your formula all the way down to:
=arrayformula(E5:E17*F5:F17*not(H5:H17)*if(J5:J17,1.075,1))
A few pointers:
What you were trying to achieve boils down to: 'on each row, give me the value of the cell in colE * the value of the cell in colF, multiplied by 1.075 if the cell in colJ is ticked, unless the cell in colH is ticked, in which case give me 0.
You don't need to evaluate tickboxes against TRUE/FALSE as they contain a TRUE/FALSE themselves (so the =TRUEs & =FALSEs in your formula are redundant)
AND/OR in arrays don't work the way you might initially want them to as they are aggregating functions (i.e. they accept arrays as input by design) and wrapping them in ARRAYFORMULA to try to make them evaluate the input arrays row-by-row or column-by-column doesn't work. Historically the answer to this problem has been to use Boolean algebra (where AND is * & OR is +, FALSE=0 and TRUE<>0) as I've done here which normally makes for the most compact representation, but more recently it's also been possible to use MAP to process arrays element-by-element (in which case AND/OR can still be used) as per one of the other answers
You only really need to use IF statements if you want to return values other than TRUE/FALSE (1/0) as a result of a logical evaluation (like your colJ where you want TRUE=1.075 & FALSE=1); otherwise you can omit them and just use Booleans.
use:
=ARRAYFORMULA(IF((J5:J17=true)*(H5:H17=false), E5:E17*F5:F17*1.075,
IF((J5:J17=true)*(H5:H17=TRUE), 0,
IF((J5:J17=false)*(H5:H17=false), E5:E17*F5:F17,
IF((J5:J17=false)*(H5:H17=true), 0)))))
You can try to do this with MAP:
=MAP(J5:J17,H5:H17,E5:E17,F5:F17,LAMBDA(j,h,e,f,
IF(AND(j=true,h=false),e*f*1.075,IF(AND(j=true,h=TRUE),0,IF(and(j=false,h=false),e*f,IF(and(j=false,h=true),0))))))

How to calculate the difference of numbers in series using Google sheets formula?

I have an inventory sheet, where I need to calculate the difference between the actual value and the series of expected values. Here is a snapshot of what I am talking about:
So for Item1:
Current: 50
Expected: 45,45,45
Now I want to devise a formula that will calculate a difference until the last column in this specific row, something like this:
difference = 50-(45,45,45) //50-45+50-45+50-45 and so on (Q,R..)
difference = 15 //final result
Is there any way that we can achieve this by putting formula in a cell, any help would be much appreciated, thank you.
In google-sheet you can use-
=ArrayFormula(SUM(M2-N2:P2))
In excel use below formula
=SUM(M2-N2:P2)
In case of non 365 version of excel you need to enter it as array means confirm by CTRL+SHIFT+ENTER.

Formula that will skip one column when calculating SUM() or similar functions

I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))

i can't find a formula that verifies if something repeats on a column

I'm doing a project in googlesheets and i need to use a formula that verifies if an input on a segment repeats in other segments on the same column.
Thanks in advance.
Assuming your inputs are A1:A8, starting with A1:
=IF(COUNTIF($A$1:$A$8, A1) = 1, "UNIQUE", "REPEATS")
Result
If you wanted to list which values were repeated, you could do it as single formula using:
=filter(unique(A:A),countif(A:A,unique(A:A))>1)
If you just wanted to know if there were any repeats anywhere, then it would just be
=counta(A:A)<>countunique(A:A)
Or if you wanted to flag up each row to show whether it was repeated or not:
=ArrayFormula(if(A:A<>"",countif(A:A,A:A)>1,))

Get value after last comma by formula

A2:
96610,80508,64406,48305
How do I extract the last value, in this case 48305?
There must be an easy solution, but I can't come up with it.
Another way would be something like
=regexextract(A2&"", "[^,]+$")
or, to convert the output to a number:
=regexextract(A2&"", "[^,]+$")+0
This formula did it:
=TRIM(RIGHT(SUBSTITUTE(A2,",",REPT(" ",500)),500))

Resources