Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variables and if statements

I've only just started using the software, so apologies if this should be simple, I'm looking for a bit of assistance...

I have a couple of expressions that are working fine:

sum(if($(vShowQty)=1,QtyInvoiced,NetSalesValue))

and

sum({$ <[Sales.Year]={"2010/11"}>} NetSalesValue)

The variable vShowQty is set based on two buttons and could either equal a 1 or 0.  Ideally, what I'm trying to do is combine the above two expressions into a single expression.  Essentially if vShowQty=1 and Sales.Year ="2010/11" I want to sum the QtyInvoiced, otherwise if vShowQty=0 and Sales.Year="2010/11" I would want to sum the NetSalesValue.

Not sure if the above makes complete sense, but hopefully someone might be able to point me in the right direction?

Thanks

1 Reply
swuehl
MVP
MVP

Maybe like this

=if( vShowQty = 1,

     sum({$ <[Sales.Year]={"2010/11"}>} QtyInvoiced),

     sum({$ <[Sales.Year]={"2010/11"}>} NetSalesValue)

)

Since vShowQty is a variable you don't need to check it per record (i.e. inside the aggregation), and you probably don't need the dollar sign expansion $(..) when used in a chart expression.

Note that {$ <[Sales.Year]={"2010/11"}>} is assigning value 2010/11 in a set expression's field selection, it's not really a condition as one can understand your above written requirement (if vShowQty=1 and Sales.Year = 2010/11 ...)