18 Replies Latest reply: Dec 14, 2017 5:12 AM by Anagha Rao

Using Sum inside if condition

I need to use sum inside if condition like

I need to calculate

sum( if( sum([tot revenue]) < 0, \$(Serv_rev), 0))

but this expression is not working.

Kindly help.

• Re: Using Sum inside if condition

You can't do a sum in a sum, and you probably don't need it.

It would be like:

if( sum([tot revenue]) < 0, \$(Serv_rev), 0)

or

if( sum([tot revenue]) < 0, sum(\$(Serv_rev)), 0)

Depending on what you have in your variable \$(Serv_rev).

• Re: Using Sum inside if condition

my variable is

rev1 + rev2 + rev3.

its not working though.

• Re: Using Sum inside if condition

try

if( sum([tot revenue]) < 0, sum(\$(Serv_rev)), 0)

• Re: Using Sum inside if condition

Not working..

its always going in false condition.

• Re: Using Sum inside if condition

I think it would be helpful if you specify what isn't working. What are the input-values and which results do you get and which output is instead expected?

Further are you sure that your variable is working? They mustn't be start with an equal-sign and most often it's useful to apply a range-function instead of adding fields maybe like this:

Serv_rev:

rangesum(rev1, rev2, rev3)

- Marcus

• Re: Using Sum inside if condition

Yeah this variable is working fine.

What I want is the sum of rev1 ,rev2, rev3 when sum of total revenue is less than 0 i.e negative.

so that's why I used this expression i.e

sum( if( sum([tot revenue]) < 0, \$(Serv_rev), 0))

buts its not working.

• Re: Using Sum inside if condition

Just create a table-chart with the needed dimensions and use there as expressions:

sum([tot revenue])

\$(Serv_rev)

Do they really return your expected results?

- Marcus

• Re: Using Sum inside if condition

yes...

• Re: Using Sum inside if condition

try adding sum(tot revenue) is one expression and then in the other :

if(column(1)<0 ,sum(variable),0)

• Re: Using Sum inside if condition

Hello,

try

sum( if(aggr(sum [tot revenue], \$(Serv_rev)) < 0, \$(Serv_rev), 0))

or if you don´t need a sum by tot revenue

sum( if( [tot revenue] < 0, \$(Serv_rev), 0))

• Re: Using Sum inside if condition

Where are you trying this expression?

• Re: Using Sum inside if condition

Inside expression editor.

• Re: Using Sum inside if condition

Remove that and use it

If( sum([tot revenue]) < 0, \$(Serv_rev), 0)

• Re: Using Sum inside if condition

For UAT, Try this?

If( sum([tot revenue]) < 0, rev1 + rev2 + rev3, 0)

• Re: Using Sum inside if condition

Nope...

• Re: Using Sum inside if condition

Last attempt from me end? If not, Provide image

If( sum([tot revenue]) < 0, RangeSum(rev1, rev2, rev3), 0)

• Re: Using Sum inside if condition

Can you upload an example app?