Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

IF Statement really bugging me

Community,

I appreciate any assistance with this IF statement that has been bugging me for a while now.  I'm pretty new to this piece of QV and thank you in advance for any guidance.

IF ([Order Status]='Open' and [Order Date] <=Today-7,'0-7 Days', IF [Order Date] >Today-8<15, '8-14 Days', IF [Order Date]>Today-15<22,'15-21 Days', IF [Order Date] >Today-21 '22+Days')

Cheers!

Sharon

1 Solution

Accepted Solutions
richard
Partner - Creator
Partner - Creator

Try this. I used two intersections because your comparison is based on two fields: order status and order date.

 

IF([Order Status]='Open',
IF(
[Order Date] <= (Today()-7),'0-7 Days',
IF (
[Order Date] > (Today()-8) AND [Order Date]<(Today()-15), '8-14 Days',
IF (
[Order Date]>(Today()-15) AND [Order Date]<(Today()-22),'15-21 Days'))),
IF (
[Order Date] >Today()-21,'22+Days'))

View solution in original post

15 Replies
jpapador
Partner - Specialist
Partner - Specialist

If you are doing this in a script you have to close all of the if statements and name your field. Also I would just nest the if statement again and not use the AND at the beginning.  For example:

IF ([Order Status]='Open',

     IF([Order Date] <=Today-7,'0-7 Days',

          IF ([Order Date] >Today-8<15, '8-14 Days',

                IF ([Order Date]>Today-15<22,'15-21 Days',

                    IF ([Order Date] >Today-21 '22+Days'))))) as OrderDateBuckets

Every IF has it's own set of parenthesis at the beginning and then they all close at the end.

Also you syntax for the today command should be Today()-7,  You may even want to put it in parenthesis like so (Today()-7)

Not applicable
Author

Hi,

Can you plese post your sample file

rajeshvaswani77
Specialist III
Specialist III

You are almost there


IF ([Order Status]='Open' and [Order Date] <=(Today()-7),'0-7 Days', IF([Order Date] >(Today()-8<15), '8-14 Days', IF( [Order Date]>(Today()-15)<22,'15-21 Days', IF( [Order Date] >(Today()-21), '22+Days'))))


Braces for if if stetement and added () to Today().


Thanks,

Rajesh Vaswani


jagan
Partner - Champion III
Partner - Champion III

Hi,

Try this, missed brackets for Today

IF ([Order Status]='Open',

     IF([Order Date] <=Today()-7,'0-7 Days',

          IF ([Order Date] >Today()-8 AND [Order Date]<Today()-15, '8-14 Days',

                IF ([Order Date]>Today()-15 AND [Order Date]<Today()-22,'15-21 Days',

                    IF ([Order Date] >Today()-21,  '22+Days'))))) as OrderDateBuckets

Not applicable
Author

jpapdor,

I appreciate your help and guidance in re: to the ()'s.  I did add them after Today and additionally put the Today-7 in parens; sadly I am still receiving an error in my expression.  Am still trying to tweak and with your assistance feel I am much closer.  Thank you!

Not applicable
Author

Amuthabharathi,

I am unable to post a sample file due to confidentiality.  I'm sorry.  Thanks for your willingness to assist!

jpapador
Partner - Specialist
Partner - Specialist

Are you trying to do this in an expression in a chart or in the script editor?

Not applicable
Author

Rajesh,

This was definitely helpful but am still getting an error in the expression.  I think with your help and the other comments here that I am much closer.  i'll continue to work with it and let you know what works in the end.  Thanks so much!

Not applicable
Author

Jpapdor,

i am adding this into an expression for a chart.