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

Count in listbox using variable or expression


Hi, I'm new in qlikview making my first steps into this world of magic.

I'm trying to make a count of occuring products in a product table in a listbox, count per type of product.

Seems to work fine if I use the count as an expression in the listbox object.

qv_img1.PNG.png

My expression in the listbox oblect : Count (Product_ProductType_Code)


Now I want to replace this by a variable to be able te reuse it.

So I've created a variabel containing this expression :

qv_img2.PNG.png

And then use this variable in my listbox expression.

qv_img3.PNG.png

But I get a different result as shown below (left = count in listbox expression, right is using variable in listbox expression).
In the result using the variable I get a total count of all products instead of a count on product type.


qv_img4.PNG.png

I expected the results to be the same but it's not.

What am I doing wrong?

Thanks for any help in understanding this.

Hugo

1 Solution

Accepted Solutions
morganaaron
Specialist
Specialist

Hi Hugo,

In your variable, remove the = sign at the beginning - what this tells Qlikview is to calculate the value globally, so it will return a total.

If you're storing it as text, when you then reference it in your listbox, include a DSE (dollar sign expansion) to calculate the expression you're storing.

So your variable is Count(Product_ProductType_Code)

And your expression will be =$(vCountProductType)

Thanks.

View solution in original post

5 Replies
sujeetsingh
Master III
Master III

How can you the single variable can provide different values.

A variable here is calculating the entire total without any distribution of the Product type.

I recommend you to use the expression only.

What you want to achieve , why you want variable?

Not applicable
Author

Hi, thanks voor replying so quickly.

I'm now just trying to understand why the result is different and how I can get the same result when using an variable.
The idea is to make the field that needs to be counted omitted so I only need 1 variable/expression for the count of any field I want to show of let the user choose wicht count to show.

Don't now if this is possible as simple as this but that's what I'm thinking of.

morganaaron
Specialist
Specialist

Hi Hugo,

In your variable, remove the = sign at the beginning - what this tells Qlikview is to calculate the value globally, so it will return a total.

If you're storing it as text, when you then reference it in your listbox, include a DSE (dollar sign expansion) to calculate the expression you're storing.

So your variable is Count(Product_ProductType_Code)

And your expression will be =$(vCountProductType)

Thanks.

sujeetsingh
Master III
Master III

Variable can not achieve this.

Why you want to omit it?

From where you want it to be omitted ?

Use hide prefix

Set Hide Prefix=$;

Now rename

Product_ProductType_Code as $Product_ProductType_Code

Not applicable
Author

Hi Aaron,

That's exactly what I wanted to now and understand.

Guess I need to get familiar with the syntax and it's differences in result.

Thanks!