Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Storing selection into qvd

Hi,

     I'm new to qlik view.I'm using records from teradata.I'm having some list boxes I need to store only the selected values from the list box into a new qlikview document on clicking the button object at the same time only the selected values should be displayed in teradata too(using select staement).Please help me out in solving this.Thanks in advance.

23 Replies
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi there,

You don't need to have a macro, you can just place the code in the variable.  In order to deal with multiple selections the code will need to be a touch more complex, something like:

=if(GetSelectedCount(cust_id) > 0,

'WHERE cust_id IN (' & chr(39) & Concat(DISTINCT cust_id, chr(39) & ',' & chr(39) ) & chr(39) & ')',

'')

If you create a variable called vWhere and then paste the code above into it, your select script would then need to be:

LOAD cust_id,

     cust_name,

     cust_type

FROM

C:\Users\<User>\Documents\cust_type.xlsx

(ooxml, embedded labels, table is Sheet1)

$(vWhere)

;

The variable would get a little more complex still if you have multiple fields, as you would need to decide by looking at the selected count of each whether you needed to include WHERE and AND statements.

The reduce data approach that I described above with the reduce data would probably be simpler though.

Steve

tresesco
MVP
MVP

Two points:

  • write WHERE (cust_id = $(s)); as WHERE cust_id = $(s);   // remove extra parenthesis
  • getting retunred value from macro in script you have to declare a function properly, read: Re: Calling VB script macro from load script
Not applicable
Author

Hi Steve,

        I done as you suggest above by using variable .

LOAD V_Id AS V,

     Start as s,

     End as e

FROM

C:\Users\387805\Documents\date_visit.xlsx

(ooxml, embedded labels) $(V1);

Got error like this.va.PNG.png

And also, the selected values should be stored in qvd only after cliking the  button object.

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Check the contents of the variable - you may have a space in front of the equals sign.  It is critical that the very first character is the =.

Not applicable
Author

I checked for blank space in front of equals sign but still getting the same error.One thing I want to be clear that Should I assign this code

=if(GetSelectedCount(cust_id) > 0,

'WHERE cust_id IN (' & chr(39) & Concat(DISTINCT cust_id, chr(39) & ',' & chr(39) ) & chr(39) & ')',

'')

to variable using variable overview or action (set variable) in button properties? because button has to be clicked inorder to store the current selection to the qvd file.

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Place it in to the variable using the Variable Overview.  You can then check the variable by pasting it into a text box on the desktop using this code:

=$(V1)

You should see the correct WHERE statement appear.

This solution does not need buttons or actions.

Not applicable
Author


Only if I assigned GetFieldSelection() to variable V1 , I can see the selected value through text box.

And not able to see the result of the below expression through text box. I dont have any idea about correct WHERE statement.

if(GetSelectedCount(V_Id) > 0,
'WHERE V_Id IN (' &
chr(39) & Concat(DISTINCT V_Id  & chr(39) & ',' & chr(39) ) & chr(39) & ')',
'')

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

The syntax for the variable is correct.  Please see the attached example.

You get the following when you multi select values:

AutoBuldWHere.png

Steve

nizamsha
Specialist II
Specialist II

Hi Steve

I cant get  u can u post two qvd so that i can understand clearly .what i understand in this post is if i select value in one qvw the selected value should display in another qvw kindly post a qvw

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Nizam - that's not what this is trying to achieve.  The remit was to make selections in a list box and then do a reload - only pulling in the selected values.

It is possible to pass selections into other documents, if you create an Action (on a button, perhaps) to open another QlikView app you can chose to send the selection across.  Obviously this depends on the two applications having the same data model.