Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
Highlighted
hariprasadqv
Contributor 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;

Tags (2)
1 Solution

Accepted Solutions
danieloberbilli
Valued Contributor II

Re: If statement in a variable of type LET

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
Valued Contributor II

Re: If statement in a variable of type LET

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');

Re: If statement in a variable of type LET

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
Contributor III

Re: If statement in a variable of type LET

Hi Daniel,

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

danieloberbilli
Valued Contributor II

Re: If statement in a variable of type LET

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
Honored Contributor III

Re: If statement in a variable of type LET

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

Re: If statement in a variable of type LET

Hi Hari,

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

Not applicable

Re: If statement in a variable of type LET

Hi Hari,

i think Daniel reply is help you...

Ramya

hariprasadqv
Contributor III

Re: If statement in a variable of type LET

Hi Ramya,

Daniel has resolved the issue.

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

Thank you.