I am trying to create a logical function in excel for the following conditions.
if value > 85 then the output should be 2
else if value < 85 the output should be 1
else
value < 65 the output should be 0
The formula I have created has the following syntax:
=IF(O25>85;"2";IF(O25<85;"1";IF(O25<65;"0")))
But the output for when it's less than 65 fails.
What have I missed here?
Add an AND statement, or swap order and check if less than 65 first
And statement:=IF(O25>85;"2";IF(AND(O25<85;O25>=65);"1";IF(O25<65;"0")))
Change order: =IF(O25>85;"2";IF(O25<65;"0";IF(O25<85;"1")))
Related
I'm trying to write a syntax code in order to perform a sum of values of different cases of the same variable. I need a loop the changes the selection of the cases for each sum based on two different variables (from the one I'm performing the sum with). It would be so nice to save the various results as a new variable but that's optional.
to give you an idea:
id. 1. 2. 1. 2.
var1. 23. 34. 23. 34
var2. 46. 37. 45. 56
sum1 (id=1 & var1=23) = 46 + 45;
sum2 (id=2 & var1=34) = 37 + 56
I already tried something like
LOOP #i=1 to 7.
LOOP #j=1 to 10.
COMPUTE filter_$=(var1 = #j & id = #i).
VARIABLE LABELS filter_$ 'var1 = #j & id = #i (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMATS filter_$ (f1.0).
FILTER BY filter_$.
DESCRIPTIVES VARIABLES=var2
/STATISTICS=SUM.
END LOOP.
END LOOP.
I really need help since I'm not a developer and having a lot of trouble working this out.
No need for looping or iterating :) - SPSS aggregate command can perform this kind of task easily:
aggregate out=* mode=add /break=id var1 /yourSum=sum(var2).
BTW this will add the sums as a new variable in the dataset, as you wanted.
Is it possible to combined Sumproduct, left and a AND function all together in Excel.
I have the below formula working correctly - but i want to add in the additional reviews which also = "88"
="Number Reviews: "&SUMPRODUCT(--(LEFT(M:M,2)="77"))
Is there a way to add in an "and" function which allows me to sum up all of 77 and 88 altogether?
& If this is possible - if i wanted to add up the remaining totals which are not 77 or 88, is that possible?
Thanks
If i understood your question correctly, this should work.
Sum up all of 77 and 88 altogether :
="Number Reviews: "&SUMPRODUCT(--(LEFT(M:M,2)="77")) + SUMPRODUCT(--(LEFT(M:M,2)="88"))
Which are not 77 or 88 :
Assuming you have Header in the data
=COUNTA(M:M)-(SUMPRODUCT(--(LEFT(M:M,2)="77")) + SUMPRODUCT(--(LEFT(M:M,2)="88")))-1
I have a list of values, some being integers and some being non-integers. I would like to return the values that are integers. My idea:
if(ISNUMBER(C1)=TRUE,C1,0)
The data is laid out as so
88
Francesc Fabregas
m
86
Andrey Arshavin
a
86
Therefore I would only return the 88, 86, and 86. 88 is in cell C1.
Update: THE CELLS HAVE THE VALUES STORED IN THEM AS TEXT. HOW MIGHT I CHANGE ALL THE CELLS FORMATTING TO NUMBERS?
Try:
=IFERROR(--C1,"")
It will try to multiply -1*-1 to the value, if it is like a number it will return the number but if not it will error out and return "".
If you are using 2003 or later then use:
=IF(ISERR(--C1),"",--C1)
To do it in place highlight the range and you will see a little box in the upper left corner:
Hit that button and you will have a drop down list of option. Choose the "Convert to Number" option.
The NUBMERVALUE() function converts text to numbers. So the formula
=IF(ISNUMBER(NUMBERVALUE(D14)), NUMBERVALUE(D14), 0)
would turn your data to
88
0
0
86
0
0
86
I have a list of numbers that i need to subtract to 60 when the number is greater than 60. is there any one here knows on what formula to use and how for me to do this????
for example:
61 = 1
75 = 15
52 = 52
using the needed formula this should be the result
Use IF condition.
The syntax for the Microsoft Excel IF function is:
IF( condition, [value_if_true], [value_if_false] )
Formula
=IF(A1>60,A1-60,A1)
Test link
I'm assuming this is number of seconds or minutes, and you want to clip it at 60 to wrap it around. This will do it:
=MOD(A1,60)
Otherwise use the If function like Ullas indicated above.
Note: Please if you can point a solution without 'eval', that would be great!!!
If not, I'll be thankful too :-)
Well, I have a cell (Var_s) that has in the first row strings and in the second row matrices:
clc
clearvars
fclose all
L=[11 22 33 44];
M=[1 2 3];
N=[101 102 103 104 105, 95 96 97 98 99];
Var_s=cell(2,3);
Var_s(1,1:3)={'Rn', 'LE', 'O'}; %// The strings are all different and were not created in a loop.
Var_s(2,1:3)={L, M, N}; %// No correlation is possible.
%//Than I delete all variables because I can work with the cell (Var_s{2,:})
%//to execute some computations
clearvars L M N
%//Now I want to save the values which are stored inside of the cells in the
%//second line of Var_s, Var_s{2,:}, associating to them the names in the first
%//row of the Var_s, Var_s{1,:}, in a .mat file
%//But let's imagine that instead of having size(Var_s{2,:})=3 I would have
%//something like 1000 (but lets keep it simple for now having just 3).
%//Consequently I want to use a 'for' to do this work!
%//And it is at this point that the issue appears. How can I use the strings
%//inside Var_s{1,:} to create variables and store them in the .mat file with
%//the values in the cells of Var_s{2,:} associated to them?
filename='Clima';
a=0;
save(filename,'a'); %//Creats the file with a variable a=0
for i=1:length(Var_s(2,:))
genvarname(Var_s{1,i})=Var_s{2,i}; %//The idea is to create a variable using a stringn and associate the values
save(filename,char(Var_s{1,i}),'-append'); %//The idea is to add the created variable that has the same name in Var_s{1,i}
end
clearvars
%//After all this I could access the variables that are stored in 'Clima.mat'
%//by their name such as
load('Clima.mat')
Rn
LE
O
And the result must be
Rn = 11 22 33 44
LE = 1 2 3
N = 101 102 103 104 105
Your question is pretty much fully covered in the docs to the save() command under "Save Structure Fields as Individual Variables". To get there, you only must create that struct.
To create that struct(), where you dynamically create its field names, not much of your code must be changed. Once your struct is created in that loop, just save the struct once after the loop with the option '-struct', which automatically then generates a new variable for each field in that struct.
s = struct();
for i=1:length(Var_s(2,:))
s.(Var_s{1,i})=Var_s{2,i}; % struct with dynamic field names
end
save(filename, '-struct', 's');
Now let's see, what we stored:
whos('-file', 'Clima.mat')
Name Size Bytes Class Attributes
LE 1x3 24 double
O 1x10 80 double
Rn 1x4 32 double
As you can see, we stored 3 variables in that file.