# AMPscript Function - Math

I wanted some help for an AMPscript function where i get an error. I have a data extension with some information like : Number of points Amount Transations

I need to display on this email the amount of money they need to go on the next step (like VIP)

So i need to do two functions :

• 5000 - Number of points = Number of points that i need to go on the next step
• Number of points that i need to go on the next step / 20 = amount of \$ that i need to spend to go on the next step.

I have this AMPscript :

``````SET @rowSet = LookupOrderedRows("Loyalty", 0, "Points Asc", "SubscriberKey", _SubscriberKey)
SET @rowCount = rowcount(@rowSet)

for @i = 1 to @rowCount do
var @nombrePointsCumul, @montantTotalTransactions, @pointManquant, @dollarManquant
SET @row = row(@rowSet, @i)

SET @nombrePointsCumul = field(@row,"Points")
SET @montantTotalTransactions = field(@row,"Transactions")

SET @pointManquant = Subtract(5000, @nombrePointsCumul)
SET @dollarManquant = Divide(@pointManquant, 20)
next @i
``````
• What error are you receiving? Jan 23 '18 at 20:22

For debugging purposes, I'd recommend doing an output() of values used in your calculations. I'm guessing your issues are data related (e.g. trying to do calculations on values that are not numbers).

``````%%[

SET @rowSet = LookupOrderedRows("Loyalty", 0, "Points Asc", "SubscriberKey", _SubscriberKey)
SET @rowCount = rowcount(@rowSet)

for @i = 1 to @rowCount do

var @nombrePointsCumul, @montantTotalTransactions, @pointManquant, @dollarManquant
SET @row = row(@rowSet, @i)

SET @nombrePointsCumul = field(@row,"Points")
SET @montantTotalTransactions = field(@row,"Transactions")

output(concat("<br>nombrePointsCumul: ",@pointManquant))
output(concat("<br>montantTotalTransactions: ",@montantTotalTransactions))

SET @pointManquant = Subtract(5000, @nombrePointsCumul)
SET @dollarManquant = Divide(@pointManquant, 20)
next @i

]%%
``````