Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

SUM 2 fields on 2 conditions...

OK, I have a question re: summing. I want to SUM [Contract Value] when Stage is 'Contract' and add this to the SUM of [Pipeline Value] when Stage is 'Contract Negotiation' or 'Offer Negotiation'.

I've seen conditional sums in here, but they are typically summing one field when multiple conditions exist. Here I need to sum 2 fields when 2 or more conditions exist.

Any help would be greatly appreciated!

Tags (1)
4 Replies
venkatasreekant
Valued Contributor

Re: SUM 2 fields on 2 conditions...

Hi Try this code:

=Sum((If(Stage='Contract',ContractValue) and if(Stage='Contract Negotiation' or 'Offer Negotiation',[Pipeline Value]))

Not applicable

Re: SUM 2 fields on 2 conditions...

Thanks for this!  I just had to tweak the "and" to an "or" and now it works, so I get what I need! Thanks!

Not applicable

Re: SUM 2 fields on 2 conditions...

Hi James

IF want to SUM [Contract Value] when Stage is 'Contract' and add this to the SUM of [Pipeline Value] when Stage is 'Contract Negotiation' or 'Offer Negotiation'. please see below code try to with this hopefully it will work out for your issue.

=Sum((If(Stage='Contract',ContractValue) and if(Stage='Contract Negotiation' or 'Offer Negotiation',[Pipeline Value]))

qlikoqlik
Contributor II

Re: SUM 2 fields on 2 conditions...

Hi James

If use set analysis the syntax would as per below and sum(set analysis is more efficient than ifs

=sum({<Stage={'Contract'}>}[Contract Value])

+ sum({< Stage= {'Contract Negotiation' , 'Offer Negotiation'}>} [Pipeline Value])

Regards

Padma


Community Browser