Search code examples
if-statementgoogle-sheetsgoogle-sheets-formulaarray-formulassparklines

How to create a serial from column values to calculate the slope in Google Sheets?


I have the following spreadsheet:

https://docs.google.com/spreadsheets/d/1Ib2Do3htfRg3NAuI-HyRA3MBM1XwUviFcAxlvF7q1J0/edit?usp=sharing

I have created 2 sparklines, 1 works, 1 doesn't. The one that does not work references the second column as the x-axis to calculate the slope. The slope is needed to give the graph some nice trending color.

My question is, how can I convert the second column into a serial [1, 2, 3, 4, 5]? So that when it is put as the x-axis, the slope would be calculated correctly. Of course, this conversion needs to happen within the formula itself. Thanks for any help.


Solution

  • try:

    =ARRAYFORMULA(SPARKLINE(C2:C, {
     "charttype", "line"; 
     "color", IF(SLOPE(C2:C, ROW(B2:B)-1)>0, "lime", "red"); 
     "linewidth", 2}))
    

    0