Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

Condition in back ground scripting


Hi.  Below is an extract of my scripting.

Its basically bringing  Sales quantity, Sales Value, Cost of Sales per Item per per Customer per Month.

LOAD

[Sales Qty],
[INCOME],
[COS],

[Financial Year],
[Calendar Month],
[Item Code],
[Customer Code]

FROM

[\\ELL-QVW-001\Qlikview\Qlikview Models\QVD\Pol - ELLDAT\Transactions.qvd]
(
qvd)

In our data source, there were certain values which was incorrectly process and therefore i want to correct this in the scripting.

For eg, say,  Item Code, ABC,  in Calendar month, Jan 2014 , Customer , 'John Smith',  the Cost of Sales (COS) was incorrectly processed by an extra $40 000.  How do i create a script that decrease the Cost of Sales by $40 000 for this item for that month.

Is this correct?   If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', [COS]= -40000)

or do i use a 'where statement' at the end?

Thanks

kind regards

Nayan


,

1 Solution

Accepted Solutions
MVP
MVP

Re: Condition in back ground scripting

Try like:

If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', -40000, [COS] ) as  [COS]

Update(Thanking Joe): If you want the value to be reduced by 40000, then try:

If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', [COS]-40000, [COS] ) as  [COS]

14 Replies
MVP
MVP

Re: Condition in back ground scripting

Try like:

If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', -40000, [COS] ) as  [COS]

Update(Thanking Joe): If you want the value to be reduced by 40000, then try:

If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', [COS]-40000, [COS] ) as  [COS]

Not applicable

Re: Condition in back ground scripting

Hi Nayan,

first thing I would say is, you should not be making this change in your QV script, always try to get data fixed at source for you to read in.

Saying that if you absolutely have to do this then the below should work for you. This is assuming you have a single row for the item/month/customer/COS combination

LOAD

[Sales Qty],
[INCOME],
If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', [COS]-40000,[COS]) As [COS],

[Financial Year],
[Calendar Month],
[Item Code],
[Customer Code]

FROM

[\\ELL-QVW-001\Qlikview\Qlikview Models\QVD\Pol - ELLDAT\Transactions.qvd]
(
qvd)

hope that helps

Joe


konstantin
Contributor III

Re: Condition in back ground scripting

you can do it directly for the column

LOAD

[Sales Qty],
[INCOME],

If ([item Code]='ABC' and Calendar Month='Jan 2014' and Customer Code='John Smith', [COS]= -40000, COS) as [COS],

[Financial Year],
[Calendar Month],
[Item Code],
[Customer Code]

FROM

[\\ELL-QVW-001\Qlikview\Qlikview Models\QVD\Pol - ELLDAT\Transactions.qvd]
(
qvd)

Not applicable

Re: Condition in back ground scripting

that will replace the COS with -40k rather than reduce won't it?

Not applicable

Re: Condition in back ground scripting

Hi

Thank you for the reply.  will try it and reload and let you know.

kind regards

Nayan

MVP
MVP

Re: Condition in back ground scripting

Yes, now I go through the post entirely(which I don't usually when it's a bit lenghty) , I just saw his line and wanted to reproduce similar.

Not applicable

Re: Condition in back ground scripting

ha no worries, just checking it wasn't my early morning brain playing tricks

Not applicable

Re: Condition in back ground scripting

Hi Joe

I cannot change the data, hence i have to change it in the scripting.  Yes, i do have a single row

I will try your scripting changes and let you know the outcome.

Thank you for reply.

kind regards

Nayan

Not applicable

Re: Condition in back ground scripting

haha