Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
satishkurra
Specialist II
Specialist II

Sales Flag in script

Hi

I'm trying to create a flag for Sales > 0 and < 0 as below in the script.

But it is displaying as Invalid Expression on reload.

Can someone help me what went wrong?

LOAD

ID,

Sales,

If(Sum(Sales) > 0, 1,0) as SalesFlag;

SQL SELECT * FROM ......

1 Solution

Accepted Solutions
MarcoWedel

In case you only want a flag per individual sales value / row of your source table, one solution might be:

LOAD ID,

        Sales,

        Sign(Sales) as SalesFlag;

SQL SELECT * FROM ......

or

LOAD ID,

          Sales,

          If(Sales, 1, 0) as SalesFlag;

SQL SELECT * FROM ......

hope this helps

regards

Marco

View solution in original post

9 Replies
sunny_talwar

Try this:

Table:

LOAD ID,

          Sales;

SQL SELECT * FROM ......


Left Join (Table)

LOAD ID,

          If(Sum(Sales) > 0, 1, 0) as SalesFlag

Resident Table

Group By ID;

Colin-Albert

To use an aggregation expression in your load script, you must include a group by clause.

sunindia shows how you can do this.

satishkurra
Specialist II
Specialist II
Author

Can we include SET ANALYSIS in above Sum(Sales) in script window?

Also the above is still throwing error

satishkurra
Specialist II
Specialist II
Author

Seems like i have the SQL statement and it is not supporting to use it.

I will use Preceding Load before this and see if i can achieve this?

satishkurra
Specialist II
Specialist II
Author

I tried different way, it is not working, Can someone help me to achieve this using SET expression in script window?

satishkurra
Specialist II
Specialist II
Author

I tried different way, it is not working, Can someone help me to achieve this using SET expression in script window?

sunny_talwar

There is not set analysis in the script. You can use ifs or Where statements to restrict things. Do you know what you are restricting?

satishkurra
Specialist II
Specialist II
Author

I'm basically restricting the sales <0 and > 0

MarcoWedel

In case you only want a flag per individual sales value / row of your source table, one solution might be:

LOAD ID,

        Sales,

        Sign(Sales) as SalesFlag;

SQL SELECT * FROM ......

or

LOAD ID,

          Sales,

          If(Sales, 1, 0) as SalesFlag;

SQL SELECT * FROM ......

hope this helps

regards

Marco