msaiz
June 26, 2022, 7:22pm
1
Hello everybody, I am trying to apply a calculation based on a value from a column, by example
Ap01:
Item unit Qtyinunit
xxxx TS 2
xxx1 EA 1000
…
The calculation that I need to do is:
if unit = “TS”
then $(Qtyinunit)*1000
else $(Qtyinunit)*1
problem is, that in new column it appears the calculation as string (21000) or (1000 1) [not evaluated]
Ap02:
I had done in another way, but takes more transformations:
(column name: Qt01)
if unit = TS
then $(Qtyinunit)
else 0
(column name: Qt02)
if unit not equal TS
then $(Qtyinunit)
else 0
(column name: Qt001
calculate
Qt01 * 1000
(column name: QTF)
calculate
QT001 + Qt02
If the first approach, Ap01, had worked, simplicity was welcomed (I really do not understand why expression was not evaluated…)
Thanks in advance
Miguel
Admin
June 26, 2022, 8:33pm
2
Hi Miguel
The If transform doesn’t accept an expression, just a value. So you just need 2 steps to make this work.
Or you could do it in one transform using the Javascript transform.
2 Likes
msaiz
June 26, 2022, 9:46pm
3
Thanks, it works for me (it is shorter that second approach!),
Regards,
Miguel
1 Like
msaiz
June 27, 2022, 1:40am
4
About JavaScript, I had tried to code a solution, but my knowledge in the language is limited (I used to be a Pascal coder, Basic, and FORTRAN [yes, long time ago]). Could you recommend me a good tutorial in JavaScript just to use to extend some transformations, please?
Hi,
The simplest is done by using the JavaScript transform as follows
Hope this helps
1 Like
Admin
June 27, 2022, 7:25am
6
This is the Javascript equivalent:
The documentation has some examples:
And there are loads of resouces online for learning Javascript. For example:JavaScript Tutorial
But I would recommend sticking with Easy Data Transform standard transforms where possible and only using JS if there is no other way to do it.
msaiz
June 28, 2022, 2:27pm
7
Thanks! I am eager to apply JavaScript!
msaiz
June 28, 2022, 2:29pm
8
Yes, I know that using JavaScript have some performance issues
Admin
June 28, 2022, 4:01pm
9
The Javascript transform is still plenty fast enough for most purposes. Also if you can replace several transforms with 1 Javascript transform, then less memory is required. But I would still other ‘native’ transforms where possible.