I have a model Invoices 

Table Invoices:
ID, PRODUCT, UNITS, PRICE

In my view, I want to show total for some columns.

For instance to show total quantity I can set in my controller:

```
@invoices = Invoice.group(:PRODUCT).select(ID, PRODUCT, UNITS, SUM(UNITS) AS TOTALUNITS, PRICE").order('PRODUCT ASC')

@units_total = @invoices.map(&:UNITS).sum

```

and in my view

```
<%= @units_total %>

```

and it returns the total in column UNITS. This works fine.

If I define in my model:

```
def total_amount
(self.PRICE * self.TOTALUNITS)
end

```

and then on the same way I want to show the total of total\_amount, I tried in my controller:

```
@amount_total = @invoices.map(&:total_amount).sum

```

it doesn't work, as I assume that if I'm not using a column name the syntax must be different. 

What should I enter then?

**UPDATE**
The problem comes form the fact that I'm using in model (self.PRICE \* self.TOTALUNITS). I didn't include it when I posted the question as I thought it didn't matter. But if I replace(self.PRICE \* self.TOTALUNITS) with (self.PRICE \* self.UNITS) there's no error but values are obviously wrong.