Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Hello everyone, What is wrong in this Script?.

Hello Everyone,

I am writing a script like as follows:

table1:

LOAD * INLINE [

    Product, Production

    Bread, 120

    Butter, 130

    Milk, 100

    Curd, 140

];

data:

LOAD

Product,

Product as abc

resident table1;

store data into E:\Poornima\data.qvd(qvd);

let v1=if(Product='Bread',Production,0);

set v2="$(v1)";

the purpose of which is to set a variable v2 with the value v1 which stores the value of production of product bread.

Is there any other way to do it?.

Thanks in advance and Regards.

1 Solution

Accepted Solutions
Not applicable
Author

use below script;

 

table1:

LOAD * INLINE [
Product, Production
Bread, 120
Butter, 130
Milk, 100
Curd, 140

]
;

data:
LOAD
Product,
Product as abc
resident table1;


store data into E:\Poornima\data.qvd(qvd);

Variable:
LOAD FirstValue(Production) as Value
Resident table1 Where Product = 'Bread' Group By Product;

let v1
=Peek('Value');

set  v2="$(v1)";

View solution in original post

4 Replies
Not applicable
Author

so the let v1=if(Product='Bread',Production,0); is within the Load script??

If so, there are so many different product, v1 will not able to have a correct value.

If you want a field to identify the "Bread". what you can do is at the 2nd part of script add in the condition:

LOAD

Product,

Product as abc

if(Product='Bread',Production, Null()) As BreadProd

resident table1;

So when you want to get Bread's production just do : =Only({1} BreadProd)

Not applicable
Author

use below script;

 

table1:

LOAD * INLINE [
Product, Production
Bread, 120
Butter, 130
Milk, 100
Curd, 140

]
;

data:
LOAD
Product,
Product as abc
resident table1;


store data into E:\Poornima\data.qvd(qvd);

Variable:
LOAD FirstValue(Production) as Value
Resident table1 Where Product = 'Bread' Group By Product;

let v1
=Peek('Value');

set  v2="$(v1)";

sushil353
Master II
Master II

Hi,

Problem is your if condition to calculate the v1 variable... it has to iterate over the table...

try the below code:

table1:

LOAD * INLINE [

    Product, Production

    Bread, 120

    Butter, 130

    Milk, 100

    Curd, 140

];

data:

LOAD

Product,

Product as abc

resident table1;

store data into data1.qvd(qvd);

Temp:

load Product as Product_1,Production as Production_1

Resident table1

Where Product='Bread' ;

let v1=Peek('Production_1',0,'Temp');

set v2=$(v1)

HTH

Sushil

set v2=$(v1);

DROP Table Temp;

Not applicable
Author

Thanks for the Reply.

Able to make.