Open Refine IF statement - if-statement

I have a question about Open Refine's IF statement GREL. I have two columns, one is "Address" and the other is "House Code". I'd like to create an If-Then statement that would say something like:
IF("Address", "Building D", 1004)
So, if the address is "Building D", the second column "House Code" would return 1004. While I know that this is very easy to accomplish in Excel, I haven't found the correct GREL equation yet...
I would appreciate any help...

The logic of an if in OpenRefine is about the same as in Excel: if(condition, what to do if the condition is true, what to do if the condition is false).
In your case you could create the column "House code" with this Grel formula:
if(value=="Building C", "1004", null)
As a reminder, value is a variable that refers to the contents of each cell in your column.
Demo :
If the "House code" column already exists, you can transform it with this formula :
if(cells.Adress.value=="Building C", "1004", null)
Demo :

Related

How to extract a column based on it's content in PowerBI

I have a column in my table which looks like below.
ResourceIdentifier
------------------
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716
arn:aws:glue:us-east-1:5XXXXXX85:devEndpoint/etl-endpoint
i-075656565f7fea3
i-02c3434343f22
qa-271111145-us-east-1-raw
prod-95756565631-us-east-1-raw
prod-957454551631-us-east-1-isin-repository
i-02XXXXXXf0
I want a new column called 'Trimmed Resource Identifier' which looks at ResourceIdentifier and if the value starts with "arn", then returns value after last "/", else returns the whole string.
For eg.
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716  ---> i-09TYTYTY797168
i-02XXXXXXf0 --> i-02XXXXXXf0
How do I do this ? I tried creating a new column called "first 3 letters" by extracting first 3 letters of the ResourceIdentifier column but I am getting stuck at the step of adding conditional column. Please see the image below.
Is there a way I can do all of this in one step using DAX instead of creating a new intermediate column ?
Many Thanks
The GUI is too simple to do exactly what you want but go ahead and use it to create the next step, which we can then modify to work properly.
Filling out the GUI like this
will produce a line of code that looks like this (turn on the Formula Bar under the View tab in the query editor if you don't see this formula).
= Table.AddColumn(#"Name of Previous Step Here", "Custom",
each if Text.StartsWith([ResourceIdentifier], "arn") then "output" else [ResourceIdentifier])
The first three letters bit is already handled with the operator I chose, so all that remains is to change the "output" placeholder to what we actually want. There's a handy Text.AfterDelimiter function we can use for this.
Text.AfterDelimiter([ResourceIdentifier], "/", {0, RelativePosition.FromEnd})
This tells it to take the text after the first / (starting from the end). Replace "output" with this expression and you should be good to go.

IF AND Formula with IS NOT NULL in Excel

I am using Excel 2010 and currently trying to get a formula for my data using a Nested If And, but unable of the correct formula.
Here is some sample data to elaborate on my point:
(A1) Received Date (B1) DueDate
(A2) 7/1/2016 (B2) 7/8/2016
(A3) 7/1/2016 (B3) 6/29/2016
(A4) 7/1/2016 (B4) NULL
Basically, I want to create a formula that satisfies the following conditions. If Received Date < DueDate AND DueDate IS NOT NULL...then "YES", else "NO". So in this sample code above, only the first record should return "YES" and the other two should return "NO."
How do I do about a formula doing this?
I don't know how to do the second condition, the IS NOT NULL part. I put the cell numbers in parenthesis to simulate the table. (Hope that helps.)
Excel does not have a function to test for null. You can use IsBlank() to check for a blank cell or you can use IsNumber() to check for a numeric value. So, in your case something like
=if(and(isnumber(B2),A2<B2),"something","else")
Edit: If you want to check for the text "Null", then
=if(and(B2<>"Null",A2<B2),"something","else")
= is the "equals" comparison operator. "Not equals" is done with the <> comparison operator. Or you could do Not(B2="Null") but that's a bit too curly.
Another edit: FWIW, the first formula should still work, regardless of the cell containing text or being blank. As soon as the cell contains a date (which is a numeric value), the condition will be TRUE. So you can use that formula as well.
=IF(AND(B2<>"NULL",A2<B2),"YES","NO")

combining IF, AND, OR expressions in Google Sheets

I have written the following function in google sheets in order to add "ID" to a column:
=if(and(E2>43%, E2<57%, C2=2016), "ID", " ")
I would like to add another logical operator, OR, to this. I would like to add "ID" if the following conditions are met, OR if the conditions above are met:
E2 >57%, C2=2016, J2=""
Column J has names written in it. What I'm trying to say with J2="" is that the space is not blank. I don't care about what the name is, just that there is text written. I wrote this but it doesn't work:
=if(or(and(E2>43%, E2<57%, C2=2016),AND(E2>57%, C2=2016, J2=""), "ID", " "))
Thanks for your help!
Try this one:
=IF(or(and(B1>43%, B1<57%, A1=2016),and(B1 >57%, A1=2016,istext(E1))), "ID",)

Comparing two values for equality using Regex

I have the following set of data :
(Name=[Jane Doe]>[Jane Doe]),
(Job=[Temporary Employee]>[Full Time]),
(Address=[1 place]>[2 St.]),
(Title=[Account Manager]>[Account Manager])
I am trying to find out which name-value pairs have been modified. For example,
While Name value stayed the same "Jane Doe" to "Jane Doe", Job's value was changed from "temporary employee" to "full time", Address' value was changed from "1 place" to "2 St.". Finally, title value remained the same.
All the comparisons will be done for values in [..] > [..]. I will also need what was changed, name, job, title and address.
Any help will be appreciated. Thanks
EDIT : Not sure why this was down voted. It is still a regex question where one needs to extract name, from-value and to-value pairs. Comparison will be done afterwards.
You can only match the keys and values - regex will not compare them for you:
\(([^=]+)=\[([^]]+)\]>\[([^]]+)\]\)
demo

Searching column with string for wildcard match

I can't seem to figure out the VLOOKUP magic needed to make this work as I want it to.
See, what I've got is a column B containing filenames, like this:
[COLUMN B]
./11001 Boogie Oogie Oogie (A Taste Of Honey).wav
./11001 Rescue Me (A Taste Of Honey).wav
./11001 Sukiyaki (A Taste Of Honey).wav
./11002 Memory (Acker Bilk).wav
./11002 Stuck On You (Acker Bilk).wav
./11002 Could I Have This Dance (Acker Bilk).wav
./11002 Do That To Me One More Time (Acker Bilk).wav
./11002 This Masquerade (Acker Bilk).wav
./11002 Just Once (Acker Bilk).wav
And so on for 6220 entries.
I have another column, Column E, which contains a TRACK NAME which is present within the filename. Looks like this:
American Patrol
Artistry In Rhythm
Begin The Beguine
Big John's Special
Cherokee
For example. So what I want to do is, in another column I want to search through Column B using the strings from Column E and then returning the matched string from Column B.
So if we imagine I put this formula in the C Column starting in the same row as the American Patrol track name, it would search through the range in Column B and return this:
./11249 American Patrol (BBC Big Band).wav
./11249 Artistry In Rhythm (BBC Big Band).wav
./11249 Begin The Beguine (BBC Big Band).wav
And so on.
I tried doing this formula
=VLOOKUP(E2;B2:B6235;2;TRUE)
So, this returns a file name, but it seems to have matched all the filenames and are just returning whichever result I specify in the col_index variable, so now it returns the second match (basically, just the second row in Column B) and if I put a 3 instead, it would just return the third hit, again having matched all the file names, it seems..
I'm not that familiar with Excel functions, so I'm not sure where to look for the solution beyond this.
You should not be using TRUE as a VLOOKUP function's range_lookup parameter on unsorted data. You can, however, wrap your track title in wildcards to achieve the search you are looking for.
      
The formula in C1 is,
=INDEX(B:B, MATCH("*"&E1&"*",B:B, 0))
... or,
=VLOOKUP("*"&E1&"*",B:B, 1, FALSE)
They accomplish the same thing.