How do I only show values that end in a specific characters? - spotfire

In Spotfire, I have a list of codes that are formatted like the following:
4530, 4510, 4550, 6000|1
4530, 4510, 4710|3|327, 6000|1
4530, 4510, 4800
4850, 4530, 4510, 6000|1
4530, 4516, 4520, 4720
4530, 4516, 4520, 4720|351
I would like for the data to only contain values that end in 6000|1.
How would I go about doing this in a custom expression?

you can use the following expression in a new calculated column:
If(Right([Column], 6) = "6000|1", "MATCH")
and then filter on your new column

Related

Insert a new column if value of previous column has some matching string

I want to perform a simple bash script. The requirement is as follows:
The data has the delimiter of csv (,)
The columns are inconsistent
I want to insert a column 'NA' if previous column data is 'login_success'
The data is as follows:
2022.01.26,00:37:08,login_success,BASIC_LOGIN,abc
2022.01.26,00:37:09,login_failed,User_not_authenticated,BASIC_LOGIN,
2022.01.26,00:37:09,login_success,TOKEN_LOGIN,xyz
2022.01.26,00:37:09,login_success,BASIC_LOGIN,123
2022.01.26,00:37:10,login_success,TOKEN_LOGIN,abc123
2022.01.26,00:37:11,login_success,BASIC_LOGIN,xyz123
2022.01.26,00:37:11,login_success,TOKEN_LOGIN,abc
2022.01.26,00:37:11,login_success,BASIC_LOGIN,xyz
2022.01.26,00:37:11,login_success,TOKEN_LOGIN,123
2022.01.26,00:37:12,login_success,BASIC_LOGIN,pqr
2022.01.26,00:37:13,login_failed,Token_does_not_exist,TOKEN_LOGIN,
2022.01.26,00:37:13,login_success,BASIC_LOGIN,abc123
2022.01.26,00:37:14,login_success,TOKEN_LOGIN,xyz123
2022.01.26,00:37:14,login_success,TOKEN_LOGIN,pqr123
Desired output:
2022.01.26,00:37:08,login_success,NA,BASIC_LOGIN,abc
2022.01.26,00:37:09,login_failed,User_not_authenticated,BASIC_LOGIN,
2022.01.26,00:37:09,login_success,NA,TOKEN_LOGIN,xyz
2022.01.26,00:37:09,login_success,NA,BASIC_LOGIN,123
2022.01.26,00:37:10,login_success,NA,TOKEN_LOGIN,abc123
2022.01.26,00:37:11,login_success,NA,BASIC_LOGIN,xyz123
2022.01.26,00:37:11,login_success,NA,TOKEN_LOGIN,abc
2022.01.26,00:37:11,login_success,NA,BASIC_LOGIN,xyz
2022.01.26,00:37:11,login_success,NA,TOKEN_LOGIN,123
2022.01.26,00:37:12,login_success,NA,BASIC_LOGIN,pqr
2022.01.26,00:37:13,login_failed,Token_does_not_exist,TOKEN_LOGIN,
2022.01.26,00:37:13,login_success,NA,BASIC_LOGIN,abc123
2022.01.26,00:37:14,login_success,NA,TOKEN_LOGIN,xyz123
2022.01.26,00:37:14,login_success,NA,TOKEN_LOGIN,pqr123
Something like this
sed 's/\(,login_success\),/\1,NA,/g' file.csv

How to split json data in PowerApps

How to split json data in PowerApps
I have a json format text
{"ID":"1","name":"yashpal"}
and I need to split the data and assign 1 to textbox1 and Yashpal to textbox2
Power Apps currently does not have a general JSON parsing mechanism, but if you know that the text you have will always have the same format, and the 'name' property cannot have double quotes ("), then you can use a regular expression to extract the values, something along the lines of
With(
Match(
<<the json text>>,
"\""ID\"":\""(?<id>[^\""]+)\"",\""name\"":\""(?<name>[^\""]+)\"""),
UpdateContext({defaultId: id, defaultName: name}))
And you can use the variables defaultId and defaultName as the Default property of 'textbox1' and 'textbox2', respectively.

Vim substitute string for same format string but different names

File looks like:
INSERT INTO x VALUES (48394, '9-10-2007', 19);
INSERT INTO x VALUES (99981, '3-5-2008', 45);
I would like to replace each line with:
INSERT INTO x VALUES (48394, STR_TO_DATE('9-10-2007', %d-%m-%y), 19);
INSERT INTO x VALUES (99981, STR_TO_DATE('3-5-2008', %d-%m-%y), 45);
I can't seem to find how to deal with changing string names to replace
:%s/<WHAT GOES HERE>/add in STR_TO_DATE(...)/
If your data is structured exactly like that with no other strings delimited by ' and the contents are always the date you want to convert, searching for simply '.*' will work:
:%s/'.*'/STR_TO_DATE(&, %d-%m-%y)
To be more specific, i.e. if other strings appear on the same line:
:%s/'\d*-\d*-\d*'/STR_TO_DATE(&, %d-%m-%y)
Here's an example of a solution:
:%s/\(INSERT INTO x VALUES (.*,\) '\(.*\)'\(.*\)/\1 STR_TO_DATE('\2', %d-%m-%y)\3/g
Relevant reading

Comparing Text boxes to be used in filtering data table c#

I want to compare two textboxes with data in a datatable and use this comparison operation to filter the datetable.
For example: I want to show all data (rows and columns) that have value x in which:
textbox1.text>x>textbox1.text
I have used "Like" operator inside string format to get the value that matches the value in the text-box completely but I could not do the required range filtering operation
Here is my code related to the specified question:
dv.RowFilter = string.Format("Type Like '%{0}%' and Gain Like" +
"'%{1}%'" +
"and Year Like'%{2}%' and MotorPower Like '%{3}%'" +
"and Profit Like '%{4}%'", textBoxType .Text,textBoxGain.Text
, textBoxYear.Text, textBoxBiggerthan.Text, textBoxKar.Text);
dataGridView1.DataSource = dv;
I have another input textbox called textBoxSmallerthan.Text
and I want to make my range for MotorPower column in datatable (datagridview) between textBoxBiggerthan.Text and textBoxSmallerthan.Text
The documentation here shows the numbers do not need be wrapped with single quote makers. So the format is:
Columnname < Number
So the final filter should be something like this:
dv.RowFilter = string.Format("Type Like '%{0}%' and Gain Like" +
"'%{1}%'" +
"and Year Like'%{2}%' and MotorPower > {3} and MotorPower < {4}" +
"and Profit Like '%{4}%'", textBoxType .Text,textBoxGain.Text
, textBoxYear.Text, textBoxSmallerthan.Text, textBoxBiggerthan.Text, textBoxKar.Text);
dataGridView1.DataSource = dv;

Excel wrongly converts ranges into dates, how to avoid it?

I have a .tsv file with some fields being ranges like 1 - 4. I want to read these fields as they are textually written. However, upon file opening excel converts automatically those range fields to dates. For instance 1 - 4 is converted to 4-Jan. If I try to format back the cell to another type, the value is already changed and I can only get a useless number (39816). Even if the range fields are within double quotes, the wrong conversion to date still takes place. How to avoid this behavior?
I think you best use the import facility in excel but you may have to manually change the file extension to a csv.
When importing be sure to select text for all the columns with these values.
My question is in fact a duplicate of at least:
1) Stop Excel from automatically converting certain text values to dates
2) Excel: Default to TEXT rather than GENERAL when opening a .csv file
The possible solutions for Excel are to 1) either writing the fields with special double quotes like "May 16, 2011" as "=""May 16, 2011""" or 2) importing the csv/tsv file with the external data wizard and then selecting manually which columns you want to read as TEXT and not GENERAL (which could convert fields to dates)
As for my use case, I was only using Excel to remove some columns. None of the solutions was appealing to me because I wouldn't like to rewrite the tsv files with special quotes and because I had hundreds of columns and I didn't want to select each manually to be read as TEXT.
Therefore I wrote a scala script to filter tsv files by column names:
package com.jmcejuela.ml
import java.io.InputStream
import java.io.Writer
import scala.io.Codec
import scala.io.Source
import Table._
/**
* Class to represent tables with a fixed size of columns. All rows have the same columns.
*/
class Table(val rows: Seq[Row]) {
lazy val numDiffColumns = rows.foldLeft(Set[Int]())((set, row) => set + row.size)
def toTSV(out: Writer) {
if (rows.isEmpty) out.write(TableEmpty.toString)
else {
out.write(writeLineTSV(rows.head.map(_.name))) //header
rows.foreach(r => out.write(writeLineTSV(r.map(_.value))))
out.close
}
}
/**
* Get a Table with only the given columns.
*/
def filterColumnsByName(columnNames: Set[String]): Table = {
val existingNames = rows.head.map(_.name).toSet
assert(columnNames.forall(n => existingNames.contains(n)), "You want to include column names that do not exist")
new Table(rows.map { row => row.filter(col => columnNames.contains(col.name)) })
}
}
object TableEmpty extends Table(Seq.empty) {
override def toString = "Table(Empty)"
}
object Table {
def apply(rows: Row*) = new Table(rows)
type Row = Array[Column]
/**
* Column representation. Note that each column has a name and a value. Since the class Table
* is a sequence of rows which are a size-fixed array of columns, the name field is redundant
* for Table. However, this column representation could be used in the future to support
* schemata-less tables.
*/
case class Column(name: String, value: String)
private def parseLineTSV(line: String) = line.split("\t")
private def writeLineTSV(line: Seq[String]) = line.mkString("", "\t", "\n")
/**
* It is assumed that the first row gives the names to the columns
*/
def fromTSV(in: InputStream)(implicit encoding: Codec = Codec.UTF8): Table = {
val linesIt = Source.fromInputStream(in).getLines
if (linesIt.isEmpty) TableEmpty
else {
val columnNames = parseLineTSV(linesIt.next)
val padding = {
//add padding of empty columns-fields to lines that do not include last fields because they are empty
def infinite[A](x: A): Stream[A] = x #:: infinite(x)
infinite("")
}
val rows = linesIt.map { line =>
((0 until columnNames.size).zip(parseLineTSV(line) ++: padding).map { case (index, field) => Column(columnNames(index), field) }).toArray
}.toStream
new Table(rows)
}
}
}
Write 01-04 instead of 1-4 in excel..
I had a "text" formatted cell in excel being populated with a chemical casn with the value "8013-07-8" that was being reformatted into a date format. To remedy the problem, I concatenated a single quote to the beginning of the value and it rendered correctly when viewing the results. When you click on the cell, you see the prefixed single-quote, but at least I stopped seeing it as a date.
In my case, When I typed 5-14 in my D2 excel cell, is coverts to date 14 May. With a help from somebody , I was able to change the date format to the number range (5-14) using the following approach and wanted to share it with you. (I will use my case an example).
Using cell format in excel, I converted the date format in D2 (14 May) to number first ( in my case it gave me 43599).
then used the formula below ,in excel, to convert it 5-14.
=IF (EXACT (D2, 43599), "5-14", D2).

Resources