Hi

Im trying to get multipe if() statements to work.

Currently i have two variables, Discount Total (call it A) and Position Total (call it B).

What i want out of the operations should look like this:

if A and B empty, then {{emptystring}}

if only A empty, then give me B

if only B empty, then give me -A (negative)

I tried setting it up like this:

But what I’m currently getting is:

If A and B empty, if get “-” (just my minus sign, this should be empty)

If only A empty, i get “-” (this should be B)

If only B empty, i get -A (this works)

Is there an easier way to set this up without needing to do multiple if()'s ?

Figured someting out:

This works now for me:

if Pos.Total is empty then minus Disc.Total

if Disc.Total is empty then Pos.Total

if both empty, then an empty string

I’m still curious if there is an easier way that’s easier to read than whatever i wrote

1 Like

Hi @FPM_Support

You can try this :

{{if((length(9.a) > 0 & length(9.b) = 0); “-” + 9.a; ifempty(ifempty(9.a; 9.b); emptystring))}}

The following conditions are considered:

if A and B empty, then {{emptystring}}

if only A empty, then give me B

if only B empty, then give me -A (negative)

**Regards,**

*Msquare Automation - Gold Partner of Make*

Book a Free Consultation | Connect Live

Explore our **YouTube Channel**

for valuable insights and updates!

1 Like

Hi,

Key point: Are `A`

and `B`

always integers/numbers, or could they be strings?

If there’s a possibility that they could be strings, use @Msquare_Automation’s solution with the `length()`

function.

A and B cannot be strings.

Thanks for the input, i forgot to mention this.

Thank you so much.

In my case there is a possibility that A or B are zero. They shouldn’t be, but i want to make sure the szenario still continues. I forgot to mention that A or B cannot be strings.

The variable you gave me might just solve another issue i have were a string in another variable should not be displayed if A and B are empty.

Thanks for suggesting length()

Hi @FPM_Support length() works for each data type. However, as @mszymkowiak said, this formula won’t be accurate in numbers data type. Hence, we have updated the formula for your requirement that is attached below.

{{if(if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring)) = 0; if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring)); parseNumber(if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring))))}}{{if(if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring)) = 0; if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring)); parseNumber(if((length(214.a) > 0 & length(214.b) = 0); if(214.a = 0; 214.a; “-” + 214.a); ifempty(ifempty(214.a; 214.b); emptystring))))}}

Please note, if you want the condition to treat like “does not exist” in case of the value is 0, then this formula won’t work.

For example, if value A is 0 and value B is 1, in this case, both the values exist.

If value A is 0 and value B is “null”, then value B does not exist and formula will return 0.

If value A is 2 and value B is “null”, then formula will return -2.

**Regards,**

*Msquare Automation - Gold Partner of Make*

Book a Free Consultation | Connect Live

Explore our **YouTube Channel** for valuable insights and updates!

1 Like