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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to make a selection based on another selection (dynamically)

Hi guys,

I have the following problem: I have two listboxes: Code and Cost Center and I want when I make selection in Cost Center a several codes to be selected in Code list box.

I decided to make a macro:

sub SelectFirstLevelCodes

set CodeField = ActiveDocument.Fields("AccountCode")
set CostCenterFirstLevelField = ActiveDocument.Fields("CostCentersFirstLevel").getSelectedValues
for i=0 to CostCenterFirstLevelField.Count - 1

if CostCenterFirstLevelField.Item(i).Text="FirstCC" then
CodeField.Select "1*"
end if

if CostCenterFirstLevelField.Item(i).Text="SecondCC" then
CodeField.Select "2*"
end if

if CostCenterFirstLevelField.Item(i).Text="ThirdCC" then
CodeField.Select "3*"
end if
next
end sub

and it is working, except that I can select only one Cost Center. If I select two, Codes are selected only for the last selected CostCenter, not for both. How can I avoid this problem?

1 Solution

Accepted Solutions
Not applicable
Author

Hi there,

Luckas, I don't want to use a button with an action for selection. The idea is when I choose lets say FirstCC from a listbox in another listbox dynamically to be choosen let's say 100 values starting with 1 (100, 101, 102, etc.) I think that answers blase question, too. (May be blase didn't see the * after the digits)

I found a solution and it was to use "ToggleSelect", instead of "Select" and also had to add "CodeField.clear" before the loop so that it deselects the codes when I deselect the Cost Center.

View solution in original post

4 Replies
Not applicable
Author

Hi there,

can you please take a look at this post and let me know if this what you try to achieve?

http://community.qlik.com/forums/t/25932.aspx

Thanks.

Lukas

blaise
Partner - Specialist
Partner - Specialist

May I ask why you dont join an inline table to your data tables instead.


CostCenterLevel:
LOAD * INLINE [
CostCenterFirstLevel,CodeField
FirstCC,1
SecondCC,2
ThirdCC,3
];


Otherwise (using your code) try changing the .Select to .ToggleSelect. Make sure to do a Field.Clear first, above the loop.

Not applicable
Author

Hi there,

Luckas, I don't want to use a button with an action for selection. The idea is when I choose lets say FirstCC from a listbox in another listbox dynamically to be choosen let's say 100 values starting with 1 (100, 101, 102, etc.) I think that answers blase question, too. (May be blase didn't see the * after the digits)

I found a solution and it was to use "ToggleSelect", instead of "Select" and also had to add "CodeField.clear" before the loop so that it deselects the codes when I deselect the Cost Center.

blaise
Partner - Specialist
Partner - Specialist

Sorry for not seeing the wildcards. If you do a left(AccountCode,1) as key_AccountCode you can use my suggestion. Worth i try if the data is rather small or you do other "non qvd optimized" conversions.