Calculate Price Based On Days

Hey there! I have to make a very simple formula but having problems on how to write it correctly

I have two date fields (arrival, depature)
I have a Total days field ( calculates the date difference) -working

I have a price field that shows price for the spesific amount of days I have the formula:

IF({Dager} = 1, "590, ") &
IF({Dager} = 2, "690, ") &
IF({Dager} = 3, "840, ") &
and so on all the way to 21 days ( everything here is working fine)

BUT, after day number 21, the price is gonna add 20 for each day.

It’s going to be something like this:

If({dager)>21, ({dager},-21*(20),1490, ")

Example with 29 days - If({dager)>21, ({29},-21*(20),1490, ")

  • Here the days over 21 is 8. Then multiply 8 by 20, then + 1490 (price for 21 days)
    And the total is then 1650, which is correct.

When I do this in the calculator I get the correct price. When I did this in Caspio Cloud, it also worked. So my problem is just how to put in all the () and , and “” or {} at the right places for this!

If someone have the time to read and look trough this I would be really happy :smiley:

Thank you
Andreas.

Hi there,

Squiggly brackets “{}” go around field names. You don’t need them for a field name that only has one word and no special characters, but I like to use them for all field names so they’re easily recognizable.

Parentheses “()” are used as part of the formula function, either to wrap the entire function, or perform certain operations first in mathematical calculations.

So, for your example with 29 days, I would write the formula like this…

IF({Dager} > 21, SUM((({Dager} - 21)*20), 1490))

Hope that helps!

Thank you for such a fast answer! Now I understand a litte bit more, and the formula you provided is working perfect!

Again thank you very much, I really appreciate it!

1 Like