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: 
Qlik_here
Contributor II
Contributor II

How to append tables inside set expression

Hi there,

I am planning to first extract 25% from each of the following subsets of a table:

  • Table 1 - if group variable = 1
  • Table 2 - if group variable = 2
  • Table 3 - if group variable = 3

Then I would like to append the 3 tables. I am having trouble finding a way to append inside set expression.

Is there a function that can do this for me? Please advice!

Many thanks in advance!

Labels (3)
5 Replies
Lisa_P
Employee
Employee

Can you give a sample to play with ?

Qlik_here
Contributor II
Contributor II
Author

Sorry I don't have any samples, I am just looking for a function that can append the following tables (Replacing the + sign)

aggr(Only({$<group={'1'}>}Name) + aggr(Only({$<group={'2'}>}Name) + aggr(Only({$<group={'3'}>}Name

marcus_sommer

What is the aim behind your question? Usually such things needs to be done within the datamodel and I assume that's the case for you, too.

- Marcus

Qlik_here
Contributor II
Contributor II
Author

I am looking to have a random sampling of N amounts (based on user input) from each of the 3 groups and show the final result in a table

marcus_sommer

Like hinted I doubt that there is really a practicable way to do it directly with any function within the UI and also not with different tables. If I had such a task I would probably go in the following direction by merging the data within a single table and precalculating an appropriate flag, like:

t4: load *, mod(recno(), 100) + 1 as Flag from t1;
concatenate(t4) load *, mod(recno(), 100) + 1 as Flag from t2;
concatenate(t4) load *, mod(recno(), 100) + 1 as Flag from t3;

With it each source will be divided into 100 parts. The users could now within the UI select the group value which they like and the parts from 1 to 100 to get a more or less random sub dataset from the entire dataset. IMO there is rather no way to get a totally ramdomly dataset - whereby you could extend the logic by switching from recno() to rowno() and/or using both in some way and/or pre-loading the data and applying various sorting picking any available field and assigning it to a variable which is then used within an order by statement mayby with:

let var = pick(ceil(rand()*20), 'Field1', 'Field2', ...);

and then:

load * from X order by [$(var)];

You may also combine multiple fields and adding another logig for asc/desc ...

- Marcus