take every 4 rows to average them and this average data put into 4 rows as a specific single result

CRG

New Member
Joined
Nov 7, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi, like title says i need to take every 4 rows to average them and this average data put into 4 rows as a specific single result. I tried my formula in tab.1 but didnt work.
My data needs to looks like tab2. Btw table2 continues to 175 000 rows.Can someone help me what i doing wrong? Thanks for help/advice. Crg


table.1
what i tried with my formula
Excel Formula:
=AVERAGE(FILTER(A1:A4;MOD(COLUMN(A1:A4);4)))
, but unfortunately i get this :
A_col(Values)B_col(values)
45
67,5
48,5
610,5
1411
1010
1210
88

table.2
what i want:
A_col(Values)B_col(Results)
45
65
45
65
1411
1011
1211
811
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the MrExcel board!

Not sure how this will go with your very large data, but you can give it a try.

CRG.xlsm
AB
1DataAverage
245
365
445
565
61411
71011
81211
9811
Sheet1
Cell Formulas
RangeFormula
B2:B9B2=IF(MOD(ROWS(B$2:B2),4)=1,AVERAGE(A2:A5),B1)
 
Upvote 1
I came up with this using FILTER.
Mr Excel Questions 72.xlsm
ABC
1
245
365
445
565
61411
71011
81211
9811
10
Sheet1
Cell Formulas
RangeFormula
B2:B9B2=AVERAGE(FILTER($A$2:$A$9,INT((ROW($A$2:$A$9)-2)/4)=INT((ROW(B2)-2)/4)))
 
Upvote 1
Solution
I came up with this using FILTER.
Considering this ..
table2 continues to 175 000 rows.
.. I just did a bit of testing of slightly larger samples and as I increased the number of rows that filter approach gets exponentially slower compared to the formula I posted. For example with about 2,500 rows it was 0.93 seconds v 0.02 seconds (factor of 45+). I think with 175,000 rows it would get very slow.

Also, if subsequently any new rows get added at the top, the FILTER formula results will be incorrect (unless the numbers of inserted rows is a neat multiple of 4)
 
Upvote 1
Hi guys, thanks for help. This one works well. but yea as Peter said, loading datas is very slow, cuz i have large table. I need to do that by 10 000 (rewriting formula 10 000/20 000/30 000... ). But it works in the end:)
I came up with this using FILTER.
 
Upvote 0
Are you saying that the formula in post #2 does not work?
It should be much faster in that it only has to calculate an average every 4 rows and the other 3 rows just copies the value above. Also, when it does calculate an average it only uses 4 rows to do so, not the entire 175,000 rows.
 
Upvote 0
Considering this ..

.. I just did a bit of testing of slightly larger samples and as I increased the number of rows that filter approach gets exponentially slower compared to the formula I posted. For example with about 2,500 rows it was 0.93 seconds v 0.02 seconds (factor of 45+). I think with 175,000 rows it would get very slow.

Also, if subsequently any new rows get added at the top, the FILTER formula results will be incorrect (unless the numbers of inserted rows is a neat multiple of 4)
Thanks Peter.
I know there is a rule of thumb (that I don't know!) regarding what kind of calculations are faster than others. I know that array formulas are in the mix but I don't recall if it is a VBA solution that is faster or not. I'm lucky I seldom have files that big. Your thoroughness is always helpful.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,976
Members
449,095
Latest member
Mr Hughes

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