5 Replies Latest reply: Jun 10, 2016 4:45 PM by Praveen Kumar Konda RSS

    If Else in Qliksense Expression

    Praveen Kumar Konda

      Hello All,

       

      Can some one help me out whats wrong with this below if else . Default View logic is not working as it gives ' - ' instead of number.

      Quick help will be really appreciated.

       

      Regards,

      PK

       

       

      //Only Region

      If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Region)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

      max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,Region={$(=concat(DISTINCT chr(39) & Region & chr(39),','))}>} Noofevents),

       

       

      //Only Group

      If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Group)=1 and GetSelectedCount(Region)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

      max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,Group={$(=concat(DISTINCT chr(39) & Group & chr(39),','))}>} Noofevents),

       

       

      //Only Org

      If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Org)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Region)=0 and  GetSelectedCount(Customer)=0,

      max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,Org={$(=concat(DISTINCT chr(39) & Org & chr(39),','))}>} Noofevents),

       

       

      //Only Customer

      If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Customer)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Region)=0,

      max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,Customer={$(=concat(DISTINCT chr(39) & Customer & chr(39),','))}>} Noofevents),

       

       

      //Quarter and Region

      If(GetSelectedCount(QuarterFormat)=1 and GetSelectedCount(Region)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

      max({<Region={$(=concat(DISTINCT chr(39) & Region & chr(39),','))}>} Noofevents),

       

       

       

       

      //Default View

      If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Region)=0 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

      max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,DataCategory = {'Global Lam Research'},Region = {'Lam Research'}>} Noofevents),

       

       

      //Quarter and Group

      If(GetSelectedCount(QuarterFormat)=1 and GetSelectedCount(Group)=1 and GetSelectedCount(Region)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

      max({<Group={$(=concat(DISTINCT chr(39) & Group & chr(39),','))}>} Noofevents),

       

       

       

       

      //Quarter and Org

      If(GetSelectedCount(QuarterFormat)=1 and GetSelectedCount(Org)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Region)=0 and  GetSelectedCount(Customer)=0,

      max({<Org={$(=concat(DISTINCT chr(39) & Org & chr(39),','))}>} Noofevents),

       

       

       

       

       

       

      //Quarter and Customer

      If(GetSelectedCount(QuarterFormat)=1 and GetSelectedCount(Customer)=1 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Region)=0,

      max({<Customer={$(=concat(DISTINCT chr(39) & Customer & chr(39),','))}>} Noofevents),Max(Noofevents) )

       

       

      ))))))))

        • Re: If Else in Qliksense Expression
          Sunny Talwar

          Have you tested each single expression and it works? Troubleshooting a big expression can be simplified by breaking down into pieces. If possible share a sample with the expected output

            • Re: If Else in Qliksense Expression
              Praveen Kumar Konda

              Yes i had tested this and Default view expression is the culprit and trying to figure out why....The one i have shared above is the actual expression that has been used.

                • Re: If Else in Qliksense Expression
                  Sunny Talwar

                  By sample I meant your application

                  • Re: If Else in Qliksense Expression
                    Stefan Wühl

                    I vaguely remember some issues in Sense with lengthy expressions and nested if(), not sure if this might also cause your issue.

                     

                    Just to clarify:

                    - All other conditions work as expected when you select e.g values in Region, Org, Customer?

                     

                    - The only condition that is not working correctly is you default view, no selections made?

                     

                    - Using this as single expression e.g. in a KPI object does return a number?

                     

                    =If(GetSelectedCount(QuarterFormat)=0 and GetSelectedCount(Region)=0 and GetSelectedCount(Group)=0 and GetSelectedCount(Org)=0 and  GetSelectedCount(Customer)=0,

                    max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,DataCategory = {'Global Lam Research'},Region = {'Lam Research'}>} Noofevents)

                    )

                     

                    If not, using this as single expression does return a number?

                     

                    =max({<YearOfData={'$(=Max(YearOfData))'} ,QuarterOfData = {'All'} ,DataCategory = {'Global Lam Research'},Region = {'Lam Research'}>} Noofevents)

                     

                    If not, you do actually have records for Noofevents when making selections in the fields stated in the set analysis with given values? And these records show numbers that can be aggregated using Max()?

                     

                    As Sunny already asked for, if you still can't make it work, post a sample QVW.

                    There are too many unknowns to give a solid answer.