Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Concatenate two data sources using condition

I want to concatenate two tables using below conditions and create a new column while concatenating:

          table 1 - when region  is null                          concatenate                   table 2 - when region is not null and district is null

Add new column XYZ with all values as - XYZ                                        Add new column - Region with values that of region column

Replace "Null" value of region column by "All"                                                            Replace region column values by value  "All"

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Set NullInterpret = 'Null';

LOAD 'ALL' as Region,'ALL' as District, Value,

  If(len(trim(Region))=0, 'ALL',If(Len(Trim(District))=0,Region,'Territory')) as NewRegion;

LOAD * INLINE [

Region District Value

Null Null 19

Null Null 5

Null Null 8

Null Null 11

Region 1 Null 1

Region 2 Null 5

Region 3 District 1 10

] (delimiter is '\t');

I hope you see how you can check for NULL in the different input fields and then create a logic upon this.

View solution in original post

19 Replies
swuehl
MVP
MVP

Could you post two small sample input tables and your expected result?

Not applicable
Author

                  Table 1
Region DistrictValue
NullNull19
NullNull5
NullNull8
NullNull11
Region 1null1
Region 2null5

Condition is somewhat like this "where region is null OR (Region is not null and district is null)" add new column and replace region and district both null with value 'All' and if region is not null then add that value in new column

Output

 

Output
Region DistrictValue New Column
NullNull19All
NullNull5All
NullNull8All
NullNull11All
Region 1null1Region 1
Region 2null5Region 2
Kushal_Chawda

try this

LOAD *,

         if(len(trim(Region))=0 and len(trim(District))=0 ,'All',

         if(not isnull(Region),Region)) as NewColumn

...

FROM atble

swuehl
MVP
MVP

Something like

Set NullInterpret = 'Null';

LOAD *,

  If(len(trim(Region))=0, 'ALL',Region) as NewRegion;

LOAD * INLINE [

Region District Value

Null Null 19

Null Null 5

Null Null 8

Null Null 11

Region 1 Null 1

Region 2 Null 5

] (delimiter is '\t');

I haven't full got your second condition:

OR (Region is not null and district is null)" add new column and replace region and district both null with value 'All'

your result table seems not to demonstrate this

Not applicable
Author

The above will add new column and add value 'All' in the column, but when value is not null in region column and in district column value is null then I want regions to be picked e.g.,

Region          District

Region 1         Null

Region 2        District 1

Null               Null

Null               Null

Null               Null

Output should be

Region     District     New Column

All     All     Region 1

All     All     Region 2

All     All     All

All     All     All

All     All     All

swuehl
MVP
MVP

As far as I see, you don't really care about District column, you only look after Region, right?

Set NullInterpret = 'Null';

LOAD 'ALL' as Region,'ALL' as District, Value,

  If(len(trim(Region))=0, 'ALL',Region) as NewRegion;

LOAD * INLINE [

Region District Value

Null Null 19

Null Null 5

Null Null 8

Null Null 11

Region 1 Null 1

Region 2 Null 5

Region 3 District 1 10

] (delimiter is '\t');

Not applicable
Author

Sorry my mistake,

When Region is Null then in new column show value 'ALL', when region is not null and district is null then show value of 'REGION COLUMN'

Replace region and district column with value 'ALL'

Region          District

Region 1         Null

Region 2        Null

Null               Null

Null               Null

Null               Null

Output should be

Region     District     New Column

All     All     Region 1

All     All     Region 2

All     All     All

All     All     All

All     All     All

swuehl
MVP
MVP

What if both Region and District are not Null?

Not applicable
Author

Then in new column the value should be Territory.