# Operations between the same field of a content type

I feel like this is a very basic question, but after a couple of years it is the first time I need something like this and I cannot wrap my mind around the structure and get an idea of how to acomplish it.

Lets say I have a content type called "Fruit" where I store data in the fields "Name" (text), "Description" (text), "Price" (integer), "Date" (date). In a view I'd like to select the fruit with names "Pear" and "Apple" with their respective prices for the dates inserted, but also make mathematical operations on the prices of the fruit (Like, "The price of apples was the 3/4 of the price of pears"). I cannot think of a way to do this since it is actually the same field, only grouped by some other field.

Any suggestions?

• a proper answer really depends on where you want to do the calculations, and what you want to do with the results Jun 28, 2015 at 14:52
• I want to do the calculations per result, like "Divide the prices of the apples with the prices of pears on every given date" and display a graph with the results. The graph part is covered, I am looking for a way to get the result as an integer. Jun 28, 2015 at 15:19

Install views_php module. This module adds a field to the view and it also provides a few tokens. You can use the current row values. Note that you have to insert the main fields before the PHP field and exclude the Price field from display, Then the `\$results,\$data,\$row` objects will give you the value of the row, Do the mathematical calculations and output the result.
• The `\$row` object returns the value of the current row but `\$results` object returns the entire value of the view. Install Devel module and use `kpr(\$results)` and `kpr(\$row)` too see the available objects. But be sure it works Jun 28, 2015 at 15:34