3 Replies Latest reply on Apr 27, 2018 8:17 AM by Joe Oppelt

    Including a singular elseif then including it within another elseif?

    Richard L

      My Calculated field is not adding the way I expect it to.

       

      My second line below for 'Aerospace and Defense' uses a code of 3364 and the third line includes 'Advanced Manufacturing' which uses 33.

      It works great for the second line and calculates it correctly, but in the third line I would like to also include the same criteria '3364'and add it to this figure as well.

       

      IF LEFT([naics],2) = '52' THEN  'Advanced Business Services 52'
      ELSEIF LEFT([naics],4) = '3364' THEN 'Aerospace and Defense'
      ELSEIF LEFT([naics],2) = '31' OR LEFT([naics],2) = '32' OR LEFT([naics],2) = '33' THEN  'Advanced Manufacturing'
      ELSEIF LEFT([naics],3) = '621' OR LEFT([naics],3) = '622' OR LEFT([naics],3) = '623' THEN 'Bioscience and Healthcare'
      ELSE [naics] END
      

       

      My results show me:

      Advanced Business Services 52

      Aerospace and Defense

      Advanced Manufacturing

      Bioscience and Healthcare

      258

      6

      473

      127

       

      Without the second line in the calculation, Advanced Manufacturing catches the extra 6 and shows 479.

       

      If I change my third line to the following, this does not work either.

      ELSEIF LEFT([naics],2) = '31' OR LEFT([naics],2) = '32' OR LEFT([naics],2) OR LEFT([naics],4) = '3364'= '33' THEN  'Advanced Manufacturing'
      

       

       

      How can I have this broken out to display?

      Advanced Business Services 52

      Aerospace and Defense

      Advanced Manufacturing

      Bioscience and Healthcare

      258

      6

      479

      127

       

      Thank you!

        • 1. Re: Including a singular elseif then including it within another elseif?
          Joe Oppelt

          Standard evaluation practice for most software languages is that as soon as a TRUE condition is met, the rest of the  "IF" logic is ignored.  So as soon as your calc hits that '3364' clause, it's done and doesn't move on to the 3rd line.

           

          Further, you are essentially expecting your calc to return two different values for the same row:  one for '3364' and a different one for '33* '.  A calc only returns one value.

           

          If you want something counted in two different totals, make two separate calcs.

          • 2. Re: Including a singular elseif then including it within another elseif?
            Richard L

            Is it possible to do this outside of making another calculation?

             

            When I create the calculation  I have my original minus the line below on my Row

                 ELSEIF LEFT([naics],4) = '3364' THEN 'Aerospace and Defense'

             

            When I create another calculation and place it beside the above calculation in my row, it loses the formatting and lists each naics code individually.

            IF LEFT([naics],4) = '3364' THEN 'Aerospace and Defense' ELSE [naics] END

            • 3. Re: Including a singular elseif then including it within another elseif?
              Joe Oppelt

              You have to have two different calcs if you want the same row counted in two different totals.

               

              There is no way around that.  In fact, for what you are doing, you will need to have a calc for Aerospace and Defense, and another calc for Advanced Business Services 52, and another for Advanced Manufacturing, etc.

               

              // Aerospace and Defense Calc

              IF LEFT([naics],4) = '3364' THEN 1 END

               

               

               

              // Advanced Business Services 52 Calc

              IF LEFT([naics],2) = '52' THEN 1 END

               

               

               

               

              // Advanced Manufacturing Calc

              IF LEFT([naics],2) = '33' THEN 1 END

               

              Etc.

               

              Then SUM([Aerospace and Defense Calc]) will give you the count for that one.  And SUM([Advanced Manufacturing Calc]) will give you that count.  Etc.

               

              It's the only way to get one row to show up in two different counts like you want.