Six Stars

Talend calculation


How to get the actual value from the cummulative value in talend ? for example On a paricular a car runs for 1000 kms next day the car will start from 1001 kms ,So what i need is how to calculate the total kms covered on a particular day

1000kms on 27-10-2017 2000kms on 28-10-2017

so the total kms covered on 28-10-2017 is 1000kms how to do that in talend for which i need to update around 1 lakh history records using the above method and this needs to be done in mongodb

6 ACCEPTED SOLUTIONS

Accepted Solutions
Twelve Stars

Re: Talend calculation

Assuming your data looks similar to this.....

 

Day       Total Miles
1            100
2             150

3             175

4             230
5             301

.....and you want to get the values.....

1 = 100
2= 50
3 = 25
4 = 55

5 = 71

 

....you can do it with a tMap. I have done this to demonstrate. The screenshot of the tMap is below....

distance.png

 

The tMap variables (the box in the middle) must be set up exactly as above. The expressions are....


todaysDistance

Var.lastDistance!=null ? row1.miles - Var.lastDistance : row1.miles 

lastDistance

row1.miles 

The trick here is that the tMap variables keep their values between rows and are processed in order.

Your dates must come in in order for this.

Rilhia Solutions
Six Stars

Re: Talend calculation

Hi ,
i am not getting the solution you gave .Can you please elaborate on this whether i need to use tmemorizerow for memorising the previous value or something like that ?
Twelve Stars

Re: Talend calculation

If you are using Talend 6 you should be using java 8.

 

int is a primitive type. This means that your tick boxes next to your variable config are not ticked. The "Nullable" tick box means they become Integer objects instead of int types.

Rilhia Solutions
Twelve Stars

Re: Talend calculation

Not if you are following the example I gave you. Can you take a screenshot of what you have?

Rilhia Solutions
Six Stars

Re: Talend calculation

11569|1
27752|1
27797|1

 

this is the output i am getting instead of the expected one.

The expression used are as follows

Var.lastDistance!=null ? row1.distance - Var.lastDistance : row1.distance  for today distance 

row1.distance  for last distance

Please tell me what is the issue

 

Twelve Stars

Re: Talend calculation

I need a screenshot of your tMap config

Rilhia Solutions
11 REPLIES
Twelve Stars

Re: Talend calculation

Assuming your data looks similar to this.....

 

Day       Total Miles
1            100
2             150

3             175

4             230
5             301

.....and you want to get the values.....

1 = 100
2= 50
3 = 25
4 = 55

5 = 71

 

....you can do it with a tMap. I have done this to demonstrate. The screenshot of the tMap is below....

distance.png

 

The tMap variables (the box in the middle) must be set up exactly as above. The expressions are....


todaysDistance

Var.lastDistance!=null ? row1.miles - Var.lastDistance : row1.miles 

lastDistance

row1.miles 

The trick here is that the tMap variables keep their values between rows and are processed in order.

Your dates must come in in order for this.

Rilhia Solutions
Six Stars

Re: Talend calculation

Hi ,
i am not getting the solution you gave .Can you please elaborate on this whether i need to use tmemorizerow for memorising the previous value or something like that ?
Six Stars

Re: Talend calculation

I need to calculate based on the customer id how to include that condition in tmap

Twelve Stars

Re: Talend calculation

You do not need to use tMemorizeRow. This configuration will work without that.

 

To do this via CustomerId, you will need to sort your data by CustomerID and date first (tSortRow), then have some logic to decide when your CustomerId switches. You can do this using the tMap variables as well. However this is a different question and I have thrown away my example.

 

Accept this as the solution (if it shows the distance between days, forgetting the CustomerID) and raise the CustomerID changing as a different question. There should only be one question per  post.


Rilhia Solutions
Six Stars

Re: Talend calculation

The operator != is undefined for the argument type(s) int, null
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio. Is the error i am getting

 

Six Stars

Re: Talend calculation

The operator != is undefined for the argument type(s) int, null
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio. Is the error i am getting
  the source data type is integer
Six Stars

Re: Talend calculation

i am getting the cummulative value not the subtracted one
Twelve Stars

Re: Talend calculation

If you are using Talend 6 you should be using java 8.

 

int is a primitive type. This means that your tick boxes next to your variable config are not ticked. The "Nullable" tick box means they become Integer objects instead of int types.

Rilhia Solutions
Twelve Stars

Re: Talend calculation

Not if you are following the example I gave you. Can you take a screenshot of what you have?

Rilhia Solutions
Six Stars

Re: Talend calculation

11569|1
27752|1
27797|1

 

this is the output i am getting instead of the expected one.

The expression used are as follows

Var.lastDistance!=null ? row1.distance - Var.lastDistance : row1.distance  for today distance 

row1.distance  for last distance

Please tell me what is the issue

 

Twelve Stars

Re: Talend calculation

I need a screenshot of your tMap config

Rilhia Solutions