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: 
CuriousGeorge
Contributor II
Contributor II

GetFieldSelections for year

I have the original code as such and it works: 

if(GetFieldSelections([Product]) = 'A', avg(123), if(GetFieldSelections([Product]) = 'B', avg(525), avg(346)))

 

However, now I need to add an additional field selections for year and it doesn't work. It just not able to recognize this field name. I tried with/without '2022', but still didn't work. 

if(GetFieldSelections([Product]) = 'A' and GetFieldSelections(Year(Date))='2022', avg(123), if(GetFieldSelections([Product]) = 'B' and GetFieldSelections(Year(Date))='2022', avg(525), avg(346)))

 

Labels (5)
3 Replies
CuriousGeorge
Contributor II
Contributor II
Author

I just tried this - NUM(Year(date#(GetFieldSelections(CreatedDate),'YYYY')))

but it is not working too. 

sasikanth
Master
Master

Try this, 

=if(GetFieldSelections([Product]) = 'A' and Year(GetFieldSelections( Date))='2022', avg(123), if(GetFieldSelections([Product]) = 'B' and  Year(GetFieldSelections( Date))='2022', avg(525), avg(346)))

( OR )

=if(GetFieldSelections([Product]) = 'A' and

Year(Date(Date#(GetFieldSelections(Date),'DDMMYYYY'),'DDMMYYYY'))='2022', avg(123),

if(GetFieldSelections([Product]) = 'B' and 

Year(Date(Date#(GetFieldSelections(Date),'DDMMYYYY'),'DDMMYYYY'))='2022',  avg(525),  avg(346)))

 

If there is any format issue, better to fix it at script level and use option1 to get desired result

 

Thanks, 

Sasi

marcus_sommer

Why not just creating appropriate period-fields within the calendar and accessing them directly where needed instead of doing all the converting/formatting stuff by each call again and again.

- Marcus