Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Tatalay2021
Contributor II
Contributor II

Eliminating if statement in expressions

Hello,

I have several expressions that use if statements, where two different set analysis calculations are performed based on field selection count. Is there a way to rewrite this expression without using an if statement?

 

=if(count(getfieldselections([TestFIeld1]))=0,num(FABS(SUM({1<Year={"=GetFieldSelections(Year)"},Scenario={'X'},[TestFIeld1]-={'Retail'}>}Sales))/1000000,'###,###.#'),num(FABS(SUM({1<Year={"=GetFieldSelections(Year)"},Scenario={'X'},[TestFIeld1]=$::[TestFIeld1]>}Sales))/1000000,'###,###.#'))

Thanks,

1 Solution

Accepted Solutions
Anil_Babu_Samineni

GetFieldSelections() will not give when you use aggregate, rather you can try this way

=if(GetSelectedCount(TestField1)=0,num(FABS(SUM({1<Year={"=GetFieldSelections(Year)"},Scenario={'X'},[TestFIeld1]-={'Retail'}>}Sales))/1000000,'###,###.#'),num(FABS(SUM({1<Year={"$(=Concat(DISTINCT Chr(39) & Year & Chr(39), '',''))"},Scenario={'X'},[TestFIeld1]=$::[TestFIeld1]>}Sales))/1000000,'###,###.#'))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful

View solution in original post

3 Replies
Anil_Babu_Samineni

GetFieldSelections() will not give when you use aggregate, rather you can try this way

=if(GetSelectedCount(TestField1)=0,num(FABS(SUM({1<Year={"=GetFieldSelections(Year)"},Scenario={'X'},[TestFIeld1]-={'Retail'}>}Sales))/1000000,'###,###.#'),num(FABS(SUM({1<Year={"$(=Concat(DISTINCT Chr(39) & Year & Chr(39), '',''))"},Scenario={'X'},[TestFIeld1]=$::[TestFIeld1]>}Sales))/1000000,'###,###.#'))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Tatalay2021
Contributor II
Contributor II
Author

Thanks for your feedback!

I should have stated this in my original post but the motivation behind this post was given what I have read elsewhere in the community about if statement impacting performance. Thus, I was trying to understand if the expression I listed is one of those situation that would need to be rewritten without including if statement. But as I think about it more perhaps that may not be applicable in this situation as I am essentially two different evaluations based on the applicable condition.

Nevertheless, I appreciate your input and will consider giving it a try in my next work.

Thanks,

Anil_Babu_Samineni

First of all, I don't see any performance issue. did you? 

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful