Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
surajap123
Creator II
Creator II

Diff between the 2 expressions

Hi All,

I thought both the below statements are same, so i created the 2nd one using set analysis. But i am getting different outputs

(Sum(IF(Status = 'Cancelled',  (Amount)))) + (Sum(IF(Status = 'Booked',  (Amount))))

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

Could you please tell me why they are giving different results?

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Set analysis would not respond to your Status field selection here, while the other expression without set analysis does.  Apart from that:

(Sum(IF(Status = 'Cancelled',  (Amount)))) + (Sum(IF(Status = 'Booked',  (Amount))))

  •      This executes like Status='Cancelled' OR 'Booked'

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

  • This executes like Status='Cancelled' AND 'Booked'    // which is not really meaningful

Update: And when it is same field, it take the later one(here 'Booked')

View solution in original post

15 Replies
its_anandrjs

You can try like

Sum( {<Status={'Cancelled','Booked'}>}Amount)

And may be your if statement which is this

(Sum(IF(Status = 'Cancelled',  (Amount)))) + (Sum(IF(Status = 'Booked',  (Amount))))



gives wrong result try to check and cross check this by using


=Sum(IF(Match(Status,'Cancelled','Booked'), Amount))



sudeepkm
Specialist III
Specialist III

Please try like below

sum( {<Status={'Cancelled', 'Booked'}>}Amount)

Anonymous
Not applicable

hi,

try like this

for 2nd expression

sum( {<Status={'Cancelled','Booked'}>}Amount)

sudeepkm
Specialist III
Specialist III

it looks like when you use this expression

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

It considers the Status as 'Booked' only

and

when you use like

sum( {<Status={'Cancelled', 'Booked'}>}Amount) then it considers either Cancelled or Booked.

tresesco
MVP
MVP

Set analysis would not respond to your Status field selection here, while the other expression without set analysis does.  Apart from that:

(Sum(IF(Status = 'Cancelled',  (Amount)))) + (Sum(IF(Status = 'Booked',  (Amount))))

  •      This executes like Status='Cancelled' OR 'Booked'

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

  • This executes like Status='Cancelled' AND 'Booked'    // which is not really meaningful

Update: And when it is same field, it take the later one(here 'Booked')

sudeepkm
Specialist III
Specialist III

Hi Tresesco,

I just created a sample app where I used the expression like below.

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

I didn't have data points that has both Cancelled and Booked Status that means it (the AND operator) should have given me 0  as there were no items in common, however I found that the result is the value of Status = "Booked". Can you please check once and confirm? I tested this using a sample app of mine.

surajap123
Creator II
Creator II
Author

Hi Tresesco,

As you mentioned, Could you please explain me why Set analysis would not respond to your Status field selection in the below expression-

sum( {<Status={'Cancelled'},Status={'Booked'}>}Amount)

SunilChauhan
Champion II
Champion II

both are same .may be not distinct and distinct results

but you can write like  Sandeep and Nisha.

hope this helps

Sunil Chauhan
sudeepkm
Specialist III
Specialist III

I just checked your update. Thanks a lot.

In case of same field it takes the later one. Thanks again.