SOLVED

Need help with formula for counting the last 10 even rows that contain a value of a column

%3CLINGO-SUB%20id%3D%22lingo-sub-1820619%22%20slang%3D%22en-US%22%3ENeed%20help%20with%20formula%20for%20counting%20the%20last%2010%20even%20rows%20that%20contain%20a%20value%20of%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1820619%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20need%20help%20with%20a%20formula.%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20the%20picture%20for%20my%20excel%20table.%20I%20want%20to%20count%20the%20average%20of%20the%20last%2010%20even%20rows%20that%20contain%20a%20value%20(so%20not%20the%20last%202%20even%20rows%20on%20the%20picture)%20of%20for%20example%20column%20B.%20I'm%20constantly%20adding%20new%20data%20in%20the%20new%20rows.%20Therefore%2C%20I%20need%20a%20formula%20that%20constantly%20only%20calculates%20the%20last%2010%20even%20rows%20with%20a%20value%20of%20column%20B.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20I%20have%20a%20formula%20that%20calculates%20the%20mean%20of%20all%20the%20even%20rows.%20So%2C%20this%20has%20to%20be%20adjusted%20that%20it%20only%20calculates%20the%20last%2010%20even%20rows%20with%20a%20value.%20This%20is%20the%20formula%20I%20have%20now%3A%3C%2FP%3E%3CP%3E%3DSUM(IF(ISEVEN(ROW(B70%3AB115))%3BB70%3AB115))%2F(COUNT(B70%3AB115)%2F2)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20I%20also%20can%20calculate%20it%20with%20this%20formula%3A%3C%2FP%3E%3CP%3E%3DSUM(IF(MOD(ROW(B70%3AB115)%3B2)%3D0%3BB70%3AB115%3B0))%2F(COUNT(B70%3AB115)%2F2)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20these%20formulas%20just%20count%20all%20the%20even%20values%2C%20but%20I%20need%20it%20to%20calculate%20only%20the%20last%2010%20even%20values.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20searched%20online%20but%20I%20wasn't%20able%20to%20find%20the%20solution.%20Hopefully%2C%20someone%20can%20help%20me!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22Schermafbeelding%202020-10-26%20om%2021.28.51.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F229385i25638AF1933AE252%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Schermafbeelding%202020-10-26%20om%2021.28.51.png%22%20alt%3D%22Schermafbeelding%202020-10-26%20om%2021.28.51.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1820619%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1820818%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20formula%20for%20counting%20the%20last%2010%20even%20rows%20that%20contain%20a%20value%20of%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1820818%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F846684%22%20target%3D%22_blank%22%3E%40Daan21%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%20this%20formula%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DSUMPRODUCT(OFFSET(%24B%2470%2CCOUNT(%24B%2470%3A%24B%241000)-20%2C0%2C20%2C1)*ISEVEN(ROW(OFFSET(%24B%2470%2CCOUNT(%24B%2470%3A%24B%241000)-20%2C0%2C20%2C1))))%2F10%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1822278%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20formula%20for%20counting%20the%20last%2010%20even%20rows%20that%20contain%20a%20value%20of%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1822278%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Hans%2C%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20formula%20worked!%20Thank%20you%20very%20much!%20However%2C%20I%20couldn't%20figure%20out%20how%20to%20do%20the%20same%20thing%20for%20the%20odd%20rows.%20So%2C%20the%20rows%20with%20the%20percentages.%20I%20also%20want%20to%20count%20the%20average%20percentage%20of%20the%20last%2010%20odd%20rows%20that%20contain%20a%20value%20(exactly%20the%20same%20as%20I%20did%20for%20the%20even%20rows%20with%20numbers).%20Could%20you%20help%20me%20figure%20this%20out%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdditionally%2C%20to%20complete%20my%20file%2C%20I%20want%20to%20calculate%20the%20chance%20of%20how%20many%20times%20of%20the%20last%2010%20dates%20there%20was%20a%20positive%20outcome%20(e.g.%2C%20%26gt%3B0).%20I%20have%20a%20formula%20now%20that%20calculates%20the%20chance%20of%20all%20the%20dates%20that%20contain%20a%20value%20in%20the%20file%20(so%20the%20last%20two%20dates%20are%20excluded%20because%20they%20haven't%20got%20a%20value%20yet)%2C%20but%20I%20want%20to%20change%20this%20to%20the%20last%2010%20dates%20that%20contain%20a%20value.%20Tried%20to%20adjust%20it%20with%20the%20formula%20you%20sent%20me%2C%20but%20couldn't%20get%20the%20right%20formula%2C%20unfortunately.%20Hope%20you%20can%20help%20me%20with%20this%20as%20well!%3C%2FP%3E%3CP%3EThis%20is%20the%20formula%20I%20use%20to%20calculate%20how%20many%20times%20of%20all%20the%20dates%20a%20date%20was%20above%200%3A%3C%2FP%3E%3CP%3E%3DCOUNTIF(B70%3AB115%3B%22%26gt%3B0%22)%2FCOUNT(B70%3AB115)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20you%20can%20help%20me%20with%20these%20two%20formulas.%20Your%20last%20solution%20worked%20perfectly%2C%20once%20again%20thank%20you%20for%20that!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGreetings%2C%26nbsp%3B%3C%2FP%3E%3CP%3EDaan%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1822349%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20formula%20for%20counting%20the%20last%2010%20even%20rows%20that%20contain%20a%20value%20of%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1822349%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F846684%22%20target%3D%22_blank%22%3E%40Daan21%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20last%2010%20odd%20rows%3A%3C%2FP%3E%0A%3CP%3E%3DSUMPRODUCT(OFFSET(%24B%2470%2CCOUNT(%24B%2470%3A%24B%241000)-20%2C0%2C20%2C1)*ISODD(ROW(OFFSET(%24B%2470%2CCOUNT(%24B%2470%3A%24B%241000)-20%2C0%2C20%2C1))))%2F10%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi,

I need help with a formula. 

See the picture for my excel table. I want to count the average of the last 10 even rows that contain a value (so not the last 2 even rows on the picture) of for example column B. I'm constantly adding new data in the new rows. Therefore, I need a formula that constantly only calculates the last 10 even rows with a value of column B. 

 

Now I have a formula that calculates the mean of all the even rows. So, this has to be adjusted that it only calculates the last 10 even rows with a value. This is the formula I have now:

=SUM(IF(ISEVEN(ROW(B70:B115));B70:B115))/(COUNT(B70:B115)/2)

 

Or I also can calculate it with this formula:

=SUM(IF(MOD(ROW(B70:B115);2)=0;B70:B115;0))/(COUNT(B70:B115)/2)

 

So these formulas just count all the even values, but I need it to calculate only the last 10 even values. 

I have searched online but I wasn't able to find the solution. Hopefully, someone can help me!!

 

Thanks in advance!

Schermafbeelding 2020-10-26 om 21.28.51.png

12 Replies
Highlighted
Best Response confirmed by Daan21 (Occasional Contributor)
Solution

@Daan21 

Try this formula:

 

=SUMPRODUCT(OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1)*ISEVEN(ROW(OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1))))/10
Highlighted

@Hans Vogelaar 

Hi Hans, 

This formula worked! Thank you very much! However, I couldn't figure out how to do the same thing for the odd rows. So, the rows with the percentages. I also want to count the average percentage of the last 10 odd rows that contain a value (exactly the same as I did for the even rows with numbers). Could you help me figure this out? 

 

Additionally, to complete my file, I want to calculate the chance of how many times of the last 10 dates there was a positive outcome (e.g., >0). I have a formula now that calculates the chance of all the dates that contain a value in the file (so the last two dates are excluded because they haven't got a value yet), but I want to change this to the last 10 dates that contain a value. Tried to adjust it with the formula you sent me, but couldn't get the right formula, unfortunately. Hope you can help me with this as well!

This is the formula I use to calculate how many times of all the dates a date was above 0:

=COUNTIF(B70:B115;">0")/COUNT(B70:B115)

 

I hope you can help me with these two formulas. Your last solution worked perfectly, once again thank you for that!

 

Greetings, 

Daan

Highlighted
Hi Hans,
This formula worked! Thank you very much! However, I couldn't figure out how to do the same thing for the odd rows. So, the rows with the percentages. I also want to count the average percentage of the last 10 odd rows that contain a value (exactly the same as I did for the even rows with numbers). Could you help me figure this out?

Additionally, to complete my file, I want to calculate the chance of how many times of the last 10 dates there was a positive outcome (e.g., >0). I have a formula now that calculates the chance of all the dates that contain a value in the file (so the last two dates are excluded because they haven't got a value yet), but I want to change this to the last 10 dates that contain a value. Tried to adjust it with the formula you sent me, but couldn't get the right formula, unfortunately. Hope you can help me with this as well!
This is the formula I use to calculate how many times of all the dates a date was above 0:
=COUNTIF(B70:B115;">0")/COUNT(B70:B115)

I hope you can help me with these two formulas. Your last solution worked perfectly, once again thank you for that!

Greetings,
Daan
Highlighted

@Daan21 

For the last 10 odd rows:

=SUMPRODUCT(OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1)*ISODD(ROW(OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1))))/10

Highlighted

@Daan21 

The number of positive entries in the last 20 even-numbered rows is

 

=SUMPRODUCT((OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1)>0)*ISEVEN(ROW(OFFSET($B$70,COUNT($B$70:$B$1000)-20,0,20,1))))

 

Divide this by 10 to get the fraction of positive entries.

Highlighted

@Hans Vogelaar 

Hi Hans,

Thank you for the quick responses! The formulas both work perfectly. I tried the one for the odd rows the same way but made a small mistake that's why I wasn't able to formulate the formula. So, Thank you very much for your perfect help!

 

Greetings,

Daan

Highlighted

@Hans Vogelaar 

Hi Hans, 

Sorry to ask you again. But I have one last formula I can't figure out on my own. Therefore, I ask you one more time for help. Hope you are willing to help again:)!

It is the same problem as for the other formulas. I have a formula that is based on all dates that contain a value and I want to change it to the last 10 dates that contain a value. Despite that I'm now familiar with the "offset" function, I can't figure out how to formulate the formula right. I want to calculate how many dates (of the last 10 dates that contain a value) contain a positive value (the green ones) in one of the columns. So, it doesn't matter if a date contains a positive value in more than one column. It does only matter if there is minimal one positive value in any of the columns B to G for a date. So, for example for date 21-09-2020, it doesn't contain a positive value in any of the columns. Therefore, this date must not be counted. The following dates (28-09-2020 till 19-10-2020), all have positive values in minimal one of the columns. Therefore, all these dates must be counted. I hope I made my idea clear. I have a formula that calculates it for all the dates, but now I need a formula that counts it for the last 10 dates that contain values. This is the formula I currently use for it:

 

=((SUM(--(MMULT(--(B84:G139>0);TRANSPOSE(COLUMN(B84:G139)))>0)))-COUNTBLANK(B84:B139))

 

I hope you can help me with this last formula I need for my sheet to complete! Already thanks in advance!!

Greetings,

Daan

Highlighted

@Daan21 

Can you explain as clearly as you can what you want to compute? I have no idea what your formula does. Thanks in advance.

Highlighted

@Hans Vogelaar 

 

Hi Hans, 

Thank you for your response! I'll try to explain it the best I can.

For the explanation, you can look at the picture below. As you can see, in column A there are all dates. Al these dates have 2 rows, one row with numbers, and one row with percentages. I want to calculate the number of dates that have at least one column (in Column B to G) with a positive value. Sidenote: the number and percentages are always both either positive or negative. So, as you can see, if a date has a positive number it always also has a positive percentage. There is no difference between the rows. The only difference is that the one is a number and one a percentage. So, you don't have to take this into account. I want to know if a date contains at least one positive value (green cells) for column B to G. IF this is the case I want it to be counted.

Here a couple of examples:

Date 01-06-2020: it has a positive value in column B (under 09.10), so this date has to be counted.

Date 08-06-2020: doesn't have a positive value in any of the columns from B to G (they hare all negative values), so this date doesn't have to be counted.

Date 29-06-2020: this date contains positive values at column B and C (so it has at least one positive value in any of the columns), so this date has to be counted.

 

But the real problem I am facing is that I want a formula that calculates for how many dates it is case that they have at least one positive value in any of the columns based on the last 10 dates that contain values in the columns. So, at this moment this is from date 17-08-2020 till 19-10-2020 and the outcome has to be 8. Because only the dates 07-09-2020 and 21-09-2020 don't have a positive value in any of the columns. However, when I fill in a new date (26-10-2020), then the last 10 dates with values are 24-08-2020 till 26-10-2020. So, this can be done (I think) with the function "offset", as you advised for the other formulas. 

 

I hope I made it clear this way! 

I'm looking forward to your reaction.

Greetings,

Daan

Schermafbeelding 2020-10-26 om 21.28.51.png

Highlighted

@Daan21 

Hi Daan,

 

Thanks, I understand now (I think). Try this formula, confirmed with Ctrl+Shift+Enter if you don't have Microsoft 365 (it's an array formula):

 

=SUM(--(MMULT(--(OFFSET($B$84;COUNT($B$84:$B$1000)-20;0;20;6)>0);TRANSPOSE(COLUMN(OFFSET($B$84;COUNT($B$84:$B$1000)-20;0;20;6))))>0))/2

Highlighted

@Hans Vogelaar 

 

Hi Hans,

Thank you for the quick responses! This formula worked! Thank you very much for your help. This was the last formula I needed in my current sheet to finalize, so I think I won't need your help any time soon anymore;) If I need help one day, I'll contact you if you are open to that!

 

For the formula, I did the same thing with "offset". However, I forgot to change the width to 6 instead of 1. So, that was the mistake I made and you cleared that up for me! 

Once again, thank you and have a nice evening!

 

Greetings,

Daan

Highlighted

@Daan21 

I'm happy to hear that your problem has been solved. Feel free to come back if you have more questions.