Skip to main content
Solved

Simple calculation and write in subsequent feature

  • July 8, 2019
  • 7 replies
  • 55 views

connecter
Contributor
Forum|alt.badge.img+10

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

oscard
Influencer
Forum|alt.badge.img+22
  • 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+62

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
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • 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+22
  • Influencer
  • 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:

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+22
  • 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
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • July 10, 2019

@oscard thanks! It works.