Expand my Community achievements bar.

SOLVED

If calculation

Avatar

Level 2

How can i do the following calculation:

Values/Fields are:

Amount:
[DISCOUNT1] 10
[DISCOUNT2] 20
[DISCOUNT3] 30

Percents:
[DISCOUNTIF1] 1
[DISCOUNTIF2] 2
[DISCOUNTIF3] 3

Total:
[TOTALDISCOUNT]


The calculation should go something like this:
If total amout is over 10[DISCOUNT1] and below 20[DISCOUNT2], the [DISCOUNTIF1] is 1,
If total amout is over 20[DISCOUNT2] and below 30[DISCOUNT3], the [DISCOUNTIF2] is 2,
If total amout is over 30[DISCOUNT3], the [DISCOUNTIF3] is 3.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Is this what you are after?

// form1.page1.subform1.discount::calculate - (FormCalc, client)


if (HasValue(totalPrice)) then

  if (totalPrice > 10 and totalPrice < 20) then

    $.rawValue = totalPrice * 0.01

  else

    if (totalPrice > 19 and totalPrice < 30) then

      $.rawValue = totalPrice * 0.02

    else

      if (totalPrice > 29) then

        $.rawValue = totalPrice * 0.03

      endif

    endif

  endif

else

  $.rawValue = null

endif

Steve

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

Is this what you are after?

// form1.page1.subform1.discount::calculate - (FormCalc, client)


if (HasValue(totalPrice)) then

  if (totalPrice > 10 and totalPrice < 20) then

    $.rawValue = totalPrice * 0.01

  else

    if (totalPrice > 19 and totalPrice < 30) then

      $.rawValue = totalPrice * 0.02

    else

      if (totalPrice > 29) then

        $.rawValue = totalPrice * 0.03

      endif

    endif

  endif

else

  $.rawValue = null

endif

Steve

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----