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.

markgraham123
Not applicable

If statement -> Loop

Hi all,

I'm using If statement to filter out the data into buckets.

I was wondering whether the same can be achieved by Loop concept.

Any help is highly appreciated.

LOAD *,

If(

([Fiscal Week]>=1 and [Fiscal Week]<=4), 1,

If(

([Fiscal Week]>=5 and [Fiscal Week]<=8), 2,

If(

([Fiscal Week]>=9 and [Fiscal Week]<=12), 3,

If(

([Fiscal Week]>=13 and [Fiscal Week]<=16), 4,

If(

([Fiscal Week]>=17 and [Fiscal Week]<=20), 5,

If(

([Fiscal Week]>=21 and [Fiscal Week]<=24), 6,

If(

([Fiscal Week]>=25 and [Fiscal Week]<=28), 7,

If(

([Fiscal Week]>=29 and [Fiscal Week]<=32), 8,

If(

([Fiscal Week]>=33 and [Fiscal Week]<=36), 9,

If(

([Fiscal Week]>=37 and [Fiscal Week]<=40), 10,

If(

([Fiscal Week]>=41 and [Fiscal Week]<=44), 11,

If(

([Fiscal Week]>=48 and [Fiscal Week]<=52), 12)))))))))))) as [Fiscal Month];

6 Replies
sunny_talwar
Not applicable

Re: If statement -> Loop

What exactly do you mean when you say loop concept?

richard_chilvers
Not applicable

Re: If statement -> Loop

What happens to weeks 45 - 47 ?

Or perhaps they can't exist?

markgraham123
Not applicable

Re: If statement -> Loop

Hi Richard,

Sorry for the confusion.

Let me re post the question with application atatched.

Thanks for your response.

markgraham123
Not applicable

Re: If statement -> Loop

Sunny,

Sorry for the confusion.

Let me re post the question with application atatched.

Thanks for your response

marcus_sommer
Not applicable

Re: If statement -> Loop

Instead of using such a nested if-loop could the use of class(), pick(match()) or a mapping be better alternatives. Whereby I would suggest to create the fiscal month within a fiscal-calendar:

Fiscal Year

Fiscal Calendar with Non-Standard Days (Not 1-31)

- Marcus

richard_chilvers
Not applicable

Re: If statement -> Loop

Its worth noting that the nested IF is processed in sequence, so it could be tidied up as follows and becomes a bit more obvious to anyone trying to understand the script:

LOAD *,

If( [Fiscal Week]<=4), 1,

If( [Fiscal Week]<=8), 2,

If( [Fiscal Week]<=12), 3,

If( [Fiscal Week]<=16), 4,             etc...........

However, my question above related to why there is a gap in the sequence.