Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Union tables.

Hello,

I am not able to present these two tables,

Motorista_1Motorista_2Motorista_3Valor_1Valor_2Valor_3
JoseJoseJose103050
JoaoJoaoJoao204060
Marcos10


as follows:

MotoristaValor_1Valor_2Valor_3
Jose103050
Joao204060
Marcos10


Could someone help?



3 Replies
Not applicable
Author

That does not look like a fun data set, very un-Kimball. Depending on how much more complicated the real data is than the sample, something like this may work:

NamesTemp:
LOAD * INLINE [
Motorista_1,Motorista_2,Motorista_3
Jose,Jose,Jose
Joao,Joao,Joao
,Marcos,
];
ValuesTemp:
LOAD * INLINE [
Valor_1,Valor_2,Valor_3
10,30,50
20,40,60
,10,
];
FullTable:
LOAD RowNo() As FakeKey,
If(Len(Motorista_1)>0, Motorista_1,
If(Len(Motorista_2)>0, Motorista_2, Motorista_3)) As Motorista
RESIDENT NamesTemp;
JOIN LOAD RowNo() As FakeKey, *
RESIDENT ValuesTemp;
DROP TABLE NamesTemp;
DROP TABLE ValuesTemp;
DROP FIELD FakeKey;


Anonymous
Not applicable
Author

Thanks for the reply, but failed. If you add two different names in the first two fields of the table NamesTemp he considers only the first field the other name of the second field does not return.

Not applicable
Author

Your sample didn't include any records like that. You have different names in one record in that table? If so, you'll need to load each column separately. You may be able to use a cross table, but creating three tables would also work.

Here's a load that should work:

NamesTemp:
LOAD * INLINE [
Motorista_1,Motorista_2,Motorista_3
Jose,NewGuy,Jose
Joao,Joao,Joao
,Marcos,
];
ValuesTemp:
LOAD * INLINE [
Valor_1,Valor_2,Valor_3
10,30,50
20,40,60
,10,
];
Comb1:
LOAD RowNo() As FakeKey, Motorista_1 As Motorista
RESIDENT NamesTemp
WHERE Len(Motorista_1) > 0;
JOIN LOAD RowNo() As FakeKey, Valor_1
RESIDENT ValuesTemp
WHERE Valor_1 > 0;
Comb2:
LOAD RowNo() As FakeKey, Motorista_2 As Motorista
RESIDENT NamesTemp
WHERE Len(Motorista_2) > 0;
JOIN LOAD RowNo() As FakeKey, Valor_2
RESIDENT ValuesTemp
WHERE Valor_2 > 0;
Comb3:
LOAD RowNo() As FakeKey, Motorista_3 As Motorista
RESIDENT NamesTemp
WHERE Len(Motorista_3) > 0;
JOIN LOAD RowNo() As FakeKey, Valor_3
RESIDENT ValuesTemp
WHERE Valor_3 > 0;
DROP TABLE NamesTemp;
DROP TABLE ValuesTemp;
DROP FIELD FakeKey;