### Post

1 follower Follow

# Conditional Format Aplication

Hi, I wanted to know how can i make a calculation with a conditional statement. What i need to do is to execute is a calculation that allows me to sum a range of other fields; and if the statement is false this field performs another different calculation.

Is this possible?

Regards.

Jester Chávarry

Jester Chavarry

Hey Jester,

This should be possible via Javascript yes - if (condition) {action1} else {action2};

Can this work?

Cheers,
Sara

Hi Sara,

I've tried what you told me, but the thing is that i didn't get the result i needed.

In my case, the calculation should be the following:
if (Category Field=True Value) {action 1} else {action 2}

Regards.

Perhaps you can write the entire calculation to help us understand what is not working?

It is important that you are familiar with Javscript for it to work :)

//Sara - Podio

Of Course Sara:

First of all, the category field titled "Incentiva a la renuncia" has two options.
"Aplica" y "No Aplica"

In this case, what i need to do is to apply a calculation if the statement is true, and another if it is false.

The details are displayed below:

if (Incentiva a la renuncia:="Aplica") {0} else {(EC NEG - Uso de gancho:*0.12*100)+(EC NEG - Sondeo:*0.05*100)}

For the example,the fields called "EC NEG - Uso de gancho:" and "EC NEG - Sondeo:" are Numbers, which already show us the result we need.

Regards.

Hi Sara; Do you have the response for my question please?

Regards.

Do you get any error message? I'm afraid it is quite difficult to see from here without access to your apps and workspaces or error message :(

I just tested myself using if(Number1==="1"){100}else{200} and it seems to work :)

You need to add "===" as = is an assignment operator, not a comparison :) I should have added this in the code description above! Will add it now.

Hi Sara, i have another question in the statement i'm giving to the calculation i need to get the result in text format, this because i need to display the "%" symbol.

How can i get this result if the statement in both cases, when it is true or false? when I execute the standard calculation i get the message "The result is not a valid number". Just Because I added +"%" to the formula i am using.

Regards.

I think you can work-around this by making the output of the calculation a text and forcing the unit at the front of the calculation. Something like:

"%" + (@number1 + @number2)

as example

But one problem with this is that you lose control of the number of decimal places that are displayed, because this is not an option in calculations with text output. You can control this by using a javascript function toFixed() like this:

"\$" + (@number1 + @number2).toFixed(2)
The brackets are important in both cases (they should be around the numbers). The 2 inside the brackets at the end is the number of decimal places you need.

Hello Sara:

I've tried including the "%" symbol inside my calculation but i'm not able to save the changes because I get the following message "The type of result changed from number to text."

Just to be sure that i explained myself right i let you the statement I´m trying to use.

if(Incentiva a la renuncia:==="Aplica") {(0)+"%"} else {(1)+"%"}

I also tried the statement without the brackets, but i got the same error.

Regards.

Hi Sara.

Sorry to bother, but I wanted to know if you have some news for me.

Thank you.

Regards.