Combine to Fields in one Qlik Sense Filter

487 Views Asked by At

I have 2 Fields and I need to combine them in one field. Is it possible to get this result in Qlik Sense?

Fileds and Results

I do not want concatenate but get the result in table

2

There are 2 best solutions below

0
On

It's not particularly clear what the source is and how the data is structured, but you can JOIN without a key to flatten. Example:

[t1]:
LOAD * INLINE [
Activity
A
B];

[t2]:
LOAD * INLINE [
"Activity Code"
A01
B02];

[final]:
LOAD
    [Activity] AS [value]
RESIDENT [t1];

JOIN([final])
LOAD
    [Activity Code] AS [value]
RESIDENT [t2];

DROP TABLES [t1],[t2];

This will result in a table with the structure of:

value
A
B
A01
B02
0
On

Levi's should be accepted as the answer but I just wanted to point out another option, which is to use the CrossTable() prefix, which can be used to "pivot" the values of 2 or more columns into a single column. This method can be useful if the columns you need to combine are already in a single table.

The script you can use in the Data Load Editor may look like this:

[Table 1]:
Load * Inline [
Activity    ,   Activity Code
A           ,   A01
B           ,   A03
C           ,   A05
D           ,   B02
E           ,   B06
            ,   B03
            ,   C01
            ,   C03
            ,   C08
            ,   D24
            ,   D21
            ,   D30
            ,   E11
            ,   E15
            ,   E22
];


[Pivoted table]:
CrossTable ([throwaway 1], [Combined], 1)
Load
    1 as [throwaway 2]
  , [Activity]
  , [Activity Code]
Resident [Table 1];

Drop Fields [throwaway 1], [throwaway 2];

[Table 1] is just the data as it appears in your screenshot. Below that, the [Pivoted table] is a table that loads three fields:

  • 1 as [throwaway 2] - this is so that we have at least one qualifier field, or unchanged dimension, to group the combined columns on (see the Qlik Help page on the CrossTable prefix to read more about why this is needed). I named it [throwaway 2] because we won't need it after this.
  • [Activity] - One of the columns we want to combine.
  • [Activity Code] - The other column we want to combine.

The CrossTable() is going to result in an attribute field called [throwaway 1] (so named because we won't need it after this) and a data field called [Combined], which will be our new combined field!

After we load this, our results are just what we'd expect:

Screenshot of Qlik Sense table with results of CrossTable prefix