2 Replies Latest reply on May 2, 2018 9:01 PM by Andrew Lemon

    Plotting a line in Tableau

    Andrew Lemon

      Hello Tableau Community,

      I hope this message finds you well.

      I have a quick question - is there a way to plot a line similar to the one below?

      This line represents the acceptable discount that sales has agreed to. I would plot on a scatter graph all our transactions - all transactions above the line is discounted too high, and below the line is considered a positive.

       

      I would love to use this line to have Tableau count the number of transactions above the invoice and below.

      Has anyone done something similar? Any ideas as to how I can complete this task?

       

      Thanks for your time!

      Line.png

        • 1. Re: Plotting a line in Tableau
          swaroop.gantela

          Andrew,

           

          Here's one method that might give an idea.

          If there are set breakpoints, you could write an equation for each section:

           

          In the workbook attached in the Forum thread,

          I plotted  Log (Sales) vs. Discount and line breakpoints were

          1 -- 0, 10 -- 10%, 100 -- 25%, 1000 -- 30%, 10000 -- 60%

           

          So the calculated field first picks out the range,

          calculates the line slope, multiplies the x-offset log(sales), adds a y-offset:

          IF [Sales]>1 AND [Sales]<10 THEN LOG(Sales)*0.1

          ELSEIF [Sales]>10 AND [Sales]<100 THEN ((0.25-0.1)/(LOG(100)-LOG(10)))*(LOG([Sales])-LOG(10))+0.1

          ELSEIF [Sales]>100 AND [Sales]<1000 THEN ((0.3-0.25)/(LOG(1000)-LOG(100)))*(LOG([Sales])-LOG(100))+0.25

          ELSEIF [Sales]>1000 AND [Sales]<10000 THEN ((0.6-0.3)/(LOG(10000)-LOG(1000)))*(LOG([Sales])-LOG(1000))+0.3

          END

           

          The color flag is then just

          [Discount]>[DiscountLine]

           

          269082disc.png

          • 2. Re: Plotting a line in Tableau
            Andrew Lemon

            This was absolutely amazing!

            Thank you!!!!