Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum of negetive value in Text Object

Hello,

I want to calculate negetive profit as show below

Profit= Income -Cost

I want the result in text box as -15 using set analysis

IncomeCost ProfitNegetive profit
251015
1520-5-5
503020
604020
4050-10-10
40-15

Thanks,

Veer.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Try

sum(if(Income-Cost < 0, Income-Cost))

edit: If you want to use set analysis, you can create a flag in your load script

LOAD

     Income,

     Cost,

     if( Income-Cost <0 ,1,0) as Flag,

     ...

FROM ...;

then in your text box, either use

sum( (Income-Cost) * Flag)

or

sum({<Flag = {1}>} Income-Cost)

Looking at these expressions, it would probably be good to calculate the difference itself also in the script.

View solution in original post

3 Replies
antoinelaviron
Partner - Contributor III
Partner - Contributor III

Hi try this in a texbox:

=sum(

     Aggr( if((Cost<Income),(Income-Cost),0), Income,Cost)

     )

or if you have the field Profit already calculated and want to use set analysis

=sum(

     Aggr( only({$ <Profit = {'<0'}>} Profit)

               ,Income,Cost

          )

     )

Best,

Antoine

swuehl
MVP
MVP

Try

sum(if(Income-Cost < 0, Income-Cost))

edit: If you want to use set analysis, you can create a flag in your load script

LOAD

     Income,

     Cost,

     if( Income-Cost <0 ,1,0) as Flag,

     ...

FROM ...;

then in your text box, either use

sum( (Income-Cost) * Flag)

or

sum({<Flag = {1}>} Income-Cost)

Looking at these expressions, it would probably be good to calculate the difference itself also in the script.

Not applicable
Author

Thank u i got the rite method