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"

19 Replies
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.

Not applicable
Author

How can I embed the above code in below one:

LOAD Region,

     District,

     Value

FROM

;

swuehl
MVP
MVP

Have you tried just using the same preceding load?

Preceding Load

Note that your Nulls in your input table should be empty values or NULL, not the text string 'Null' (that's why I used the Set NullInterpret as workaorund to read the text in as NULL).

Not applicable
Author

Thanks a lot for your help, it worked!!!

Not applicable
Author

I need to upgrade the below statement:

If(len(trim(Region))<>0 and len(trim(District))=0, Region,If(Len(Trim(Terr))=0 and Len(Trim(Region))<>0,District,Terr)) as NewCol

To

Region is not equal to null and district is null then copy region to NewCol

Secondly, Region is not equal to null and Terr is null then copy District value to that NewCol

Input Table

RegionDistrictTerrValue
Region 1NullNull1
Region 2District 1Terr12
NullNullNull3
Region 2District 1Null6

Output to be

 

RegionDistrictTerrValueNewCol
Region 1NullNull1Region 1
Region 2District 1Terr12
NullNullNull3
Region 2District 1Null6Region 2
Not applicable
Author

I need to upgrade the below statement:

If(len(trim(Region))<>0 and len(trim(District))=0, Region,If(Len(Trim(Terr))=0 and Len(Trim(Region))<>0,District,Terr)) as NewCol

To

Region is not equal to null and district is null then copy region to NewCol

Secondly, Region is not equal to null and Terr is null then copy District value to that NewCol

Input Table

RegionDistrictTerrValue
Region 1NullNull1
Region 2District 1Terr12
NullNullNull3
Region 2District 1Null6

Output to be

RegionDistrictTerrValueNewCol
Region 1NullNull1Region 1
Region 2District 1Terr12
NullNullNull3
Region 2District 1Null6District 1
swuehl
MVP
MVP

Your expected output is not matching your requirement in the last line

Region is not equal to null and district is null then copy region to NewCol

Secondly, Region is not equal to null and Terr is null then copy District value to that NewCol

Not applicable
Author

Just a sample, and also want to check one thing my below condition is giving blank value in NewCol:

LOAD *,

           If(len(trim(Region))=0 , Region) as Newcol

  

FROM

;

Not applicable
Author

I have written below condition for the above requirement but it's not working:

       If(len(trim(Region))<>0 and len(trim(District))=0, Region,If(Len(Trim(District))<>0 and Len(Trim(Terr))=0 and Len(Trim(Region))<>0,District)) as NewCol

swuehl
MVP
MVP

'Not  working' is not a good issue description.

If possible, upload a small sample input file that shows all possible combinations of conditions to check and a table that exactely shows your expected result.

A sample output that is not matching your written requirements is not helping much (is the expected output incorrect? or the written requirements?).

The input file is needed to check the range of possible field values and NULL handling issues.