0

I have some basic AMPscript pulling content in based on value of the @AccountBalance attribute in my DE:

%%[IF @AccountBalance >= '2000' THEN]%%
HTML
%%[ELSE THEN]%%
HTML

I wasn't getting the results I expected, people with 0 points were getting the right content but people with more than 0 but less than 2000 as their AccountBalance were getting the >= 2000 content.

I was able to play around with the code to get it to work (I thought), by removing the quotes around 2000 so the code read %%[IF @AccountBalance >= 2000 THEN]%%. I assumed that the system was looking for AccountBalance values of exactly 2000. However, while the people under 2000 points were getting the right content, people over were not.

Once I set @AccountBalance = ACCOUNTBALANCE, then it all seemed to come together. But I don't know why. We use AccountBalance and other variables like @FirstName in our emails without specifically declaring them, so why was it different this time?

2
  • 1
    What's the data type of AccountBalance in the send context? Dec 5, 2023 at 18:04
  • it's text data type
    – PForsyth
    Dec 5, 2023 at 19:42

2 Answers 2

2

Here's what I'd suggest:

%%[

set @accountBalance = AttributeValue("accountBalance")
set @accountBalance = "$1,000" /* for testing */

if empty(@accountBalance) then
  set @accountBalance = 0
else
  set @accountBalance = replaceList(@accountBalance,"",",","$"," ")
  set @accountBalance = add(@accountBalance,0)
endif

if @accountBalance > 2000 then 
  output(concat("balance is more than 2000"))
else 
  output(concat("balance is less than or equal to 2000"))
endif

]%%

Try it yourself: https://mcsnippets.herokuapp.com/s/NmyrdN38

1

It depends on if ACCOUNTBALANCE is a number or not. When comparing strings, 3 is greater than 2000 (3 is greater than 2), so 3 >= 2000 is true. However, if you compare numbers, you'll get the values you expect. You should also be able to write:

%%[IF FormatNumber(@AccountBalance, "N") >= 2000 THEN]%%
2
  • This'll work however, the formatNumber will throw a compiler error if you don't pass it a numeric value, e.g. $2000. Dec 5, 2023 at 18:41
  • @AdamSpriggs I only addressed the likely initial problem given the limited information in the question, and I honestly have about 5 seconds worth of actual MC experience, lol. Your answer was definitely enlightening.
    – sfdcfox
    Dec 5, 2023 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .