title: Get the last X non-empty rows of a range in Google Sheets
body: <p>I have a range like in the following image:</p>
  <p><img src="https://i.stack.imgur.com/7IKGR.png" alt="Google Sheets Range" /></p>
  <p>Where the top headers represent the months of the year (1-12) and the left column represents the days in a month (1 to 28/29/30/31).</p>
  <p>I would like to perform a SUM function over the last 30 days of my range such that it starts counting from the last non-empty value and goes up until it reaches the first value of that column, and then if there are still days to count, goes to the previous month and starts counting from its last value.</p>
  <p>For example, in the image if I wanted the sum of the values of the last 6 cells of the range, it would sum up 16, 12, 8, 4, 4 and 15.</p>
  <p>I've tried adapting the solution to a similar problem as outlined <a href="https://stackoverflow.com/questions/5779222/get-the-range-of-the-last-x-rows-in-google-spreadsheet">here</a>, but I haven't been able to make it work so far.</p>