How to create conditional IF THEN ELSE calculations involving two fields?

Comments

16 comments

  • Hamid

    Hi Armando,
    You can use this syntax :

    var TR = @taxRateField;
    var PR = @publicRateField;
    var P1 = PR + (PR * 0.21);
    var P2 = PR + (PR * 0.10);
    TR == 0 || TR == null ? P1 : P2
    

    /Hamid

    0
    Comment actions Permalink
  • Ralston

    Hello

    I have a similar IF calculation.

    I have a CATEGORY Field with values "Income" & "Expense"
    And an AMOUNT Field

    In my CALCULATION Field, I want the following:
    IF CATEGORY = "Income"
    THEN AMOUNT is +AMOUNT
    ELSE AMOUNT is -AMOUNT

    Thanks :)
    Rally

    0
    Comment actions Permalink
  • Hamid

    Hi Rally,

    in a calculation field weite this :

    @YourCategory_Field == "Income" ? +@Amount ? -@Amount
    
    0
    Comment actions Permalink
  • Ralston

    Thank you very much Hamid :)

    0
    Comment actions Permalink
  • Hamid

    Hi Ralston,
    there is an error in my formula :) you should replace the second "?" by " : "
    like this

    @YourCategory_Field == "Income" ? +@Amount : -@Amount
    
    0
    Comment actions Permalink
  • Ralston

    oh ok, thank you again :)

    0
    Comment actions Permalink
  • Victor Konig

    Hi Hamid!

    I asked a question to PODIO support but no one can help. I would be very grateful if you could help me with this

    I am trying to do a basic IF/Then number calculation and I know this isn't excel but i'm not sure the correct way to enter it so that PODIO recognizes it.

    I would like a CALCULATION field to see an above MONEY field and if that number is less than 160 to enter the number 16 within that CALCULATION field. IF the number is greater than 160 I would like polio to multiply it by .10 and enter the new number in the CALCULATION field.

    In trying to keep it like EXCEL I am referencing fields vs cells of course but i can't get it to quit work. (I'm not a programmer)

    IF(@Food Total<160,16,@Food Total*.1)

    Do I write "IF" do I add an Equal Sign, Parenthesis, etc... How do I get this to function on PODIO

    Thanks

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Victor,

    the formula in Javascript is:

    var ft = @Food Total;
    ft < 160 ? 16 : ft > 160 ? ft*.1 : ""
    

    Read it as: IF Condition 1 is true THEN (=?) display 16 ELSE IF (= : ) condition 2 is true THEN Numenr*.1 ELSE show nothing (nothing for the case when nothing is entered in the money field). Btw. I would write ft <= 160 for the case if it is exactly 160.

    Rainer

    1
    Comment actions Permalink
  • Rudy Saborio -JBI Studios

    Hello

    We Have an App that we created on Podio, and inside of it, i add 2 money fields, and one field for Calculation where i want to add my JavaScript, the Money Fields are named Rudy Order $, Rudy GTotal $, all of them should be populated with Numbers, So in the calculation field i add this JavaScript to make my calculation.

    Basically what i need to do is: if field Rudy Order $ it has a different amount number than Rudy GTotal $, Write the amount from the field Rudy GTotal $, and if Rudy Order $ equals to cero write the ammount from the field Rudy GTotal $.

    if(@Rudy Order $ != @Rudy GTotal $ ) {

    document.write(@Rudy GTotal $);
    } else (@Rudy Order $ = "0" ){
    document.write(@Rudy GTotal $);

    But i keep getting this error that sais "The calculation field must reference at least one other field. It cannot be entirely based on static data, such as strings or numbers."

    Thanks in advance


    if($rudyOrder != $rudyGtotal ) {
    document.write($rudyGtotal);
    } else ($rudyOrder = "0" ){
    document.write($rudyGtotal);

     

    0
    Comment actions Permalink
  • Hugo Hidalgo

    Hi Hamid,

     

    I am trying to have an auto populated field on my app from a relationship field. 

    So I have 3 apps:

    Company app has a field with Contact app into it.

    Contacts app has related items referencing company app

    demo app has both other apps as relationships.

    in the contact app I have a calculation field named Business Card with all fields I wanted: @Name of Contact + '\n' + @Email + '\n' + @Phone

    what I want is that when I choose the Company from the relationship firld in the demo app, the calculation throws the business card for that contact.

     

    how can I do this?

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi,

    easiest way:  Add a calc field in Companies (e.g called Business Cards from Contacts), pull the Business Cards from all related contacts (@all of Business cards.join("\n")) into that new field. Then in your calc field in Demo: @all of Business Cards from Contacts.join("\n")

    Rainer

    0
    Comment actions Permalink
  • James

    @Rainer Nice and Simple Code, Thanks.

    But how can i implement a IF AND statement like this?

    How can i get this to work?

    var ANZ=@Anzahl Rabattberechtigt

    if (ANZ <=19){20;}

    else if ((ANZ >19)&&(ANZ <50)){30;}

    else if ((ANZ >49)&&(ANZ <100)){40;}

    else if ((ANZ >99)&&(ANZ <250)){50;}

    else if ((ANZ >249)&&(ANZ <500)){55;}

    else if ((ANZ >499)&&(ANZ <1000)){60;}

    else (ANZ >999){65;}
    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Roman,

    var ANZ=@Anzahl Rabattberechtigt;
    anz <= 19 ? 20 : anz < 50 ? 30 : anz < 100 ? 40 : ... and so on

    Rainer

    0
    Comment actions Permalink
  • Jade Cones

    I currently have a coded naming system for a google drive folder name creation as:

     

    var year = moment(@Created On).year();

    @Unique ID + " - " + @All of Name+ " (" + year + ")"

     

    This works fine. However, if I have the company field filled out in podio then I would like that to appear at the end. If the company field is not filled out then I want the naming convention to go as above... I tried to do it my self and for some reason it is saying there is still a script syntax error, maybe you could tell me where I went wrong:

     

    var year = moment(@Created On).year();
    var comp = @All of Company Name ;

    comp = comp ? @Unique ID + " - " + @All of Name+ " (" + year + ")" + " - " + @All of Company Name + ";
    : @Unique ID + " - " + @All of Name+ " (" + year + ")"

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Jade,

     

    the error is caused by missing quotation marks between the semicolon and the colon. Here's a simplified version: 

    var year = moment(@Created On).year();
    var comp = @All of Company Name ;
    var comp = comp ? " - " + comp  + "; " : "";
    @Unique ID + " - " + @All of Name+ " (" + year + ")" + comp

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk