"IF" with conditions across multiple columns in Excel - excel

My dataset looks like this:
I am looking for a formula to add to the column "Status" to do the following:
If Name = "A" and Project = "TT" and Number > 5, write "PASS" otherwise write "FAIL"
If Name = "A" and Project = "NN" and Number > 10, write "PASS" otherwise write "FAIL"
If Name = "B" and Project = "TT" and Number > 20, write "PASS" otherwise write "FAIL"
I struggle puting together something that works with "IF" and "OR".
Would anyone be able to offer a simple solution?

Breaking this into parts:
AND(A2="A",B2="TT",C2>5)
AND(A2="A",B2="NN",C2>10)
AND(A2="B",B2="TT",C2>20)
Then using OR:
=IF(OR(AND(A2="A",B2="TT",C2>5),AND(A2="A",B2="NN",C2>10),AND(A2="B",B2="TT",C2>20)),"PASS","FAIL")

Related

How to make custom references in an Excel row with specific rules ? with VBA or Excel formula

I Want to customise automatically in Excel a Reference number according to the content of the line it is representing.
I have a table for test procedure that looks like this :
Ref
Action
Check
A 001
Name of the Action to perform
Empty if it is an Action
C 001
Empty if it is a Check
Name of the Check to perform
C 002
Empty if it is a Check
Name of the Check to perform
C 003
Empty if it is a Check
Name of the Check to perform
A 002
Name of the Action to perform
Empty if it is an Action
The logic would be the following:
To iterate separately references starting with A and the ones starting with C depending on the type of procedure, that is to say whether the name of the procedure is in Action Column or Check Column.
I would like to implement an algorithm like this, or a formula that does the same thing :
For line in TABLE1 :
if ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Action = Ref_Action + 1
Ref_Code = "A" + Ref_Action
elif ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Check = Ref_Check + 1
Ref_Code = "C"+ Ref_Check
else raise error : "a procedure shall be either an action or a Procedure"
TABLE1[line,Ref] = Ref_Code
(It is not a code language, just my way of representing the algorithm, I hope it is readable.)
Unfortunately, I have no experience in VBA and I couldn't find a way to write an appropriate formula. Or maybe there is another way ?
Thank you,
Gautier

Getting Token Eof Expected when using a IF function with Text.Contains

Hello I am getting a 'Token Eof Expected' Error when trying to use a nested if statement with Text.Contains function.
if Text.Contains([Status],"A") then "A"
else
Text.Contains([Status],"B") then "B"
else
"C"
So here I am trying to get 'A' if 'A' is present, then 'B' id 'B' is present or 'C' for anything else in the string. Here 'Status' is my list/column.
PowerQuery is highlighting the second then as the problem.
On the other hand the below code works perfectly.
if Text.Contains([Status],"A") then "A"
else "B"
I was able to go around this problem by using 3 additional steps.
1st Step
if Text.Contains([Status],"A") then "A" else null
Outputs a column with name 'Status1'
2nd Step
if Text.Contains([Status],"B") then "B" else "C"
Outputs a column with name 'Status2'
3rd Step
if [Status1] = null then [Status2] else [Status1]
It gets the job done but it is not elegant.
Any help is appreciated.
Thanks
Except for the final condition, you need to repeat if after else:
if Text.Contains([Status], "A") then
"A"
else if Text.Contains([Status], "B") then
"B"
else
"C"

How to turn multiple rows corresponding with one ID into single row - Presto

I'm looking the way to convert the data below
"itemid" "attr_id" "Merk" "Berat" "Panjang" "BPOM" "TInggi" "Kadaluarsa"
3624918424 14718 "Hansaplast" "" "" "" "" ""
3624918424 22229 "" "" "" "" "" "24 Bulan"
into this one
itemid Merk Berat Panjang BPOM TInggi Kadaluarsa
3624918424 Hansaplast 24 Bulan
I have checked another questions in SO, the most popular answer is by using PIVOT function. but that function didnt exist in presto. can someone have solution using presto?
I think you can just work with GROUP BY clause to get the desired result:
SELECT itemid
,MAX(Merk) Merk
,MAX(Berat) Berat
,MAX(Panjang) Panjang
,MAX(BPOM) BPOM
,MAX(TInggi) TInggi
,MAX(Kadaluarsa) Kadaluarsa
from data_table
GROUP BY itemid
It's not clear in your example if the columns are NULL or have an empty string '' - with an empty string it might be a bit more complicated and you need something like for all columns:
,MAX(case when Merk='' then NULL else Merk end) Merk
If you have multiple entries per itemid and you want to keep all entries you can also work with array_agg:
array_agg(x) → array<[same as input]>
Returns an array created from the input x elements.

Count specified character from field(s) in excel

I have an excel sheet that recorded data like following:
_____|__A__|__B__
__1__|__x__|_____
__2__|__x__|_____
__3__|__y__|_____
__4__|__x__|_____
__5__|__x__|_____
__6__|__y__|_____
__7__|__x__|_____
__8__|__ __|_____
__9__|__x__|_____
_10__|__y__|_____
_11__|__ __|_____
_12__|__x__|_____
I would like to count all field contained 'y' and ' ' from A1 to A12. Here's what I did for now:
=COUNTIF(A1:A12, "y") + COUNTIF(A1:A12, "")
It will become longer if I count more specified character...
Would you suggest any better way ?
You can use this shorthand to achieve your result
=SUM(COUNTIF(A1:A12,{"y",""}))
This is exactly the same as
=COUNTIF(A1:A12, "y") + COUNTIF(A1:A12, "")
The shorthand allows you to easily add more characters you want to count.
You can read more about this here:
https://excelxor.com/2014/09/28/countifs-multiple-or-criteria-for-one-or-two-criteria_ranges/

Converting Excel functions into R

I have two excel functions that I am trying to convert into R:
numberShares
=IF(AND(N213="BOH",N212="BOH")=TRUE,P212,IF(AND(N213="BOH",N212="Sell")=TRUE,ROUNDDOWN(Q212/C213,0),0))
marketValue
=IF(AND(N212="BOH",N213="BOH")=TRUE,C213*P212,IF(AND(N212="Sell",N213="Sell")=TRUE,Q212,IF(AND(N212="BOH",N213="Sell")=TRUE,P212*C213,IF(AND(N212="Sell",N213="BOH")=TRUE,Q212))))
The cells that are referenced include:
c = closing price of a stock
n = position values of either "buy or hold" or "sell"
p = number of Shares
q = market value, assuming $10,000 initial equity (number of shares*closing price)
and the tops of the two output columns that i am trying to recreate look like this:
output
So far, in R I have constructed a dataframe with the necessary four columns:
data.frame
I just don't know how to write the functions that will populate the number of shares and market value columns. For loops? ifelse?
Again, thank you!!
Covert the AND()'s to infix "&"; the "=" to "=="; and the IF's to ifelse() and you are halfway there. The problem will be in converting your cell references to array or matrix references, and for that task we would have needed a better description of the data layout:
numberShares <-
ifelse( N213=="BOH" & N212=="BOH",
#Perhaps PosVal[213] == "BOH" & PosVal[212] == "BOH"
# ... and very possibly the 213 should be 213:240 and the 212 should be 212:239
P212,
ifelse( N213=="BOH" & N212=="Sell" ,
round(Q212/C213, digits=0),
0))
(You seem to be returning incommensurate values which seems preeety questionable.) Assuming this is correct code despite my misgivings the next translation involves apply the same substitutions in this structure (although you seem to be missing an else-consequent in the last IF function:
marketValue <-
IF( AND(N212="BOH", N213="BOH")=TRUE,
C213*P212,
IF(AND(N212="Sell",N213="Sell")=TRUE,
Q212,
IF( AND(N212="BOH",N213="Sell")=TRUE,
P212*C213,
IF(AND(N212="Sell",N213="BOH")=TRUE,
Q212))))
(Your testing for AND( .,.)=TRUE is I believe unnecessary in Excel and certainly unnecessary in R.)

Resources