0

Relationship between "Chice" and "Formula" fields

The table has two fields, a choice "Category" and a formula field "Discount" . Depending on the client category, a discount is assigned. Can someone, please, tell me the formula, for example, when the category is 1 or 2, the discount is 10%, when the category is 3 or 4  - 15%,  5 - 20% 

Regards

5 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    You can try this in your formula field "Discount":

    switch true do
    case Choice = 1 or Choice = 2:
        0.1
    case Choice = 3 or Choice = 4:
        0.15
    case Choice = 5:
        0.2
    end
    

    You can change the number to text "10%" if you want. If you leave it as a number then you can quickly use it in other formulas.

    You can check out this post for more background info and more examples of what you can do from Jacques TUR .

      • iliper LTD
      • iliper_LTD
      • 1 yr ago
      • Reported - view

      Fred Thanks for the quick response.

      good solution as always
      Thanks

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    You can also use a table with all possible discount rates according to the category number:

    item([0, 0.1, 0.1, 0.15, 0.15, 0.2],Number(category))
      • iliper LTD
      • iliper_LTD
      • 1 yr ago
      • Reported - view

      Jacques TUR Thanks for help, but 

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      iliper LTD  Oh yes, the Ninox compiler is case sensitive. Just replace "N" by "n" on the number function name.

      item([0, 0.1, 0.1, 0.15, 0.15, 0.2], number(Category))
      

      Another thing, Fred  's solution is just as interesting because it is easier to read. Sometimes it is more interesting to favor the ease of reading for the maintenance of the program rather than the optimization of the number of lines.

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 5Replies
  • 58Views
  • 3 Following