Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
lockematthewp
Creator II
Creator II

Formula Improvement

I currently have a bar chart with the following formula:

=Num(
if (getselectedcount([~Period]) <> 0,
(if(wildmatch(','&Concat([~Period],',') & ',','*,Jan,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jan$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Feb,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Feb$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Mar,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Mar$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Apr,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Apr$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,May,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}May$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Jun,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jun$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Jul,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jul$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Aug,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Aug$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Sep,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Sep$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Oct,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Oct$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Nov,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Nov$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Dec,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Dec$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Q1,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jan$+Feb$+Mar$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Q2,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Apr$+May$+Jun$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Q3,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jul$+Aug$+Sep$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Q4,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Oct$+Nov$+Dec$), 0)),
(if(wildmatch(','&Concat([~Period],',') & ',','*,Jan,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jan$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Feb,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Feb$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Mar,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Mar$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Apr,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Apr$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,May,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}May$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Jun,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jun$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Jul,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Jul$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Aug,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Aug$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Sep,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Sep$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Oct,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Oct$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Nov,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Nov$), 0)+
if(wildmatch(','&Concat([~Period],',') & ',','*,Dec,*')=1, Sum({<[~Data Classification(B)] = {'Applied Hrs'}>}Dec$), 0)))
,'#,##0.00')

However, this chart takes a while to load. I believe it has to do with the multiple nested 'if' statements. If any one can help me improve this formula I would greatly appreciate it.

(It just returns the Applied Hours for the selected period (month or quarter). If none are selected, it shows all months.)

 

 

6 Replies
jwjackso
Specialist III
Specialist III

Check out the P() Function.  

It will work better if you are using a calendar.  I'm not sure how you have the Jan$, Feb$ fields defined.  But using the P() function will return the rows that have the period selected or all rows if no period is selected.

 

Sum({<[~Data Classification(B)] = {'Applied Hrs'},[~Period]=P([~Period])>} AmtValue)

jwjackso
Specialist III
Specialist III

One other thing, Qlik evaluates every possible outcome of the IF statement.  It assumes that at some time every outcome will occur, so it caches the results.  When possible, don't use an IF statement.

lockematthewp
Creator II
Creator II
Author

Thanks for the help. Unfortunately I do not have a Period field with the months in it. Instead the values are listed as Jan$, Feb$, Mar$, etc. So each month is like its own separate field. Any other suggestions?

lockematthewp
Creator II
Creator II
Author

Actually, I do have a period field. But it is just for matching. For example, Period is Jan, Feb, Mar,.... and separately I have Jan$, Feb$, Mar$, ... all as separate fields. And I am not able to change the way this is set up as it is used in many other dashboards as well.

jwjackso
Specialist III
Specialist III

Well if possible, using the crosstable function to change the table layout may make your life a lot easier.

Brett_Bleess
Former Employee
Former Employee

If you are still searching for a solution, try the Design Blog area of Community as well, hundreds of how to and explanatory posts on different topics there that may be useful to you as well:

https://community.qlik.com/t5/Qlik-Design-Blog/bg-p/qlik-design-blog

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.