Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Compare number of orders for selected and previous year, based on an orderdate.

Hi,

I need to compare the number of orders for the selected and previous year, based on an OrderDate (e.g. 1-1-2018 = year 2018) as I have no OrderYear field.

I have created the following variables:

vSelectedOrderYear = GetFieldSelections(Year(OrderDate))

vPreviousOrderYear = GetFieldSelections(Year(OrderDate)-1)

And the following expressions:

Selected year=count({<OrderDate={$(vSelectedOrderYear)}>} distinct (Orderkey))

Previous year=count({<OrderDate={$(vPreviousOrderYear)}>} distinct (Orderkey))

However result is 0.

I also tried to create the OrderYear via the script:

Year(OrderDate) as OrderYear

and with the expression:

Selected year=count({<[OrderYear]={'$(=OrderYear)'}>} DISTINCT[OrderKey])

Previous year=count({<[OrderYear]={'$(=Year(OrderYear)-1)'}>} DISTINCT[OrderKey])

Then I have the correct result for the selected year but no results for the previous years.

Can you please help me? Thanks in advance.

Regards,

Marielle

3 Replies
sunny_talwar

Try this for previous year

Previous year =Count({<[OrderYear]={'$(=Max(OrderYear)-1)'}>} DISTINCT[OrderKey])

Anonymous
Not applicable
Author

Unfortunately, then the count for both years is equal:

sunny_talwar

Would you be able to share a sample to show the issue?