7 Replies Latest reply on Apr 17, 2019 9:01 AM by Don Wise

    Calculation by attribute

    Salma Mirza

      Hi

      I have a question that I'll lay out piece by piece.

      1. My data set has a dimension, say Customer Type (Type 1, Type 2, Type 3)

      2. I want to create a calculation Yield by each customer  (basically seeing how much profit I'm making out of each Type)

      3. I want a table that shows Yield by Type.

      4. If the Yield by Type 3 is less than Yield by Type 2, I want the Yield font to be red.

       

      Help!

        • 1. Re: Calculation by attribute
          Don Wise

          Hello Salma,

           

          You'll get more and better responses with some fake/mock data in an actual Tableau Workbook. 

           

          Best, Don

          • 2. Re: Calculation by attribute
            Salma Mirza

            Thank you Don,

            I'm attaching a twbx file and elaborating a little more.

             

            1. My dataset has a dimension, Year (Fall 2017, Fall 2018, Fall 2019). I know, it should be a date field when I call it year, but its a text field because I am specifying it based on seasons.

            2. I want to create a calculation Yield by each year (basically seeing how many customer out of all the 32 that we reached out to, made a purchase; see Yield calculated field in the twbx file )

            3. I want a table that shows Yield by Year. Up until this point it is easy

            4. This is the main question; If the Yield Fall 2019 is less than Yield in Fall 2018, I want it's font to be red, if not, then blue.

             

            I've experimented with If statements in the calc field (If Year = Fall 2019, then "calculated Yield....) and then pulling it in into Color Mark, but it tells me that i cannot combine aggregate and non-aggregate functions.

             

            I would really appreciate your help.

             

            thanks

            • 3. Re: Calculation by attribute
              Don Wise

              Hi Salma,

              There's a couple of methods in this workbook.  Hope it helps.  Best, Don

               

              Method 1 uses PREVIOUS_VALUE to look backwards one row (Fall 2018):

              Screen Shot 2019-04-12 at 6.45.13 PM.png

              Method 2 uses the normal Quick Calculation to LOOKUP the previous row and determine if it's less than 0 then it's below otherwise it's above.  FIRST() allows you to change the color for Fall 2017.  If you don't want that, then simply remove the FIRST() clause.

              Screen Shot 2019-04-12 at 6.45.24 PM.png

              1 of 1 people found this helpful
              • 4. Re: Calculation by attribute
                Salma Mirza

                Thank you Don,

                 

                This really helps. I used the 2nd method and color-coded it and it works. I modified the formula to specify that if Fall 2019 Yield is 0.5 less than Fall 2018, it should be red.

                 

                IF FIRST()=0 THEN 'first year' ELSEIF

                LOOKUP(ZN([Yield]), -1)-ZN([Yield]) >0.5 THEN 'Below' ELSE 'Above' END

                 

                I am trying to refine it further because essentially I am only concerned with Fall 2019 falling below Fall 2018. I'm not bothered if the Fall 2018 Yield is less than Fall 2017 as its old news. I tried the following modification in the calculation. Does it seem like its working?

                IF FIRST()=0 THEN 'first year'

                ELSEIF First ()=-1 then 'second year'

                ELSEIF First ()=-2

                And LOOKUP(ZN([Yield]), -1)-ZN([Yield]) >0.5 THEN 'Below' ELSE 'Above' END

                 

                 

                Thank you so much for your help

                 

                Salma

                • 5. Re: Calculation by attribute
                  Don Wise

                  Hi Salma,

                  Minor modification to get your new revised formula to get to your red color:

                  Screen Shot 2019-04-16 at 7.34.17 AM.png

                  If this answers your question please mark it as correct so that others may find it in their search for a solution in the future.  Best, Don

                  • 6. Re: Calculation by attribute
                    Salma Mirza

                    This is really helpful Don. Thank you very much.

                    There's an additional piece to this (pls do let me know if I should't continue here and instead open a new question. I'm putting it here because it is related).

                    If we have further groupings besides "Year" , say "Industry", how can I apply the same conditional formatting. Essentially, I want to compare Fall 2019,  Industry 3 Yield with Fall 2018,  Industry 3 Yield, and if the Fall 2019 is less than Fall 2018, I want the Yield value to be turned red. I would like to replicate it for Industry 1 and 2.  I used the existing color calc field and it seems to be comparing Fall 2017 Industry 3 with Fall 2017 Industry 3.

                    Thank you

                    • 7. Re: Calculation by attribute
                      Don Wise

                      Hi Salma,

                      In that case, then you'd lose 'First Year' and 'Second Year' as those values would conflict with what you're trying to do.  The calculation also needs to be changed and is more simplified to what it was before.  However, requires the setting of Table Calc settings to work.  Please see the screenshot below.  Right-click the Color Table Calc and select Edit Table Calc.  Then set the settings as shown in the screenshot, or in the attached.  As this is an added question, if you'd mark it as helpful?  Best, Don

                      Screen Shot 2019-04-17 at 8.56.58 AM.png

                      1 of 1 people found this helpful