Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
don_qlikview
Creator
Creator

Help with If condition

Hello Everyone,

I am writing the following expression in the script

Load A,
B,
C,
Amount,
if(Sum[Amount] = 0, null(), Sum([Amount]),
D,
E,
F

FROM
ABC.xlsx.

It says invalid expression. Can anyone tell what am I doing wrong?

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

You are getting syntax error because of missing group by statement.

Kindly provide your actual statement...

It should be something like below

Load A,
B,
C,
//Amount,
if(Sum[Amount] = 0, null(), Sum([Amount]),
D,
E,
F

FROM
ABC.xlsx

Group by A, B, C, D, E, F

or May be

Use as below, considering that you want to group by only one field A

=================

Load A, B, C, Amount, D, E, F From TableName;

Load A, If(Sum(Amount) = 0, Null(), Sum(Amount)) as TotalAmount Resident TableName Group By A;

==============================

Hope this helps...

View solution in original post

9 Replies
Not applicable

In your expression, you are not wrapping the Sum and If function with ()


if(Sum[Amount] = 0, null(), Sum([Amount]),


try:


if(Sum(Amount) = 0, Null(), Sum(Amount)),

vgutkovsky
Master II
Master II

Depends on what you are trying to summarize "Amount" over. You're either trying to just check the value of "Amount" on the line you're on, or you're trying to get a sum of "Amount" over certain dimensions. Which is it?

don_qlikview
Creator
Creator
Author

Hi Vlad,

I want to get the Sum(Amount) over a field called Week.


don_qlikview
Creator
Creator
Author

This does not work

Anonymous
Not applicable

can i have your clear requirement??

if(condition   , A(if cond. true), B(if cond. false) )..this is the syntax.....check urs

...

vgutkovsky
Master II
Master II

Then you'd need a GROUP BY statement (which only works from a RESIDENT load):

data:

LOAD

         Week,

         Amount,

         A,

         B,

FROM

...

data2:

LOAD

         Week,

         sum(Amount) as Amount

RESIDENT data

GROUP BY Week

;

If you have a more specific problem, please post more specifics 🙂

Vlad

MK_QSL
MVP
MVP

You are getting syntax error because of missing group by statement.

Kindly provide your actual statement...

It should be something like below

Load A,
B,
C,
//Amount,
if(Sum[Amount] = 0, null(), Sum([Amount]),
D,
E,
F

FROM
ABC.xlsx

Group by A, B, C, D, E, F

or May be

Use as below, considering that you want to group by only one field A

=================

Load A, B, C, Amount, D, E, F From TableName;

Load A, If(Sum(Amount) = 0, Null(), Sum(Amount)) as TotalAmount Resident TableName Group By A;

==============================

Hope this helps...

Anonymous
Not applicable

you missed ")"..

don_qlikview
Creator
Creator
Author

This helps.. Thanks!!!