Skip to main content
Solved

Simple calculation and write in subsequent feature


connecter
Forum|alt.badge.img+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!

Best answer by oscard

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

View original
Did this help you find an answer to your question?

7 replies

oscard
Influencer
Forum|alt.badge.img+21
  • Influencer
  • July 8, 2019

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.

redgeographics
Celebrity
Forum|alt.badge.img+48

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.


connecter
Forum|alt.badge.img+4
  • Author
  • July 9, 2019

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:


oscard
Influencer
Forum|alt.badge.img+21
  • Influencer
  • July 9, 2019
connecter wrote:

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.


oscard
Influencer
Forum|alt.badge.img+21
  • Influencer
  • Best Answer
  • July 9, 2019

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


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • July 9, 2019

@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.


connecter
Forum|alt.badge.img+4
  • Author
  • July 10, 2019

@oscard thanks! It works.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings