Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
hariprasadqv
Creator III
Creator III

If statement in a variable of type LET

Hi All,

LOAD * INLINE [

    F1, F2, F3

    A, 23, 18

    B, 24, 12

    C, 25, 34

];

lET VT1=SUM(F2);

lET vT2=SUM(F3);

Let vt= if([F1]="A",VT1,vT2);

What is the wrong with the if statement;

1 Solution

Accepted Solutions
danieloberbilli
Specialist II
Specialist II

please find attached a revised version

Data:

LOAD * INLINE [

    F1, F2, F3

    A, 23, 18

    B, 24, 12

    C, 25, 34

];

sumtab:

LOAD

sum(F2) as F2sum,

sum(F3) as F3sum

Resident Data;

LET VT1 = Peek('F2sum');

LET VT2 = Peek('F3sum');

Result:

LOAD

sum(if([F1]='A', $(VT1),$(VT2))) as Result

Resident Data;

LET vt = Peek('Result');

View solution in original post

8 Replies
danieloberbilli
Specialist II
Specialist II

for the first part consider the script below. The if statement cant work as a variable can only store one value at a time.

Data:

LOAD * INLINE [

    F1, F2, F3

    A, 23, 18

    B, 24, 12

    C, 25, 34

];

sumtab:

LOAD

sum(F2) as F2sum,

sum(F3) as F3sum

Resident Data;

LET VT1 = Peek('F2sum');

LET VT2 = Peek('F3sum');

CELAMBARASAN
Partner
Partner

Field names are cannot use directly in the variables either it could use Peek or FieldValue

I hope your intention is different. Let me know whether below script helps you

T:

LOAD * INLINE [

    F1, F2, F3

    A, 23, 18

    B, 24, 12

    C, 25, 34

];

T1:

Load F1, If(F1='A', Sum(F2), Sum(F3)) AS VT

Resident T

Group By F1;

hariprasadqv
Creator III
Creator III
Author

Hi Daniel,

I want to pick only one value. And I have to display it in a Text Object.

danieloberbilli
Specialist II
Specialist II

please find attached a revised version

Data:

LOAD * INLINE [

    F1, F2, F3

    A, 23, 18

    B, 24, 12

    C, 25, 34

];

sumtab:

LOAD

sum(F2) as F2sum,

sum(F3) as F3sum

Resident Data;

LET VT1 = Peek('F2sum');

LET VT2 = Peek('F3sum');

Result:

LOAD

sum(if([F1]='A', $(VT1),$(VT2))) as Result

Resident Data;

LET vt = Peek('Result');

View solution in original post

anbu1984
Master III
Master III

You don't need variables in script. Try this expr in Text box

=If(Max(Aggr(Max(If(F1='A',1,0)),F1)) = 1,Sum(F2),Sum(F3))

Not applicable

Hi Hari,

I am going to help you. What is exact requirement...?

Not applicable

Hi Hari,

i think Daniel reply is help you...

Ramya

hariprasadqv
Creator III
Creator III
Author

Hi Ramya,

Daniel has resolved the issue.

Req; Summing coulmn of values based on another coulmn value.

Thank you.