Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
brijesh1991
Valued Contributor

multiply a field by -1 at script level in qlikview

Hi All,

I had a problem in multiplying a field value by -1 at script level, look at my script, it's not working.

Example:

My data in backend is like this:

ID Amount

1 -800

2 700

3 -900

4 1000

5 -400

Whenever I am fetching data from backend and storing it into qvd,

In QVD, Amount  should multiply by -1

My script is:

Table1:

Load

ID,

(Amount*(-1)) as Amount

From SchemaName.TableName;

Store Table1 into [../Data/Qvd/Table1.Qvd](qvd);

In QVD, Data should be like this:

ID Amount

1 800

2 -700

3 900

4 -1000

5 400

Your feedback is precious to me. . .

Brijesh

1 Solution

Accepted Solutions
brijesh1991
Valued Contributor

Re: multiply a field by -1 at script level in qlikview

Hi er.mohit,

if(Amount>0,Amount*-1, Amount*-1) as Amount <--- it will make positive to negative and negative to positive. . . I have tried this, but why I can't do in this way--> Load ID, -1*Amount as Amount from........??

Thanks

9 Replies
MVP
MVP

Re: multiply a field by -1 at script level in qlikview

Change the name of your newly created Amount field name:

Like:

Load

Amount*(-1) as NewAmount

Sokkorn
Honored Contributor

Re: multiply a field by -1 at script level in qlikview

Hi Brijesh,

Your script should work. Can you post error load msg and full script here?

Regards,

Sokkorn

brijesh1991
Valued Contributor

Re: multiply a field by -1 at script level in qlikview

Thanks Sokkorn Cheav (Cambodia) for your efforts. . .

There is no error, just I am getting the same data as it was without multiplying by -1 even though we are applying the operator there. . .

Sokkorn
Honored Contributor

Re: multiply a field by -1 at script level in qlikview

Hi Brijesh,

Let try this one

Table1:

Load

ID,

Num(Amount)*-1 as Amount

From SchemaName.TableName;

Let me know the result.

Regards,

Sokkorn

brijesh1991
Valued Contributor

Re: multiply a field by -1 at script level in qlikview

Thanks for your time, tresesco ...

it's working while we are using this in INLINE, but when we are fetching data from backend i.e we are using it with select or load statement, it's not working. . .

MVP
MVP

Re: multiply a field by -1 at script level in qlikview

Can you share your sample application?

er_mohit
Honored Contributor II

Re: multiply a field by -1 at script level in qlikview

have you tried this

if(Amount>0,Amount*-1) as Amount

brijesh1991
Valued Contributor

Re: multiply a field by -1 at script level in qlikview

Hi er.mohit,

if(Amount>0,Amount*-1, Amount*-1) as Amount <--- it will make positive to negative and negative to positive. . . I have tried this, but why I can't do in this way--> Load ID, -1*Amount as Amount from........??

Thanks

MVP
MVP

Re: multiply a field by -1 at script level in qlikview

Brijesh,

PFA. it works even with LOAD. may be there is something wrong in your app. if you can share,,,,,,can be checked.

Community Browser