Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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)";
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)
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)";
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;
Thanks for the Reply.
Able to make.