Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Best and Correct way to write this expression

Hello

I am trying to write an expression that returns either a 1 or a 0 which I will multiply by another expression.

Which of the two ways is correct:

Method 1: if (XDate>=StartDate and XDate<=EndDate,1,0)

Method 2: sum(if(XDate>=StartDate and XDate<=EndDate,1,0))

Which of the above two methods is correct?

Please Note I will be multiplying the result of the above expression by my amount. So for example 600 * 1 or 600 * 0 depending upon the condition.

Thanks

6 Replies
trey_bayne
Partner - Creator
Partner - Creator

What are you trying to accomplish. I ask because Method 1 has no aggregation but Method 2 uses sum.

In short, 'If' is always CPU intensive though sometimes necessary. If you have to Sum something, I might recommend using Set Analysis.

sum( {$ < XDate = {">=StartDate<=EndDate"} > } Amount )

Not applicable
Author

@Trey Bayne

Hello Trey

Basically what I want to do is this:

I have a column Amount and another column is the above expression which should return either a 1 or a 0 to me. Because my third column then is Amount * 1 or Amount * 0 and when it is Amount * 0 then I will supress 0's

Thx

trey_bayne
Partner - Creator
Partner - Creator

In that case, use Method 1.

The sum in Method 2 is not going to accomplish anything as it will just produce the same number as Method 1.

That being said, if you'd be willing to share your 3rd column expression there may be a better way to accomplish what you are doing.

sujeetsingh
Master III
Master III

Method 1 seems correct

vijetas42
Specialist
Specialist

Method 1 is correct way to write this expression

Greg_Williams
Former Employee
Former Employee

Method 1 (optimized)