2

So I'm trying to find a simple way to create a new column that displays the difference between two existing columns (each with numbers)... I can't seem to find the proper GREL expression....

So I'm trying to find the amount of items sold with a column named "stock_before" and the other named "stock_after".

I click on edit column from the column "stock_before" and then add column based on this column.

For the GREL I have already entered is: value-cells["Stock_after"] It returns no syntax error but still all of the cells for preview say "null"... I have transformed the value of the columns to numbers.

For Python I have tried: substract(value,"Stock_after") Same no syntax error but still everything null.

This seems so ridiculously simple but I couldn't find an answer... You can guess I'm fairly new to all this :) Hope someone out there can help me!

thanks for your having the patience to read this and thanks for your time if you answer!

I'd like something similar to this (3 columns):

Stock_before, Stock_after, dif

1,1,0

3,1,2

4,4,0

2,1,1

1 Answers1

0

In GREL, the expression cells["Stock_after"] returns a Cell object representing the corresponding cell, not the actual value of that cell. To get the value, you need to use cells["Stock_after"].value.

So your final GREL expression should be value - cells["Stock_after"].value.

You should also make sure your values are stored as numerals, not strings: they should appear in green in the table. If they do not, use a "To number" operation on both columns first.

You can find out more about GREL and Cell objects here: https://github.com/OpenRefine/OpenRefine/wiki/Variables

pintoch
  • 2,293
  • 1
  • 18
  • 26