3 Replies Latest reply: Jan 19, 2017 9:58 AM by Matt Storey RSS

    Displaying Slope/ Best Fit Line using Reference Line in a Scatter Plot Qlik Sense

    Liam Hanninen

      I've explored many potential answers to this question. Many end up pointing to this answer How to add lineal trend in Qlik sense but it doesn't seem to work for a reference line in a scatter plot.


      The attached qvf has the chart (Chart 1) from the above question and Chart 2 which is a scatter plot.  Below that chart I have KPIs representing the variables for Chart 1 such as the slope and y-intercept.


      I'd like to create a best fit line for Chart 2. I'm thinking the code might look like:

      linest_m(total aggr(sum(Profit),Country),Freight)* 

      only({1}???)+linest_b(total aggr(sum(Profit),Country),Freight)


      This mimics Chart 1 and is essentially y=mx+b.

      1. The equation is not correct-obviously
        1. What should go in the only() function?
        2. Even when it generates a line it returns a single value and therefore a straight line
      2. I don't know where the above equation would go even if it was correct
        1. Add-ons>X-axis reference lines
        2. Add-ons>Y-axis reference lines
        3. As a third measure

       

      My question is: how do you create a best fit line using y=mx+b (or anything) on a scatter plot chart in Qlik Sense?

       

      Thanks so much for any ideas and suggestions and hopefully answers.