Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Community,
i would like to join two tables to achive the result as shown in: Joint Table.
I am using two xlsx inputs to get the data.
Right now I'm using a simple join, and the result is, that I get a table like the Joint Table BUT for all of the companies which don't have a group assigned in Input Table Group table, i get back a "-" -> means the company group field isn't filled.
How to a setup a join to have the following result:
If a company group is assigned to the company it should set be included in the company group field.
If no company group is assigned to the company in the lookup table, it should use instead of an assigned company group the company na
Thanks,
Mathias
Joint Table | ||
Company | Revenue | Company Group |
T-Mobile US | 25,00 € | T-Mobile Group |
T-Mobile DE | 52,00 € | T-Mobile Group |
T-Mobile UK | 88,00 € | T-Mobile Group |
Vodafone DE | 65,00 € | Vodafone Group |
Vodafone Spain | 21,00 € | Vodafone Group |
Vodafone Italy | 256,00 € | Vodafone Group |
O2 Germany | 85,00 € | O2 Germany |
Eplus Germany | 21,00 € | Eplus Germany |
Mobitel Italy | 55,00 € | Mobitel Italy |
The input tables are:
Input Table Group | |
Company | Company Group |
T-Mobile US | T-Mobile Group |
T-Mobile DE | T-Mobile Group |
T-Mobile UK | T-Mobile Group |
Vodafone DE | Vodafone Group |
Vodafone Spain | Vodafone Group |
Vodafone Italy | Vodafone Group |
AND:
Input Table Revenue | |
Company | Revenue |
T-Mobile US | 25,00 € |
T-Mobile DE | 52,00 € |
T-Mobile UK | 88,00 € |
Vodafone DE | 65,00 € |
Vodafone Spain | 21,00 € |
Vodafone Italy | 256,00 € |
O2 Germany | 85,00 € |
Eplus Germany | 21,00 € |
Mobitel Italy | 55,00 € |
had a further throught you could use a mapping load:
group_map:
mapping LOAD Company,
[Company Group]
FROM
Book1.xls
(biff, embedded labels, table is Sheet2$);
main:
LOAD Company,
Revenue,
applymap('group_map',Company,Company) as [Company Group]
FROM
Book1.xls
(biff, embedded labels, table is Sheet1$);
Both have the same affect
Thanks
Steve
Hi once you have joined the table you could join the table back on itself using an isnull condition on the Group to create the final Company Group, something like :
main:
LOAD Company,
Revenue
FROM
Book1.xls
(biff, embedded labels, table is Sheet1$);
Join (main)
LOAD Company,
[Company Group] as temp_co
FROM
Book1.xls
(biff, embedded labels, table is Sheet2$);
Join (main)
load Company,Revenue,if( isnull(temp_co) ,Company,temp_co) as [Company Group]
resident main;
drop field temp_co;
Hi,
I'd use a mapping table if there is a unique value for each Company, although a JOIN would work as well using the Company field as key field.
RevenueTableMap:
MAPPING LOAD Company,
Revenue
FROM InputTableRevenue;
JointTable:
LOAD Company,
ApplyMap('RevenueTableMap', Company, 'Not found') AS Revenue,
"Company Group"
FROM InputTableGroup;
In its three parameter form, the ApplyMap() function takes the mapping table single quoted as the first parameter, the field which correspondence you want to get as the second parameter, and the third "Not found" in the case above, the default value should any value in the mapping table matches the current value for Company.
Hope that helps.
BI Consultant
had a further throught you could use a mapping load:
group_map:
mapping LOAD Company,
[Company Group]
FROM
Book1.xls
(biff, embedded labels, table is Sheet2$);
main:
LOAD Company,
Revenue,
applymap('group_map',Company,Company) as [Company Group]
FROM
Book1.xls
(biff, embedded labels, table is Sheet1$);
Both have the same affect
Thanks
Steve
Gentlemen; Thanks to all for your answers. I tried the last one of sbaldwin because here I understood the code most. It works fine. Thanks again.