How to use one attribute to subtract against another attribute

chee_altair_com
chee_altair_com
Altair Employee
edited November 2024 in Community Q&A
In a dataset, the attribute names are:
State   2020  2019  2018  2017  2016

What is required is the difference between the numeric columns, say:
column diff2020 = column 2020 - column 2019.

I've tried using loop_attribute operator. Inside this loop process, I have a Generate Attribute operator.
For this Generate Attribute operator:
the attribute_name is:    diff_%{loop_attribute}
the function expression is:    eval(%{loop_attribute}) - eval(%{loop_attribute}-1)

the above is an incorrect function expression. What should the correct function expression be?


Thanks
Chee


Tagged:

Best Answer

  • chee_altair_com
    chee_altair_com
    Altair Employee
    Answer ✓
    Found the answer. 

    In the Generate Attribute, the function expression syntax is: (#{loop_var} - #{prevloop_var})/ #{prevloop_var}

    This is the column based operations to calculate relative difference between two consecutive years.

    The attribute(column) names are loop_var created using Set Macro and the calculated name prevloop_var using Generate Macro.

Answers

  • chee_altair_com
    chee_altair_com
    Altair Employee
    following above, I've discovered the syntax for column is the square brackets.

    So it would be something like [2020] - [2019]    if we write manually.
    But programmatically for many columns, it should be:
       [%{loop_attribute} ]   - [ %{loop_attribute} -1 ]

    Obviously, the syntax above is wrong. But can anyone tell me what should the syntax be, that can be entered into the Generate Attributes field.

    Thanks
    Chee

  • chee_altair_com
    chee_altair_com
    Altair Employee
    Answer ✓
    Found the answer. 

    In the Generate Attribute, the function expression syntax is: (#{loop_var} - #{prevloop_var})/ #{prevloop_var}

    This is the column based operations to calculate relative difference between two consecutive years.

    The attribute(column) names are loop_var created using Set Macro and the calculated name prevloop_var using Generate Macro.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.