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

Help - Set expression in straight table

Hi,

I have a requirement to create the result as below from table 1 and table 2

 

Table 1
Veh Cost
A20000
B25000
C26000
D

27000

Table 2
VehComparetoVeh
AA
BA
CB
DC

     

Result
VehComparetoVehCost of Vehcost of ComparetoVehDelta
AA20000200000
BA25000200005000
CB26000250001000
DC27000260001000
5 Replies
Anonymous
Not applicable

Have you tried:

Step 1 - load table 1

Step 2 - make a mapping load with resident table 1 (Veh, Cost)

Step 3 - left join table 2 to table 1, (comparetoVeh), ApplyMap(step2), Cost-ApplyMap(step2)

Anonymous
Not applicable

Table1:

LOAD * INLINE [

Veh,Cost

A,20000

B,25000

C,26000

D,27000

];

Let rowcount=NoOfrows('Table1');

Trace (1) Table 1 size: $(rowcount);

MappingCost:

Mapping Load

    Veh,Cost

Resident Table1;

Let rowcount=NoOfrows('Table1');

Trace (2) Table 1 size: $(rowcount);

Left Join (Table1)

LOAD * INLINE [

Veh,ComparetoVeh

A,A

B,A

C,B

D,C

];

Let rowcount=NoOfrows('Table1');

Trace (3) Table 1 size: $(rowcount);

Left Join (Table1)

Load

    Veh,

    ApplyMap('MappingCost', ComparetoVeh, 0) as [cost of ComparetoVeh],

    Cost - ApplyMap('MappingCost', ComparetoVeh, 0) as Delta

Resident Table1;

Let rowcount=NoOfrows('Table1');

Trace (4) Table 1 size: $(rowcount);

petter
Partner - Champion III
Partner - Champion III

You could achieve this by unpivoting the second table by using crosstable prefix on the load statement - then it is simple to use set expressions to do the calculations in a (straight) table:

2018-07-15 11_01_04-Compare Vehicles _ Data load editor - Qlik Sense.png

2018-07-15 11_01_18-Microsoft Store.png

g_santhosh86
Contributor
Contributor
Author

Thanks.

petter
Partner - Champion III
Partner - Champion III

Please mark the approritate answer as correct to close this thread