Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Best way to calculate a new field

I have two .qvw : GetData.qvw (load data from SQL DB creating qvd) and ShowData.qvw (load data from qvd and prepare data to be presented).

In the SQL DB there are two tables that I import creating two distinct qvd(s): table1.qvd and table2.qvd.

In the ShowData.qvw I have to load the two qvd(s)

Table1:

(

Key,

A,

)

Table2:

(

Key,

B,

….

)

In the ShowData.qvw I would have a calculated field C = A-B, for all the rows in Table1 (left join).

I did as follow:

Table:

LOAD

Key,

A,

From table1.qvd;

Left join

LOAD

Key,

B,

….

From table2.qvd;

NewTable:

LOAD *

C=A-B

Resident Table;

And it works, but I'm not sure that this is the best way to do it as it requires loading the data a second time in order to do the calculation.

Can someone help?

Many Thanks

2 Replies
swuehl
MVP
MVP

Here is an alternative approach:

MAP:

MAPPING LOAD

Key,

B

From table2.qvd;

Table:

LOAD

Key,

A,

A - applymap('MAP',Key) as C

From table1.qvd;

Not applicable
Author

Thanks for the suggestion, the problem is that tables have more than two fields. If I understood well how the map works, I can'use it as Tables1 and Tables2 have more fields.

Many Thanks, Martina