<< Click to Display Table of Contents >>

Navigation:  Reference > Transforms >



Create a custom transform using Javascript (ECMAScript).


Easy Data Transform allows you to carry out a wide range of data transformations without programming. But sometimes you might need a specialist transformation that can't be done with the built-in transforms. For that you can use the Javascript transform. It allows you to write the body of a Javascript function, to calculate a value for each row in a new column. Existing column values can be used as variables.


Javascript is a fully-fledged programming language and can perform arbitrarily complex transforms. It can handle strings, numbers, dates and text.



Multiply the value in column 'items' by the value in column 'item price':


how to use Javascript for a custom transform example


To concatenate 'last' and 'first' columns with a comma and a space:


return $(last) + ', ' + $(first);


To calculate the biggest of numeric columns 'v1' and 'v2':


return Math.max( $(v1), $(v2) );


To find the number of characters in column 'v1':


return String( $(v1) ).length;


To determine whether phone numbers in the 'phone_num' column are valid using a regular expression:


const validPhoneNum = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/;

if ( validPhoneNum.test( $(phone_num) ) )

  return "valid";


  return "invalid";


To replace the last comma in the 'Location' column with a ';' using a regular expression:


return $(Location).replace(/(.*),([^ ]*)$/, '$1;$2');


To calculate the number of years difference between Javascript compatible dates in column 1 and column 2:


return new Date( $(1) ).getFullYear() - new Date( $(2) ).getFullYear();


To calculate the number of milliseconds between a datetime in the 'datetime' column and 1st Jan 2000:


return new Date( $(date) ) - new Date( "2000-01-01T00:00" );


To calculate the number of whole days difference between a date in the 'created' column and today (negative for future dates):


return Math.floor( ( new Date() - new Date( $(created) ) ) / ( 1000*60*60*24 ) );


To use the value of the 'n' column if it is a number and 0 if it isn't:


if ( isNaN( $(n) ) )

  return 0;


  return $(n);


To reverse the text in the 'key' column:


var a = $(key);

var newString = "";

for (var i = a.length - 1; i >= 0; i--) {

  newString += a[i];


return newString;


To convert meters to feet using a function:


function metersToFeet( x )


  return 3.28084 * x;


return metersToFeet( $(meters) );






Set New column name to the name of the new column you want to create.

Set Type column as to:

oNumber/Boolean/String to pass:

A column that is numeric values as Javascript Number type.

A column that is true and false values as Javascript Boolean type.

Anything else as Javascript String type.

oString to pass data all columns with Javascript String type.

Enter your script into the Javascript field. The script should be the body of a Javascript function.

Select a column from Insert variable to add that column variable into the Javascript field at the current cursor position.

Click the Evaluate button to evaluate your Javascript expression over every row and show any errors (only available if Run>Auto Run is checked).



The Javascript transform is calculated every time:

oThe Evaluate button is pressed.

oThe Javascript transform item is unselected in the Center pane and script changes have been made without the Evaluate button being clicked.

oAn item upstream of it changes.

An empty string is passed as an empty Javascript string variable (""), not null. To test if the 'v' column has a blank or empty value:


if ( $(v).length === 0 )


  // empty cell


else if ( String( $(v) ).trim().length === 0 )


  // blank cell



Numeric values should use dot ('.') as the decimal separator and have no group separator. E.g. 1234.5 is valid, but 1,234.5 and 1.234,5 are not, regardless of the locale. You can use the Num Format and Replace transforms to put numeric data in the correct format before processing a Javascript transform.

The new column is added at the right end. You can change the column order with Reorder Cols and the column name with Rename Cols.

The Javascript Date() object evaluates to the number of milliseconds since 1 January 1970 UTC.

Date values passed to Javascript Date() objects should be in ISO ('yyyy-mm-dd') format, e.g. '2020-01-31' (not '2020-1-31').

If you want to carry out your transform across more than one dataset, you should merge them first, e.g. using Join.

The Javascript transform is very versatile and quite fast. But is not as fast as built-in transforms. So we recommend you use built-in transforms where possible.

Javascript running in Easy Data Transform is not 'sandboxed' and has the same privileges as the Easy Data Transform executable. However the Javascript does not have access to window(), XMLHttpRequest() or ActiveXObject(). So we aren't aware of any way that a bad actor could damage your system from Javascript sent in a .transform file.

Javascript is far too big a topic to cover here. However there are many detailed resources online. If you are stuck contact support.

If you only want to combine text from columns, use the simpler Substitute transform.

Warnings are shown in the Warnings tab for:

oJavascript syntax errors

oAmbiguous column references

For simple arithmetic operations on numbers and dates use the Calculate transform.


See also

Find the difference between dates/datetimes