Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

count(...) if no values selected

Hey guys,

Another question, a simple one I think 😉

I want to get a string of selected values of a field. The following code does the trick pretty neatly:

Concat(distinct {$} fieldName, ',')

Until NO values are selected. Then it still returns the full set of values, whereas I'd expected to get an empty string

I tried the following as a workaround, but the count() function seems to show the same behaviour (which I haven't quite understood, yet)

if(count(distinct {$} fieldName) > 0; Concat(distinct {$} fieldName, ','); '')

What am I missing here?

Thank you!

Sandro

1 Solution

Accepted Solutions
IAMDV
Luminary Alumni
Luminary Alumni

Hi Sandro,

The reason why you get the same result is because you are using Count() function which returns total number of rows when there are no selection in the model. Please remember that aggregations are performed on full set of data when there are no selections. However, data is filtered when you make selections hence Count() would give the right number of values. To keep it simple…always remember that – No Selections in QlikView means Selecting All. I hope this makes sense.

Marco is right with that expression. However if you wanted to take this expression a step further where you wanted to check the selection state across all the fields in one Variable/Expression then use the below one…

vMySelectionState       =      =Concat('GetSelectedCount([' & $Field & '])', '+')

Then you can use $ (Dollar Sign Expansion) $(=vMySelectionState) to check if there are any selections in the entire application.

Note: Please include the “=” before the Concat function in the above expression.

I hope this helps!

Cheers,

DV

www.QlikShare.com

View solution in original post

8 Replies
Not applicable
Author

 

Use this

GetFieldSelections(CAMPO,';',100)

Anonymous
Not applicable
Author

That works the way I thought it should 🙂

Any reasoning as to why the other two would behave the way they do, though? Maybe I am missing something in the set analysis concept or something

Marco, you'll get the correct answer. I just want to wait another hour to see whether someone can enlighten me about this

Sandro

Anonymous
Not applicable
Author

Oh, I just realized something else:

What I also need is to do this on a certain alternate state. As far as I can see the getCurrentSelections() function doesn't support set analysis, does it? Anyone has an alternative?

Sandro

IAMDV
Luminary Alumni
Luminary Alumni

Hi Sandro,

The reason why you get the same result is because you are using Count() function which returns total number of rows when there are no selection in the model. Please remember that aggregations are performed on full set of data when there are no selections. However, data is filtered when you make selections hence Count() would give the right number of values. To keep it simple…always remember that – No Selections in QlikView means Selecting All. I hope this makes sense.

Marco is right with that expression. However if you wanted to take this expression a step further where you wanted to check the selection state across all the fields in one Variable/Expression then use the below one…

vMySelectionState       =      =Concat('GetSelectedCount([' & $Field & '])', '+')

Then you can use $ (Dollar Sign Expansion) $(=vMySelectionState) to check if there are any selections in the entire application.

Note: Please include the “=” before the Concat function in the above expression.

I hope this helps!

Cheers,

DV

www.QlikShare.com

Anonymous
Not applicable
Author

Hey Deepak, thank you for the answer!

Let's say that the rule you gave me is something, that I can remember, but not something I can make a lot of sense off 😉

I understand the idea of the variable, that is dynamically evaluated as well. Will keep that concept in mind for later

But it also doesn't solve the problem I posted in my last message (you might not have seen that, yet). How to determine all this for a particular alternate state?

Sandro

Not applicable
Author

take this

examle

  CAMPO_CHEAK='A' or 'B'  or 'C'

SubStringCount(GetFieldSelections(CAMPO_CHEAK,';',63),'A')

IAMDV
Luminary Alumni
Luminary Alumni

Hi Sandro,

I understand this logic is counter Intuitive to how we (humans) think! However, consider this example where Count() & Sum() returning zero when there is no selection. So if the user logins into the application for the first time then he will see the results a Zero for every chart. Does that make sense? I don’t think it doesn’t make sense. QlikTech has to follow a path and to me they made logical decision with this behaviour.

To resolve your issue please try something like this…

if(GetSelectedCount(fieldName) > 0; Concat(distinct {$} fieldName, ','); '')

I hope this helps!

Cheers,

DV

IAMDV
Luminary Alumni
Luminary Alumni

Sandro - Did you try GetSelectedCount() function with your original expression?

Thanks,

DV

www.QlikShare.com