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

Join the same Field located in two different tables

Hello,

I have a table with the calculated Dimension 'KPI', as below:

rafakmargos_0-1669054201272.png

And I have another table with the calculated Dimension 'KPI' to another dates, as below:

rafakmargos_1-1669054315087.png

 

How can I do to join this two tables using the same Dimension 'KPI' and keeping the quantity of records?

I tried to concatenate the both tables, but it duplicates the Dimension 'Date'.

Labels (3)
1 Solution

Accepted Solutions
Dalton_Ruer
Support
Support

If you don't care about keeping the dates with blank KPI values then when you load the first table simply add a where clause to leave the blank rows behind, then you will be able to concatenate the second table. 

DataTable:

Load

Date,

KPI,

Value

From {whatever file or source for your first table}

Where Not IsNull(KPI);

 

It looks from your example like the values would be NULL. But you can adjust at times in the event you have blanks, or spaces etc as needed. 

The above will work with concatenate for your second table, assuming you don't have duplicate dates in your second table. So now let's consider the duplicates situation. If there can/will be duplicates, and the second table is what you want to keep, then load them first. And then do a concatenate load for the first table with a clause that appends only the rows from the first table that do not already exist. 

Where Not Exists(Date);

 

Here is some example code where I use INLINE to create the two dummy sources and I show how you use the exists clause in cases where you are aliasing fields. Notice that I'm saying if the value in Field1 that I'm loading from the first source doesn't already exist as a Date value. 

Source1:
Load * Inline [
Field1, Field2, Field3
1/1/2022, 1, 399
2/1/2022, 1, 300
3/1/2022, 1, 100
4/1/2022,, 0
5/1/2022,, 5
];

Source2:
NoConcatenate Load * Inline [
Field1, Field2, Field3
3/1/2022,1,200
4/1/2022,1,500
5/1/2022,1,150
6/1/2022,1,100
];

MyDataTable:
Load
Field1 as Date,
Field2 as KPI,
Field3 as Value
Resident Source2;

Concatenate Load
Field1 as Date,
Field2 as KPI,
Field3 as Value
Resident Source1
Where Not Exists(Date, Field1);

Drop Table Source1;
Drop Table Source2;

Data modeling can be so much fun. I've been a Qlikkie now for 13 years and I still revel in the fact that in Application 1, I can use 1 technique and when the users for Application 2 provide crazy different requirements I can use a totally different technique. 

View solution in original post

4 Replies
Dalton_Ruer
Support
Support

Looking at your 2 different tables the big question for me is whether you need the blank KPI values for dates that are not in the second table? For example you have 9/1/2022 and 10/1/2022 in both the first and second table with NO KPI values. Do you need to retain those to show no value, or is it ok to leave them behind? 

Next question ... if you have values for the Value field in table 2 that are different from the values in table 1 for the Value field do you need them both, or will you want to keep the first or the second values?

Happy to help you model but those questions are going to be what drives my suggested technique. 

rafakmargos
Contributor III
Contributor III
Author

Dalton,

About the first question: it's ok to leave the blank values behind.

About the second question: It'll not happen to have two different KPI values to the same Date.

Buuut, even if it happens, I would keep the last value. (the second).

Thanks for you help!

Dalton_Ruer
Support
Support

If you don't care about keeping the dates with blank KPI values then when you load the first table simply add a where clause to leave the blank rows behind, then you will be able to concatenate the second table. 

DataTable:

Load

Date,

KPI,

Value

From {whatever file or source for your first table}

Where Not IsNull(KPI);

 

It looks from your example like the values would be NULL. But you can adjust at times in the event you have blanks, or spaces etc as needed. 

The above will work with concatenate for your second table, assuming you don't have duplicate dates in your second table. So now let's consider the duplicates situation. If there can/will be duplicates, and the second table is what you want to keep, then load them first. And then do a concatenate load for the first table with a clause that appends only the rows from the first table that do not already exist. 

Where Not Exists(Date);

 

Here is some example code where I use INLINE to create the two dummy sources and I show how you use the exists clause in cases where you are aliasing fields. Notice that I'm saying if the value in Field1 that I'm loading from the first source doesn't already exist as a Date value. 

Source1:
Load * Inline [
Field1, Field2, Field3
1/1/2022, 1, 399
2/1/2022, 1, 300
3/1/2022, 1, 100
4/1/2022,, 0
5/1/2022,, 5
];

Source2:
NoConcatenate Load * Inline [
Field1, Field2, Field3
3/1/2022,1,200
4/1/2022,1,500
5/1/2022,1,150
6/1/2022,1,100
];

MyDataTable:
Load
Field1 as Date,
Field2 as KPI,
Field3 as Value
Resident Source2;

Concatenate Load
Field1 as Date,
Field2 as KPI,
Field3 as Value
Resident Source1
Where Not Exists(Date, Field1);

Drop Table Source1;
Drop Table Source2;

Data modeling can be so much fun. I've been a Qlikkie now for 13 years and I still revel in the fact that in Application 1, I can use 1 technique and when the users for Application 2 provide crazy different requirements I can use a totally different technique. 

rafakmargos
Contributor III
Contributor III
Author

@Dalton_Ruer ,

 

Thank you so much for your help.

I was able to solve the problem that I had.