Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
joeybird
Creator III
Creator III

peek or pervious when simular number

hi

I am trying to see if next number is lower than the next...but I am having issues when it sees the first number or next

I have tried both expressions

if((Sales)< peek(sales),'1','0') as flag

if((Sales)< previous(sales),'1','0') as flag

basically

Month 1 , sales = 10     ...flag = 1

Month 2,  sales = 9.8   ... flag = 1

Month 3,  sales = 9.9  ....flag =  0

Month 4  Sales = 9.9   ... flag = 0

Month 5  Sales = 15   .... flag = 0

how can I make Month 1 flag be 0?

please help

1 Solution

Accepted Solutions
ramoncova06
Specialist III
Specialist III

are your months strings or numbers ?

if they are string, then try adding a number and apply the sort on a descending way, peek or previous should work as long as you use the same field name, like Jonathan already suggested

View solution in original post

7 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Is the field Sales or sales - QV field names are case sensitive.

The correct syntax would be:

If(Sales < Alt(previous(Sales), 0), 1, 0) as flag,



Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable

Hi

Please find the attachement of QVF of your requirement ..

Note : I am assuming   'Sales' as field name ...

joeybird
Creator III
Creator III
Author

hi

I have tried both and both give me same answer I have been getting

any other ideas please?

Mark_Little
Luminary
Luminary

HI,

You need to make sure you data is orders by the month,

Then you Can do something like

IF(RowNo() = 1,

    0,

     IF(Sales < previous(Sales),

          1,

          0

          )

     ) as flag,

If you have multiple years you can add a check for year in a similar fashion

Mark

ramoncova06
Specialist III
Specialist III

are your months strings or numbers ?

if they are string, then try adding a number and apply the sort on a descending way, peek or previous should work as long as you use the same field name, like Jonathan already suggested

joeybird
Creator III
Creator III
Author

Hi guys

still a problem,

I am loading in from SQL tables

I have tried order by month too

I have even tried

Num(replace(Sales, ' ', '')) as Sales... to make sure it sees a number field

I am guessing its rounding the figure? because its decimal places?

please help

joeybird
Creator III
Creator III
Author

Hi

after some testing ..it only works, if field is cast as an int ...not numeric

thanks guys for your help x