Use Case statement to output value if Specific String + Value are present in row - spotfire

I will have thousands of rows with different combinations of the following in [COLUMN1]
I want to search each row and return a different output depending on the value of W123 if present
COLUMN1:
Row 1: W277(20000.0),W278(50000.0),W290(10000.0),W279(5000.0),W123(10000.0)
Row 2: W277(20000.0),W278(50000.0),W123(20000.0),W279(5000.0)
Row 3: W277(20000.0),W123(30000.0),W278(50000.0),W279(5000.0)
What I have tried:
case
When COLUMN1 ~= "W123(10" then "Pray"
When COLUMN1 ~= "W123(20" then "THIS"
When COLUMN1 ~= "W123(30" then "WORKS"
else "No W123"
end

You need to escape your characters:
case
When [COLUMN1]~="W123\\(10" then "Pray"
When [COLUMN1]~="W123\\(20" then "THIS"
When [COLUMN1]~="W123\\(30" then "WORKS"
else "No W123"
end
Returns this:

Related

Partial match between 2 column and output yes, no in another column

Trying to do a partial match between the two columns and generate Yes or No if they do have a partial match on the third column
So, for the names given, you'd expect three "Yes" answers - for Trelleborg and Moog?
You could try this: get the first word from column B, and see if it's present in column A.
To get the first word, find the first space.
=FIND(" ", #B:B)
Get that many letters (minus 1 for the space) from B:
=LEFT(#B:B,FIND(" ", #B:B)-1)
Find that word in column A. Use SEARCH not FIND for a case-insensitive search:
=SEARCH(LEFT(#B:B,FIND(" ", #B:B)-1),#A:A)
This will give a number or an error. Let's make that be FALSE or TRUE:
=ISERROR(SEARCH(LEFT(#B:B,FIND(" ", #B:B)-1),#A:A))
Finally let's turn that into "No" (is true, an error, no match found) or "Yes" (if false, not an error, match found)
=IF(ISERROR(SEARCH(LEFT(#B:B,FIND(" ", #B:B)-1),#A:A)),"No","Yes")

how to group data from a column into rows based on content

In Excel, I have a column of filenames. Each filename as a unique prefix and I would like to transpose all cells in the column with matching prefix into a unique row. There is not a fixed number of entries with matching prefixes, as I have seen a solution with that condition.
For example, I have data in a column like this:
col1
col2
col3
Apple_1
Apple_2
Apple_3
Boy_1
Cow_1
Cow_2
and I want to group and transpose it into rows like this:
col1
col2
col3
Apple_1
Apple_2
Apple_3
Boy_1
Cow_1
Cow_2
I think I can do it in VBA, but was hoping there is some way to do this without custom coding.
EDIT - Basically, this is what I need to do in a VBA macro:
FoundCnt = 0
CurrentCell = A1
Get the string of chars up until the _ and store in CurrentPrefix
Do {
NextCell = CurrentCell +1
Get the chars in NextCell up until the _
store in NextPrefix
If CurrentPrefix == NextPrefix {
move content of NextCell up 1 and to the right to B FoundCnt + 1
FoundCnt++
delete Row containing NextCell
} else {
FoundCnt = 0
}
CurrentCell = NextCell
} Until NextCell == ""
Plz try this - it isn't very different from the formula for converting a single column into a 2d range with a fixed number of columns, you just hang the output on a Sequence with number of rows equal to number of unique prefixes and number of columns equal to max number of entries sharing the same prefix. Then you have to check that the current output column is less than the number of entries matching the current prefix:
=LET(range,A2:INDEX(A:A,COUNTA(A:A)),
uniques,UNIQUE(LEFT(range,FIND("_",range))),
cols,MAX(COUNTIF(range,uniques&"*")),
seq,SEQUENCE(COUNTA(uniques),cols,0),
IF(MOD(seq,cols)<COUNTIF(range,uniques&"*"),INDEX(range,MATCH(INDEX(uniques,INT(seq/cols)+1)&"*",range,0)+MOD(seq,cols)),""))

How to get element index of a series

I have a dataframe with let's say 2 columns. Example below :
I want to match text from column "Text1" with values of column "Text2" and create a new column which says "matched" or "not matched" with position of column "Text2" where match found. Example shown below :
With my approach, I was able to do the match but I am not able to get the position of text in column "Text2" where the match is found. My approach is below :
df["Match?"] = df["Text1"].apply(lambda x: "matched" if x in df["Text2"].values else "not matched")
You can use np.where
data = """txt1,txt2
hello,that
hi,these
sure,sure
there,hello
"""
df["Match?"] = df["txt1"].apply(lambda x:
"Matched ,"+ str(*np.where(df["txt2"] == x)[0])
if np.where(df["txt2"] == x)[0].shape[0] != 0
else "Unmatched" )
Output:
txt1 txt2 Match?
0 hello that Matched ,3
1 hi these Unmatched
2 sure sure Matched ,2
3 there hello Unmatched

Excel: Combining semi-duplicated records (with different columns)?

How would I combine records if specified columns are the same?
Here's what I have, and the result I'm looking for:
It can be done using array formulas if you don't mind them being big and ugly. This example should do what you're looking for. In case of duplicate entries, it simply takes the last defined value (Prog instead of Programmer for Kevin Moss):
Enter the following formula into C11 and D11, then press CTRL+SHIFT+ENTER to apply the array formula. You can then copy the formula to the rows below as needed.
=INDEX((IF((((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,C$2:C$7,"")),MAX(IF((IF((((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,C$2:C$7,""))<>"",ROW($A$1:$A$6),0)))
This breaks down what's happening a little bit, but admittedly it's still pretty opaque, sorry:
=INDEX(
(IF( # This IF statement collects all entries in a data field for a given Fname/Lname combination
(((($A11=$A$2:$A$7) + ($B11=$B$2:$B$7))=2) + (C$2:C$7<>""))=2, # Checks that First and Last Name Match, and Data field isn't empty
C$2:C$7, # Return data field if TRUE
"" # Return empty if FALSE
)),
MAX( # Take the highest index number, use it to select a row from the result of the IF statement above
IF(( # This IF statement returns an index number if the data field isn't empty
IF( # This IF statement collects all entries in a data field for a given Fname/Lname combination (copied from above)
(((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,
C$2:C$7,
"")
)<>"", # End of conditional statement
ROW($A$1:$A$6), # Value if TRUE (ROW used as an incrementing counter)
0 # Value if FALSE (0 will be ignored in the MAX function that uses this result)
)
)
)

Locate a sub-string within a string Oracle

I am trying to locate a substring within a string. Everything I find on the net is locating its position. I don't care about the position and given the position on every row floats I cant say regexp_instr(X, 10, 5).
I am looking to say if X in Column String then give me a new column with only the string I asked for. If not Give me Y.
The issue is that 1 of 10 strings are within Column String and I am trying to extract them out in 1 to 2 steps as a separate column.
Can this be done?
Thanks.
maybe something like...
But I'm unclear if you want one column, multiple columns or if you want first result or all results that match...
So if column contains 'CAT' and you're looking for Z, C, A, T... What results should be in the resulting column? No Z... just C or CAT or what?
SELECT CASE WHEN INSTR('CAT','Z')>0 THEN 'Z'
WHEN INSTR('CAT','C')>0 THEN 'C'
WHEN INSTR('CAT','A')>0 THEN 'A'
WHEN INSTR('CAT','T')>0 THEN 'T'
ELSE 'Not in' end from dual;
To search a string for another string and return the searched for string when found or a fixed string if not found you have several options. The instr and regexp_instr methods rely on the fact that when not found they return an index of zero (0) while the regexp_substr method returns null when not found otherwise it returns the string that matches the search pattern:
with dta as (
select 'this is a test' str from dual union all
select 'every good boy does fine' from dual union all
select 'testing one two three' from dual
), fnd as (
select 'test' fnd, 'not found' fail from dual union all
select 'good' fnd, 'not good' fail from dual
)
select fnd
, str
, case instr(str, fnd) when 0 then fail else fnd end result
, case regexp_instr(str,fnd) when 0 then fail else fnd end result2
, nvl(regexp_substr(str, fnd), fail) result3
from dta, fnd
order by 1, 2;

Resources