# New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Highlighted
Contributor III

## If statement in a variable of type LET

Hi All,

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

## Re: If statement in a variable of type LET

please find attached a revised version

```Data:
F1, F2, F3
A, 23, 18
B, 24, 12
C, 25, 34
];

sumtab:
sum(F2) as F2sum,
sum(F3) as F3sum
Resident Data;

LET VT1 = Peek('F2sum');
LET VT2 = Peek('F3sum');

Result:
sum(if([F1]='A', \$(VT1),\$(VT2))) as Result
Resident Data;

LET vt = Peek('Result');
```
8 Replies
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:
F1, F2, F3
A, 23, 18
B, 24, 12
C, 25, 34
];

sumtab:
sum(F2) as F2sum,
sum(F3) as F3sum
Resident Data;

LET VT1 = Peek('F2sum');
LET VT2 = Peek('F3sum');
```
MVP

## 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:

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;

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.

Valued Contributor II

## Re: If statement in a variable of type LET

please find attached a revised version

```Data:
F1, F2, F3
A, 23, 18
B, 24, 12
C, 25, 34
];

sumtab:
sum(F2) as F2sum,
sum(F3) as F3sum
Resident Data;

LET VT1 = Peek('F2sum');
LET VT2 = Peek('F3sum');

Result:
sum(if([F1]='A', \$(VT1),\$(VT2))) as Result
Resident Data;

LET vt = Peek('Result');
```
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

Hi Hari,

Not applicable

Hi Hari,

Ramya

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.