Need a better formula

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have a set of consumption data, where I am trying to count by 2 months frequency and take an average. Since I have a data from 2012 till date my formula works fine but I am tired doing the loops. Below is the sample of data from what I am trying to achieve.


[TABLE="width: 485"]
<tbody>[TR]
[TD="width: 64, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] "]item
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Jan
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Feb
[/TD]
[TD="width: 49, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Mar
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Apr
[/TD]
[TD="width: 47, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-May
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Jun
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Jul
[/TD]
[TD="width: 48, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Aug
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Sep
[/TD]
[TD="width: 40, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Oct
[/TD]
[TD="width: 49, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Nov
[/TD]
[TD="width: 45, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ACB9CA]#ACB9CA[/URL] , align: right"]1-Dec
[/TD]
[TD="width: 64, bgcolor: #FFC000"]2 months
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]ABC
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]12
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]2
[/TD]
[TD="bgcolor: transparent, align: right"]3
[/TD]
[TD="bgcolor: transparent, align: right"]5
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]0
[/TD]
[TD="bgcolor: transparent, align: right"]4
[/TD]
[TD="bgcolor: transparent, align: right"]6
[/TD]
[TD="bgcolor: transparent, align: right"]1.00
[/TD]
[/TR]
</tbody>[/TABLE]

Formula under the 2months which I have =AVERAGE(COUNTIF(B2:C2,">0"),COUNTIF(C2:D2,">0"),COUNTIF(D2:E2,">0"),COUNTIF(E2:F2,">0"),COUNTIF(F2:G2,">0"),COUNTIF(G2:H2,">0"),COUNTIF(H2:I2,">0"),COUNTIF(I2:J2,">0"),COUNTIF(J2:K2,">0"),COUNTIF(K2:L2,">0"),COUNTIF(L2:M2,">0"))

I am looking for a better formula may be offset function.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try

=SUMPRODUCT((B2:L2>0)+(C2:M2>0))/COLUMNS(B2:L2)

or this array formula - entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}.

{=AVERAGE((B2:L2>0)+(C2:M2>0))}
 
Last edited:
Upvote 0
Thank you very much for the swift reply. It works the way I was expecting. Just a quick question, I would also like to do it for 3 months & 6 months frequency. Can you please assist.
 
Upvote 0
I have it figured out for 3 months & 6 months, but I am unable to understand how this function is working. If feasible can you please enlighten me. Thanks.
 
Upvote 0
Edit: Sorry, I hadn't seen your last post. Anyway, you can compare your solution to mine. :)

Thank you very much for the swift reply. It works the way I was expecting. Just a quick question, I would also like to do it for 3 months & 6 months frequency. Can you please assist.
Try these

Excel Workbook
ABCDEFGHIJKLMNOP
1item1-Jan1-Feb1-Mar1-Apr1-May1-Jun1-Jul1-Aug1-Sep1-Oct1-Nov1-Dec2 months3 months6 months
2ABC001202350004611.53.285714286
Average
 
Last edited:
Upvote 0
Thank you very much for your time. Have a great day!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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