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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
daturpin
Partner - Creator II
Partner - Creator II

How to store concatenated list of selected values in a variable

In my App, I have ships, and these ships have a lot of data but right now I am working with their names and their ID numbers (all my tables have ID numbers GENERATED ALWAYS AS IDENTITY in SQL tables)

I am trying to create a button which will assign some number of ships to a list to pass to Databricks, and I select those ships from within a Map which, for the user, displays the ship_name of each ship on the map in their appropriate location (latitude, longitude are also data points)

I have created a variable 'ships_stacked', and I want that variable to store a comma-separated aggregate of all selected ship ID numbers.

The expression I have working is:
=if(match(GetFieldSelections(unit_name), unit_name), [units_id-units_id))

Which I parse as "if the selected ship's unit name is X, and that matches X in the table, then return the units_id "(which links a bunch of tables, hence the 'units_id-units_id')

Problem is that it only works if I select ONE and ONLY ONE ship on the map. I know that I need to use some sort of aggregate function to return more than one selected units_id, but I have been working on it for four hours and can't figure out how to make it work.

Please, come someone point me in the right direction?

Labels (3)
1 Solution

Accepted Solutions
cristianj23a
Partner - Creator III
Partner - Creator III

Hi Daturpin.

From your description, it seems like you're looking for a way to aggregate multiple selected ship IDs into a comma-separated string. In Qlik, the Concat function can be used to create such a string.

The Concat function concatenates all values of a field into a string. So you could create a variable that contains all selected ship IDs like this:

=Concat({<unit_name = p(unit_name)>} [units_id-units_id], ',')

In this expression, {<unit_name = p(unit_name)>} is a set expression that selects all currently selected unit_names. p(unit_name) returns the possible values of unit_name in the current selection state, and <unit_name = p(unit_name)> restricts the set to those possible values.

Then, Concat concatenates the corresponding units_id-units_id values for the selected unit_names into a comma-separated string.

The resulting string can be stored in the ships_stacked variable. With this setup, the ships_stacked variable should contain a comma-separated list of all selected ship IDs, regardless of the number of selected ships.

This is just a general guide, so you might need to adjust the expression based on your specific data model and requirements.

Regarts.

 
https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.

View solution in original post

2 Replies
cristianj23a
Partner - Creator III
Partner - Creator III

Hi Daturpin.

From your description, it seems like you're looking for a way to aggregate multiple selected ship IDs into a comma-separated string. In Qlik, the Concat function can be used to create such a string.

The Concat function concatenates all values of a field into a string. So you could create a variable that contains all selected ship IDs like this:

=Concat({<unit_name = p(unit_name)>} [units_id-units_id], ',')

In this expression, {<unit_name = p(unit_name)>} is a set expression that selects all currently selected unit_names. p(unit_name) returns the possible values of unit_name in the current selection state, and <unit_name = p(unit_name)> restricts the set to those possible values.

Then, Concat concatenates the corresponding units_id-units_id values for the selected unit_names into a comma-separated string.

The resulting string can be stored in the ships_stacked variable. With this setup, the ships_stacked variable should contain a comma-separated list of all selected ship IDs, regardless of the number of selected ships.

This is just a general guide, so you might need to adjust the expression based on your specific data model and requirements.

Regarts.

 
https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.
daturpin
Partner - Creator II
Partner - Creator II
Author

Excellent, thank you!

The only modification is that, for some reason, it was returning duplicates of each units_id selected, like

1,1,2,2,3,3,7,7

So I added a distinct marker:

=Concat({<unit_name = p(unit_name)>} distinct[units_id-units_id], ',')

and it returns 1,2,3,7 just as I wanted!