INDEX MATCH with Nested IF Statements - excel

Here is my statement with just one IF Statement:
=IF(AF2="Consultant",IF(C2=INDEX(JIRA!F:F,MATCH('RFO Checks'!M2,JIRA!A:A,0)),1,0),"N/A")
This works great, but now I need to add two more IF Statements.
AF2 will either contain "Consultant", "Retailer", or "PC".
Each one will be directed to a different price column:
for "Consultant" it's JIRA!F:F
for "Retailer" it's JIRA!D:D
for "PC", it's JIRA!E:E.
I've been wracking my brain for two days now and haven't gotten no where.
Suggestions?
Thank you in advance!

Use CHOOSE()
=IFERROR(--(C2=INDEX(CHOOSE(MATCH(AF2,{"Consultant", "Retailer", "PC"},0),JIRA!F:F,JIRA!D:D,JIRA!E:E),MATCH('RFO Checks'!M2,JIRA!A:A,0))),"N/A")

Aaron,
I have provided you the high level structure for the change of logic.
If this is what you want, then you can substitute the phrases with the appropriate logic.
=IF(AF2="Consultant",
IF(C2=INDEX(JIRA!F:F,MATCH('RFO Checks'!M2,JIRA!A:A,0)),1,0),
IF(AF2="Retailer",
<insert_logic_for_retailer>,
IF(AF2="PC",<insert_logic_for_PC>,"N/A")
)
)
Logic for Consultant -
IF(C2=INDEX(JIRA!F:F,MATCH('RFO Checks'!M2,JIRA!A:A,0)),1,0)
Logic for Retailer, use this to replace -
IF(C2=INDEX(JIRA!D:D,MATCH('RFO Checks'!M2,JIRA!A:A,0)),1,0)
Logic for PC, use this to replace -
IF(C2=INDEX(JIRA!E:E,MATCH('RFO Checks'!M2,JIRA!A:A,0)),1,0)
Let me know in case you still have any issues!

Related

How to simplify 4 nested IF functions in EXCEL

This might be a simple fix I'm unsure. I have the following formula which I would like to be able to drag up and down =IF(C311>B311,IF(C310>B310,IF(B309>C309,IF(C312>B312,2,1),0),0),0)
I'm guessing AND can be implemented in some way but I'm not sure. The logic behind my goal is if C311>B311 AND C310>B310 AND B309>C309 then check to see if C312>B312 if it is then put a 2 else put a 1. Perhaps there is another solution as well I'm not thinking of.
Try this: =IF(AND(C311>B311,C310>B310,B309>C309),IF(C312>B312,2,1),"")
Last argument I left it as "" but replace it to whatever you need.
Just another approach-
=IF((C311>B311)*(C310>B310)*(B309>C309),IF(C312>B312,2,1),"")

How to correct an Excel formula error

=O27&" "&IF(D27<>"",VLOOKUP(D27,성취기준1반!$B$4:$C$19,2)&" ","")&IF(E27<>"",VLOOKUP(E27,성취기준1반!$E$4:$F$19,2)&" ","")&IF(F27<>"",VLOOKUP(F27,성취기준1반!$H$4:$I$19,2)&" ","")&IF(G27<>"",VLOOKUP(G27,성취기준1반!$K$4:$L$19,2)&" ","")&IF(H27<>"",VLOOKUP(H27,성취기준1반!$N$4:$O$33,2)&" ","")&IF(I27<>"",VLOOKUP(I27,성취기준1반!$Q$4:$R$33,2)&" ","")&IF(J27<>"",VLOOKUP(J27,성취기준1반!$T$4:$U$33,2)&" ","")&IF(K27<>"",VLOOKUP(K27,성취기준1반!$W$4:$X$33,2)&" ","")&IF(L27<>"",VLOOKUP(L27,성취기준1반!$Z$4:$AA$33,2)&" ","")&IF(M27<>"",VLOOKUP(M27,성취기준1반!$AC$4:$AD$19,2)&" ","")&P27
this is working code
=O28&" "&IF(D28<>"",VLOOKUP(D28,성취기준1반!$B$4:$C$19,2)&" ","")&IF(E28<>"",VLOOKUP(E28,성취기준1반!$E$4:$F$19,2)&" ","")&IF(F28<>"",VLOOKUP(F28,성취기준1반!$H$4:$I$19,2)&" ","")&IF(G28<>"",VLOOKUP(G28,성취기준1반!$K$4:$L$19,2)&" ","")&IF(H28<>"",VLOOKUP(H28,성취기준1반!$N$4:$O$33,2)&" ","")&IF(I28<>"",VLOOKUP(I28,성취기준1반!$Q$4:$R$33,2)&" ","")&IF(J28<>"",VLOOKUP(J28,성취기준1반!$T$4:$U$33,2)&" ","")&IF(K28<>"",VLOOKUP(K28,성취기준1반!$W$4:$X$33,2)&" ","")&IF(L28<>"",VLOOKUP(L28,성취기준1반!$Z$4:$AA$33,2)&" ","")&IF(M28<>"",VLOOKUP(M28,성취기준1반!$AC$4:$AD$19,2)&" ","")&P28
this is doesn't workin code.
Why doesn't it work?
This is not an answer in terms of a solution, but an answer in terms of the method you could employ to find and solve the issue. Mainly because you have not provided a working verifiable example, data or detail of the actual error.
First I would remove the vlookups and replace them with the expected results - if that then functions as it should then each of the vlookups needs to be tested, if not then check the detail of the function.
Appreciate if you can assist by explaining.. "why this doesn't work?" part. It is an error message or the the expected value is _ but I got _ instead.. (:
One thing I noticed is that you don't define what will be the outcome if D28 is "". If you don't define it, it'll return 'FALSE' value instead of a String/text.
In your IF() function, you only say IF(d28<>"",<DisplayValueFrom성취기준1반>) it should be IF(d28<>"",<DisplayValueFrom성취기준1반>,<DisplaySomeThingElse>)

Trying to write an IF ( Match ); possible syntax error?

Highly likely this is a syntax error, but it's not throwing any errors.
=IF(ISERROR(MATCH(MID(Z2,28,6),$AF$1:$AG1,0)),"Mismatch","Included")
I have Z2, Z2 contains the following text:
"Revenue account for invoice P13930."
Or something like that, so the Mid function is suppoused to match that code, P13930, and not if it is within the specified cells (Here, AF1 and AG1)
I tried copying the whole text, or even just the code to AF1 and AG1, but it never writes a match. What's wrong with it?
Based it on my prototype:
=IF(ISERROR(MATCH($AE1,$AF1:$AG$1,0)),"Mismatch","Included")
Which does happen to work.
EDIT: I forgot to mention, I was wondering how to include the following scenarios:
Sometimes the code would look like this: P13930. and other times like this: P13930A. I'm not sure how to consider these as my knowledge is limited to Mid , Left , and Right. And as Jordan Mentioned, MATCH would be out of the picture given these variations.
If AF1 and AG1 contain codes like P13930A, you can use a wild card to match them like this
=IF(ISERROR(MATCH(MID(Z2,29,6)&"*",$AF$1:$AG1,0)),"Mismatch","Included")
Could you please specify your question:
First which we can advice, is to correct mid function argument:
=IF(ISERROR(MATCH(MID(Z2,29,6),$AF$1:$AG1,0)),"Mismatch","Included")
MID(Z2,29,6) - will give you result P13930
and then you want to find this code in some area, don't you? for example in the area AF1:AG1.
Please specify the result which you want to see in the cell AF2:
(a) code P13930; (b) INCLUDED - if area AF1:AG1 includes code P13930; (c) MISMATCHED - if area AF1:AG1 does NOT include code P13930 and etc.

With data.table, return between certain characters into a new column

I have a feeling this might be a simple question, but I've searched through SO for a bit now and found many interesting related Q/A, I'm still stumped.
Here's what I need to learn (in honesty, I'm playing with the kaggle Titanic dataset, but I want to use data.table)...
Let's say you have the following data.table:
dt <- data.table(name=c("Johnston, Mr. Bob", "Stone, Mrs. Mary", "Hasberg, Mr. Jason"))
I want my output to be JUST the titles "Mr.", "Mrs.", and "Mr." -- heck we can leave out the period as well.
I've been playing around (all night) and discovered that using regular expressions might hold the answer, but I've only been able to get that to work on a single string, not with the whole data.table.
For example,
substr(dt$name[1], gregexpr(",.", dt$name[1]), gregexpr("[.]", dt$name[1]))
Returns:
[1] ", Mr."
Which is cool, and I can do some further processing to get rid of the ", " and ".", but, the optimist(/optimizer) in me feels that that's ugly, gross, and inefficent.
Besides, even if I wanted to settle on that, (it pains me to admit) I don't know how to apply that into the J of data.table....
So, how do I add a column to dt called "Title", that contains:
[1] "Mr"
[2] "Mrs"
[3] "Mr"
I firmly believe that if I'm able to use regular expressions to select and extract data within a data.table that I will probably use this 100x a day. So thank you in advance for helping me figure out this pivotal technique.
PS. I'm an excel refugee, in excel I would just do this:
=mid(data, find(", ", data), find(".", data))
Umm.. I may have figured it out:
dt[, Title:=sub(".*?, (.*?)[.].*", "\\1", name)]
But I'm going to leave this here in case anyone else needs help, or perhaps there's an even better way of doing this!
You can use the stringr package
library(stringr)
str_extract(dt$name, "M.+\\.")
[1] "Mr." "Mrs." "Mr."
Different variations on the regular expression will let you extract other titles, like Dr., Master, or Reverend which may also be of interest to you.
To get all characters between "," and "." (inclusive) you can use
str_extract(dt$name, ",.+\\.")
and then remove the first and last characters of the result with str_sub (also from stringr package).
But as I think about it more, I might use grepl to create indicator variables for all the different titles that are in the Titanic dataset. For example
dr_ind <- grepl("Dr|Doctor", dt$name)
titled_ind <- grepl("Count|Countess|Baron", dt$name)
etc.

Cassandra comments data model

I am trying to store very simple comments in a wide row, but the problem is that i want to have top comments.
So at first I have tried to use UTF8 comparator type and each column name would begin by likes amount and would be followed by timestamp, for example:
Comments_CF = {
parent:{
8_timestamp: comment,
5_timestamp: comment,
1_timestamp: comment,
...
}
...
}
The problem with this approach is that for example 2_timestamp > 19_timestamp because lexicographically 2 is bigger than 19
I could probably store top comments in a separate CF but then i would need to do two queries instead of one so i would really like to avoid that, any suggestions?
2 queries instead of one is usually not a big deal. You could also just do a composite value(number of likes+the comment) and sort the comments yourself....From stuff I have seen there is never alot of comments except a few posts anyways so that would be very quick.
There are other patterns that might spark ideas here as well...
https://github.com/deanhiller/playorm/wiki/Patterns-Page
Use a composite, where the first component is a long and the second is whatever type is appropriate for your timestamp format. This way the sorting will be correct.

Resources