Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

Year selection in list box not showing result in text object.

Hi,

I do have below field in my app.

PeriodSales
2021006100
2021005200
2020011300
2020009400

 

In order to extract year, current year and pervious year from Period field I've created below expressions and stored in a variable.

vPeriod=Year(Date#(Period,'YYYYMM'))

vPeriodCurrent=(Num(Year(today(vPeriod))))

vPeriodLast=(Num(Year(today(vPeriod))-1))

So now I'm using the below formulae to get pervious year and current year sales when user selects year from list box, but it is displaying '0' when ever user selects year.

=if(vPeriod=vPeriodCurrent,Sales,0)

vikasshana_1-1630164242770.png

Regards,

Vikas

1 Reply
stevejoyce
Specialist II
Specialist II

I would recommend you evaluate your variables by themselves and see if they are returning the results you want.

Couple things that are an issue:  Selecting Year of Period is going to result in multiple period values, so this wouldn't work and isn't what you are trying to do.

To make it easier, add Year in your data model, so you can eliminate your listbox being a calulated field and be able to use set analysis.

-> either add in your initial data load when loading period/sales, or join in


left join (table)
load
Period,
Year(Date#(Period, 'YYYYMM'))as Year
resident table;

 

now your variables, can be set in load script but this will take into account user selections:

set vMaxYear = =max(Year);

set vPreviousYear = =max(Year)-1;

 

Now your KPI calculation is: sum({<Year = {$(vMaxYear)} >}Sales)