How to create column based on null value from previous column to replace true and false with CN and LX - trifacta

Hi I'm trying to create a new column with two values only based on a criteria of null values i.e if state is null then CN if not null then LX
Tried IF clause but can't get it to put out the second input of LX

Related

Add new column to the existing table based on specific row value conditions

For the below table sample, I want to add and additional column lets say " Amount difference" and it should have value only if the successive rows of D column has "Success" and "Waiting" as value and A B and c column value matches exactly. IN such scenario the new coulmn F (Amount difference) should have (15-0) as the value and rest of the column values should be null. If the successive rows doenst have Waiting then the value of row 2 in New column should be 15 and rest all rows should be null.
A Id
B session Id
C customer Type
D ticket status
E Amount
ORDINAL
First
A
vip
Failed
10
0
First
B
ordinary
Success
15
1
First
B
ordinary
Waiting
0
2
How can this be achieved with a query please?

Python : How to create a new boolean column in my dataframe if the value of another column is in a list

I have a dataframe and I want to create a new column which take the value 1 if the value of an other column is in a list and 0 else. I try this but it did not work. Thank you

Reference another cell in the same row having calculated the minimum value in a datatable column

Using VB, I've used the following line to successfully find the minimum value in a specific column (say column 5, where the values are all of double) in a datatable:
Dim test as double
test = datatable.Compute("min(sourcecolumn)", "")
I would now like to refer to the values in other columns (let's say column 2) along the row containing that minimum column value.
Any help would be much appreciated as I can't get my head round it!
Thanks
You can use the DataTable.Select() method to get the row(s) that contain the minimum value. DataTable.Select() returns a DataRow(). In the code below, I assumed only one column contains the minimum value hence Data(0).
Dim test as double
test = datatable.Compute("min(sourcecolumn)", "")
Dim Data() As DataRow = datatable.Select("sourcecolumn = " & test.ToString())
Dim column2 = Data(0)(1)
All you have is a value but you currently have no idea what row(s) contain that value. You can use the table's Select method to get the row(s) that contain that value in that column. Once you have the row(s), you can do whatever you want with it/them:
Dim minValue = CDbl(myDataTable.Compute("MIN(MyColumn)", Nothing))
Dim rows = myDataTable.Select($"MyColumn = {minValue}")
For Each row In rows
'Use row here.
Next
Select always returns an array, even if there is only one row, so the loop will always work. If you know that there will never be more than one match, you can just get the first element directly.

Get integer data from word tables

I have several word tables that I want to edit based on the value in the last row of the column. I want to delete column contents (except last row of specified column) if the value in the last row exceeds 20.
I have used . Range. Textbut I am having challenges with its implementation. I have this
For i = 3 To . Columns. Count
If ActiveDocument.Tables(i).Cell(ActiveDocument. Tables(i).Rows.Count, i).Range.Text >20 Then ...
How can I get VBA to return the contents of a cell not as a string but as an integer for calculation.
VBA's VAL() function will convert a string containing a numeric value into a number. The function starts from the left and recognises numbers until a non-numeric character is encountered and ignores everything that follows. In the case of text taken from a table cell that is very useful because the End-Of-Cell marker included in the text will be ignored.
Dim C As Long
For C = 1 To 3
With ActiveDocument.Tables(1)
If Val(.Rows.Last.Cells(C).Range.Text) > 20 Then
Debug.Print "Delete rows above"
End If
End With
Next C

Converting lengthy Excel function to SQL?

IFERROR((SUMIFS('Sheet 1'!$K:$K,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0"))/(SUMIFS('Sheet 1'!$J:$J,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")),"")
I am working with the following function in Excel and need to interpret it into MS SQL. I am familiar with SQL, but extremely unfamiliar with excel. From what I understand the function is returning "" if error. otherwise it is calling SUMIF on the innermost parentheses - inside of which I am not sure what is going on, even after looking up what !, :, and $ do in Excel
Okay since I have no idea what you sheet is I can't help with the SQL but i will try and break down the function for you
#this part is for if the enclosed returns an error like #VALUE
#you can think of this as a try rescue block of sorts
#so if there is an Error then Return ""
IFERROR(
(
#This part is Summing All the values in Column K for multiple criteria
#Sum all the values in Column K ref ['Sheet 1'!$K:$K]
#Where all the values in Column A = Value in Cell I5 ref['Sheet 1'!$A:$A,'Sheet 2'!I$5]
#And Values in Column C = Value in Cell B15 ref [ 'Sheet 1'!$C:$C,'Sheet 2'!$B15]
#And the Values in Column K Do not = 0 ref ['Sheet 1'!$K:$K,"<>0"]
SUMIFS('Sheet 1'!$K:$K,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")
#Above Number Divided By
)/(
#This part is Summing All the values in Column J for multiple criteria
#Sum all the values in Column J ref ['Sheet 1'!$J:$J]
#Where all the values in Column A = Value in Cell I5 ref['Sheet 1'!$A:$A,'Sheet 2'!I$5]
#And Values in Column C = Value in Cell B15 ref [ 'Sheet 1'!$C:$C,'Sheet 2'!$B15]
#And the Values in Column K Do not = 0 ref ['Sheet 1'!$K:$K,"<>0"]
SUMIFS('Sheet 1'!$J:$J,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")
)
,"")
Here is the definition of SUMIFS. Quick Synopsis:
*First Argument is the Rows being Summed
*Second Argument is the Criteria Being Evaulated
*Third Argument is the Expression Being Evaluated Against
*Repeat Second and Third for all additional Criterium
Hacked SQL
SELECT Sum(Sheet1.ColumnK) / Sum(Sheet2.ColumnJ)
FROM Sheet1 JOIN Sheet2
WHERE
Sheet1.ColumnA = 10 --I Used 10 in place of Sheet2.ColumnI Row5 as this does not translate directly in SQL
AND Sheet1.ColumnC = 20 -- Same As Above Substitution for Sheet2.ColumnB Row 15
AND Sheet1.ColumnK <> 0
Hope this helps
SUMIFS() adds a range of cells based on one or more criteria applied to a range of cells.
First is the range of values to be summed up, then after that come pairs of criteria, first is the criteria range, then the criteria. The first one breaks down something like this:
SUMIFS('Sheet 1'!$K:$K -- Sum this field
,'Sheet 1'!$A:$A,'Sheet 2'!I$5 --When same row in A matches Sheet 2 I5
,'Sheet 1'!$C:$C,'Sheet 2'!$B15 --When same row in C matches Sheet 2 B, but 15 rows down.
,'Sheet 1'!$K:$K,"<>0") --When the values aren't 0
That's the numerator in your formula, you can break down the 2nd SUMIF() similarly.