Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
srihitha
Contributor III
Contributor III

variable not resolving as expected

Hi , 

Can anyone pls help me with below code

I am getting error wen running below script.

There is some issue when i try to use these in load statement - $(vSelectMeasure),$(=vSelectMeasure)

I am trying to fetch minimum string of sales i,e; 150 by resolving the defined variable. 

Let vSelectMeasure ='=MinString(Sales)';

MyTable1: 
Load *,'$(vSelectMeasure)',$(vSelectMeasure),$(=vSelectMeasure);
Load * inline [
Dim, Sales
A, 150
A, 200
B, 240
B, 230
C, 410
C, 330 ];

Labels (1)
5 Replies
Davis69
Contributor III
Contributor III


@srihitha wrote: EmployeeConnection

Hi , 

Can anyone pls help me with below code

I am getting error wen running below script.

There is some issue when i try to use these in load statement - $(vSelectMeasure),$(=vSelectMeasure)

I am trying to fetch minimum string of sales i,e; 150 by resolving the defined variable. 

Let vSelectMeasure ='=MinString(Sales)';

MyTable1: 
Load *,'$(vSelectMeasure)',$(vSelectMeasure),$(=vSelectMeasure);
Load * inline [
Dim, Sales
A, 150
A, 200
B, 240
B, 230
C, 410
C, 330 ];


You are not the first, who fell into the famous "delayed expansion trap" (and you won't be the last).

You need delayed expansion if you want to use a variable, that you changed in the same block (a block is a series of commands within parentheses (and )).

Delayed variables are referenced with !var! instead of %var%.

Reason is the way, cmd parses the code. A complete line or block is parsed at once, replacing normal variables with their value at parse time. Delayed variables are evaluated at runtime.

srihitha
Contributor III
Contributor III
Author

Hi Davis ,

So what must be done  in my code to get the expected result as per delayed variable concept.

I tried this !$(vSelectMeasure)!  but, it did'nt work.

marcus_sommer

It's not really clear what do you want to do. Within the script you need in each case a load to aggregate data, maybe something like:

Set vSelectMeasure = Min(Sales);

MyTable1: 
Load Dim, num#(Sales) as Sales inline [
Dim, Sales
A, 150
A, 200
B, 240
B, 230
C, 410
C, 330 ];

MyTable2: 
load Dim, $(vSelectMeasure) as MinSales
resident MyTable1
group by Dim;

The benefit of the variable seems to be limited in a similar use-case ...

- Marcus

srihitha
Contributor III
Contributor III
Author

Hi Marcus ,

I just want to understand why below statement is not working in Mytable1.Should I always call a variable only inside resident table?

//Load Dim,$(vSelectMeasure) group by Dim;

Let vSelectMeasure ='=MinString(Sales)';
MyTable1:
Load Dim,$(vSelectMeasure) group by Dim;
Load * inline [
Dim, Sales
A, 150
A, 200
B, 240
B, 230
C, 410
C, 330 ];

 

marcus_sommer

By variables it depends how they are defined + where are they called + what contained the variable to which has the syntax to look like that they are working.

In the script is no possibility to aggregate loaded values outside from a load. And within the load there are only listings of fields and/or functions allowed but no '=' which caused your load-error.

- Marcus