8 Replies Latest reply: Jan 18, 2013 10:13 AM by Deepak Vadithala RSS

    count(...) if no values selected

    Sandro Krumbein

      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

        • Re: count(...) if no values selected
          marco masin

           

          Use this

          GetFieldSelections(CAMPO,';',100)

            • Re: count(...) if no values selected
              Sandro Krumbein

              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

                • Re: count(...) if no values selected
                  Deepak Vadithala

                  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

                    • Re: count(...) if no values selected
                      Sandro Krumbein

                      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

                        • Re: count(...) if no values selected
                          Deepak Vadithala

                          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

                          • Re: count(...) if no values selected
                            Deepak Vadithala

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

                             

                            Thanks,

                            DV

                             

                            www.QlikShare.com

                      • Re: count(...) if no values selected
                        Sandro Krumbein

                        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