Count number of last 12 non-zero months of sales (consecutive values) in a row

evesin

New Member
Joined
Mar 24, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that I'm trying to figure out a formula for, but I'm stuck. My data needs to be calculated across rows. I'm trying to calculate the last 12 (or more) months in consecutive order, when sales were bigger than 0 on each row. The catch is that I need to count those values from the end of the row before a 0 sales value occurs.
The columns all represent months of the year.

I have found a formula in the forums, which gives me the result of max consecutive values greater than 0 in a row, but it does not include the condition of LAST 12 or more months of non-zero sales, beginning to count from the right side of the row until the first month of 0 sales occur. The formula is the following:
=MAX(FREQUENCY(IF(D10:AP10>0;COLUMN(D10:AP10));IF(D10:AP10<=0;COLUMN(D10:AP10))))

For example > the formula applied for the marked row returns a count of 24 (counting the values where sales were bigger than 0), though the needed result should be 0, because counting from the last month of sales (from the right side) - there were no sales.
1648125822592.png


Thank You!
 

Attachments

  • 1648125782311.png
    1648125782311.png
    25.9 KB · Views: 42

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The following formula will find the position of the first cell within the row that contains a zero value, starting from the right side, and then subtracts 1 from that position to return the number of consecutive non-zero values.

Note the following . . .
  1. If it does not find a cell that contains a zero value, it simply returns a count of the number of cells referenced in the range.
  2. If a cell is empty, it considers the cell as containing a zero value.
  3. If a cell is blank, such as a cell that contains a formula that returns a blank/null string, the formula will need to be amended.
Therefore, assuming that you want to return the results in Column AR, enter the following formula in AR10, confirm with CONTROL+SHIFT+ENTER, and copy down:

Excel Formula:
=IFERROR(MATCH(TRUE,INDEX(D10:AP10,N(IF(1,COLUMNS(D10:AP10)-COLUMN(D10:AP10)+COLUMN(D10))))=0,0)-1,COLUMNS(D10:AP10))

Hope this helps!
 
Upvote 0
Thank You, Domenic!

The formula provided worked like charm!
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

It looks like you don't have any empty cells so I have not allowed for number 2. of @Domenic's post.
However, if you have recent Excel version (ref my first paragraph above) with the XMATCH function then you could also try this (normal entry)

Excel Formula:
=COLUMNS(D10:AP10)-IFNA(XMATCH(0,D10:AP10,0,-1),0)
 
Upvote 0
Solution

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top