Solved

Simple calculation and write in subsequent feature


Badge +4

Hi,

I have a little calculation problem:

I want to @sub(A1,B1) and write the result (72) at A2. Next step A2-B2 (72-18)--> result (54) at A3... and so on. The dataset must be flexible, because the input is not only 3 rows long.

Thank you for your help!

icon

Best answer by oscard 9 July 2019, 15:26

View original

7 replies

Userlevel 2
Badge +19

Add an AttributeManager to your workspace after the Reader.

In that transformer, enable the adjacent features. Number of prior features = 1

Calculate the A value in that AttributeManager as: @sub(features[-1].A, features[-1].B)

 

 

I think that should do the trick.
Userlevel 5
Badge +25

In the AttributeManager you can use the adjacent features option to access attributes from previous features, as long as everthing remains in that order you can do it.

Check out Excercise 3 of the Advanced Attribute Handling part of the 2018 Desktop Advanced course, it does something very close to what you're trying to do here.

Badge +4

Thank you for your response and help. The exercise is a little bit different and when I try it, I don´t get the right result:

In the exercise the @sub from month to month is taken and is writen in a new attribute.

I tested a little bit around with the "Substitue Missing, Null and Empty by" option:

 

The result isn´t in cell A2 (all results are feature[-1]), but it is caluclate right:

Userlevel 2
Badge +19

Thank you for your response and help. The exercise is a little bit different and when I try it, I don´t get the right result:

In the exercise the @sub from month to month is taken and is writen in a new attribute.

I tested a little bit around with the "Substitue Missing, Null and Empty by" option:

 

The result isn´t in cell A2 (all results are feature[-1]), but it is caluclate right:

You need to ignore the first row with a conditional value.

 

 

Before the AttributeManager, add a Counter. Then, in the AttributeManager for the A value, you need to put a Conditional Value. Something like this:

If _counter != 0 Then @sub(features[-1].A, features[-1].B)

Else (do nothing)

 

Hope that helps.

Userlevel 2
Badge +19

Sorry, I think I was explaining myself very badly.

 

 

I have attached a workspace with what I think is the result you want.

xlsxr2none.fmw

Badge +3

@oscard

 

If it is to excell, you can also write the expression (in english and quoted) to excell itself.

So in A2 "=A1+B1"

A3 "=A2+B2"

etc.

Use stringconcatenator.

 

Or you can expose xls_row_id then explode and do the expression.

Or of course, as it is only one row down, you canuse adjacent features. (But what if it is not just 1 row down?) You than need to use stringconcatenation anyway.

Badge +4

@oscard thanks! It works.

Reply