We recently set up an email that needed different content based off if a sales goal was hit.

We had the following ampscript, but for some reason the system would only read the first integer. So if their target was 20, but they sold 4 items, it would read that 4 was higher than 20. Any ideas on why this is the case?

EDIT: The data types of Sales_Target and Total_Sales are both numbers.

    %%[ var @SalesTarget, @TotalSales, @text1, @text2
 set @SalesTarget = attributevalue("Sales_Target") 
 set @TotalSales = attributevalue("Total_Sales") 
 set @text1 = "You have not reached your target, but you still have plenty of time to earn."
 set @text2 = "You have reached your sales target." ]%% 
 %%[ IF @SalesTarget < @TotalSales THEN]%% 
  • What are the data types of Sales_Target and Total_Sales? Can you update your question to include samples of both? Dec 2 '21 at 20:28
  • 3
    Results of your conditional would vary if you're comparing strings instead of numbers, which is what I suspect is the issue. Dec 2 '21 at 20:40

Your comparison is being treated as string (instead of number). You need to use "FormatNumber" function to treat the values as numbers.

IF @SalesTarget < @TotalSales condition can be rewritten as

IF FormatNumber(@SalesTarget,"G") <= FormatNumber(@TotalSales, "G") ...

Also, note that I have changed the operator from "<" , to "<=", to treat two equal number as "meeting the target" path.

I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.