cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Valid expression for derive fields

SaranKarthick
16-Pearl

Valid expression for derive fields

Hi Developers,

 

I've an infotable where column 1 is a date time field and column two is a string field. Column 2 has the datetime value in string format and it also have null rows.

 

My requirement is to find difference between the two column values and show the difference in a new column. If there is null row in any one of the column then I need to set the diferrence as null.

 

For the above requirement i used the derive fields snippet in the following manner:

 

Step 1: Use NE filter to remove the null rows (Because with null rows the derive function doesnt seem to work. Tried if else block within the expression but doenst seem to work)


Step 2: Convert the coulmn 2 string value (in filtered infotable from step 1) to date time format using parse function and store it as column 3.

 

Step 3: Find date difference between column 1 and the coulmn 3. Store the difference in column 4.

 

Following are the questions i have about expressions in derive fields:

 

Question 1: Can we use if else block in expressions of the derive function. When i tried to capture the null character it didnt work.

 

Question 2: Can i do both parsing (the string to date time format) and date difference in one go instead of doing one by one.

 

If the actions mentioned in the above questions can be done, kindly provide me with an example or atleast the syntax to do the same.

 

Thanks and Regards,

Saran

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @SaranKarthick 

 

For Question 1, no you cannot use If else statement, you can only use expression, not statement.

See https://medium.com/launch-school/javascript-expressions-and-statements-4d32ac9c0e74 for some good example of expression vs statements.

 

Hope this helps

Christophe

 

View solution in original post

1 REPLY 1

Hi @SaranKarthick 

 

For Question 1, no you cannot use If else statement, you can only use expression, not statement.

See https://medium.com/launch-school/javascript-expressions-and-statements-4d32ac9c0e74 for some good example of expression vs statements.

 

Hope this helps

Christophe

 

Top Tags