Nested If Formula always returning FALSE - Google Spreadsheet - google-sheets-formula

I am trying to use a formula to tell if the cell value is within one of these ranges and set the value based on which is true.
If the value is between 0 and 10 set the cell value to "Needs Improvement"
If the value is between 10 and 15 set the cell value to "Meets Expectations"
If the value is greater than 15 Set the cell value to "Exceeds Expectations"
Any value I put it in always results in it being false meaning it doesn't apply any of those values.
My current formula is:
=IF(AND(D21>=0, D21<=10), "Value is between 5 and 10", IF(AND(D21>=10, D21<=15), "Value is between 15 and 20", IF(AND(D21>=15, D21<=100), "Value is between 15 and 20", "Value is not within the specified range")))
No matter what I change the number to it's always not within the specified range, I have tried googling so many things but I cannot figure it out

instead of AND(D21>=0, D21<=10), use ISBETWEEN(D21,0,10)
the range of number you set is over lapping each other, correct way to go should be something like AND(>=0,<=9), AND(>=10,<=14), AND(>=15,<=100) in you case,
these kind of nested IF() is easy to get wrong if you don't know what you are doing. You can instead use a non-nested way to do what you want:
=LAMBDA(VALUE,
IF(ISBETWEEN(VALUE,0,9),"Value is between 0 and 9","")
&IF(ISBETWEEN(VALUE,10,14),"Value is between 10 and 14","")
&IF(ISBETWEEN(VALUE,15,100),"Value is between 15 and 100","")
&IF(OR(VALUE<0,VALUE>100),"Value is not within the specified range","")
)($D$21)
And since you are referencing D21 instead of D1 or D2,
make sure you have entered the value to test into cell D21.
Actually IFS() is a better option than IF() in this case:
=LAMBDA(VALUE,
IFS(
ISBETWEEN(VALUE,0,9),"Value is between 0 and 9",
ISBETWEEN(VALUE,10,14),"Value is between 10 and 14",
ISBETWEEN(VALUE,15,100),"Value is between 15 and 100",
TRUE,"Value is not within the specified range"
)
)($D$21)

use:
=IF(AND(D21>=0, D21<=10), "Needs Improvement", IF(AND(D21>10, D21<=15), "Meets Expectations", IF(D21>15, "Exceeds Expectations")))

Related

Sum or Percentage of a word in the results / column

I have a report that in part is providing: Job Date, Job Target Date and Completion date.
I have a column at the end that works out whether or not the job was completed within the target time our outside of returning true or false.
As mentioned, I have created a column to work out whether a job is completed on time and I have tried googling many different solutions and trying them out.
The expression I've used to work out whether the job was completed on time is:
=IIF(Fields!CompletedDate.Value <= Fields!Target.Value, "True", "False")
Now I need an expression to work out the percentage that are within the target. So, let's say there are 80 jobs and 67 are completed in time. It would be 'True' (67) / 80 *100 = 83%.
The expression I've used to work out whether the job was completed on time is:
=IIF(Fields!CompletedDate.Value <= Fields!Target.Value, "True", "False")
Now I need an expression to work out the percentage that are within the target. So, let's say there are 80 jobs and 67 are completed in time. It would be 'True' (67) / 80 *100 = 83%.
I figured this one out myself, again..
If anyone is interested I kept the same IF statement in the original cell. I then created 2 additional cells underneath one containing the text 'Percentage of jobs completed on target' and the other cell I added a new expression that included the original one above;
=SUM(IIF(Fields!CompletedDate.Value <= Fields!Target.Value, 1, 0)) / count(Fields!PropertyCode.Value)
All I had to keep in mind was that I am already showing the results as true and false so in my seconds expression I change the values to numbers so I can calculate. True is '1' so I know that it will not be calculating on 0 as it cannot divide by zero.
So, I did a sum on the number true represented as 1 divided by number of results. Rather than times this by 100 ( 5/19*100 = percentage), I simply left out the times and changed the format of that cell to percentage so it takes the value in the cell and returns the percentage.
Thanks,
Jordan

Change All Value Labels to Numerics in SPSS

I need to change all the value labels of all my variables in my spss file to be the value itself.
I first tried -
Value Labels ALL.
EXECUTE.
This removes the value labels, but also removes the value entirely. I need this to have a label of some sort as I am converting the file and when there is no values defined it turns the value into a numeric. Therefore, I need the all value labels changed into numbers so that each value's label is just the value - value = 1 then label = 1.
Any ideas to do this across all my variables??
Thanks in advance!!
Here is a solution to get you started:
get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".
begin program.
import spss, spssaux, spssdata
spss.Submit("set mprint on.")
vd=spssaux.VariableDict(variableType ="numeric")
for v in vd:
allvalues = list(set(item[0] for item in spssdata.Spssdata(v.VariableName, names=False).fetchall()))
if allvalues:
cmd="value labels " + v.VariableName + "\n".join([" %(i)s '%(i)s'" %locals() for i in allvalues if i <> None]) + "."
spss.Submit(cmd)
spss.Submit("set mprint off.")
end program.
You may want to read this to understand the behaviour of fetchall in reading date variables (or simply exclude date variables from having their values labelled also, if they cause no problems?)

re sizing column data with tcl

I have a set of data that has a X number of points and I want to re size this to x+n number of points.
I need to do this with tcl and am struggling in the last part.
I know the Max, Min and the delta that is needed to refit the data to desired number of points.
Original data:
-0.3925
-0.262
-0.1965
-0.026
-0.013
-0.0065
-0.0026
0
0.0026
0.0065
0.013
0.026
0.1965
0.262
0.3925
I'm struggling to construct a for loop that will, take the first value and subtract it from delta to create the second value. Subsequently take the second and subtract it from delta to create third and so on and so forth.
Given:
Points 19
Min : -0.3925
Max :0.3925
Delta : 0.04361
Results column data would look like:
-0.3925
-0.348888889
-0.305277778
-0.261666667
-0.218055556
-0.174444444
-0.130833333
-0.087222222
-0.043611111
-6.93889E-17
0.043611111
0.087222222
0.130833333
0.174444444
0.218055556
0.261666667
0.305277778
0.348888889
0.3925
Could someone kindly give me some advice.
There are a few key points when doing this sort of thing (and these apply to languages other than Tcl too). Firstly, you should compute the delta from the span you want and the number of steps you want. Secondly, you should keep your incrementing and loop control using integers if you can, so as to avoid fencepost errors caused by rounding; instead compute the value for the loop iteration by multiplying the delta by the loop counter and adding to the originating value. Thirdly, you should consider what the right precision is when printing your results; in Tcl, this tends to mean using format with the %f conversion and appropriate width specifier.
set from -0.3925
set to 0.3925
set points 19
set delta [expr {($to-$from) / double($points-1)}]
for {set i 0} {$i<$points} {incr i} {
set x [expr {$from + $i*$delta}]
puts [format "%.5f" $x]
}
This produces this output:
-0.39250
-0.34889
-0.30528
-0.26167
-0.21806
-0.17444
-0.13083
-0.08722
-0.04361
0.00000
0.04361
0.08722
0.13083
0.17444
0.21806
0.26167
0.30528
0.34889
0.39250

SSRS sum based on not-null condition

I have a report I am building that I am summing a column with the total minutes listed in it then dividing it by 60 to get number of hours like so.
=Sum(Fields!designtimeValue.Value) / 60
But I have a condition where I want to weed out rows that contain other data in another column
Its laid out like so
Submittal_date Submittal_returned Design_Hours
12/01/2014 180
12/01/2014 12/02/2014 240
12/01/2014 60
So I want to do something like =Sum(IIF(Fields!sumbittal_returned.Value="NULL",Fields!design_hours.Value)) / 60
But it is throwing an error the sum iff does not allow that number of exceptions
I then need to take it a step further And be able to take the sum of design total if submittal_returned = NULL total then for any instance submittal_returned = Not-NULL add 120 minutes
Thanks
Edit : format code
IIF takes 3 arguments. A condition, a true result, and a false result. You have to supply all three.
This would be the correct syntax:
=Sum(IIF(IsNothing(Fields!submittal_returned.Value),Fields!design_hours.Value,0)) / 60
Although that condition will only be true if submittal_returned actually contained the string "NULL". If it's actually NULL (not a string), you would need test with the IsNothing() function.
Not sure I understand your last sentence, maybe you mean this?:
=Sum(IIF(IsNothing(Fields!submittal_returned.Value),Fields!design_hours.Value,Fields!design_hours.Value + 120)) / 60

VBScript: Finding the number of non-null elements in an array

What is the "best" way to determine the number of elements in an array in VBScript?
UBound() tells you how many slots have been allocated for the array, but not how many are filled--depending on the situation, those may or may not be the same numbers.
First off there is no predefined identifier called vbUndefined as the currently accepted answer appears to imply. That code only works when there is not an Option Explicit at the top of the script. If you are not yet using Option Explicit then start doing so, it will save you all manner of grief.
The value you could use in place of vbUndefined is Empty, e.g.,:-
If arr(x) = Empty Then ...
Empty is a predefined identify and is the default value of a variable or array element that has not yet had a value assigned to it.
However there is Gotcha to watch out for. The following statements all display true:-
MsgBox 0 = Empty
MsgBox "" = Empty
MsgBox CDate("30 Dec 1899") = True
Hence if you expect any of these values to be a valid defined value of an array element then comparing to Empty doesn't cut it.
If you really want to be sure that the element is truely "undefined" that is "empty" use the IsEmpty function:-
If IsEmpty(arr(x)) Then
IsEmpty will only return true if the parameter it actually properly Empty.
There is also another issue, Null is a possible value that can be held in an array or variable. However:-
MsgBox Null = Empty
Is a runtime error, "invalid use of null" and :-
MsgBox IsEmpty(Null)
is false. So you need to decide if Null means undefined or is a valid value. If Null also means undefined you need your If statement to look like:-
If IsEmpty(arr(x)) Or IsNull(arr(x)) Then ....
You might be able to waive this if you know a Null will never be assigned into the array.
I'm not aware of a non-iterative method to do this, so here's the iterative method:
Function countEmptySlots(arr)
Dim x, c
c = 0
For x = 0 To ubound(arr)
If arr(x) = vbUndefined Then c = c + 1
Next
countEmptySlots = c
End Function
As Spencer Ruport says, it's probably better to keep track yourself to begin with.
There's nothing built in to tell you what elements are filled. The best way is to keep track of this yourself using a count variable as you add/remove elements from the array.

Resources