SUM last N values based in criteria

tennis07

Board Regular
Joined
Apr 29, 2015
Messages
57
Hi guys,

Does anyone could help me?

What I need is to type a color and the last N values to be calculated.

N values = 1*4 = last 4 values

So, if I enter 1, it needs to get the last 4
2 = 8
3 = 12
and so on...

Sometimes a color has 5 cells but the fifth is always marked with an X and it is not to be calculated.
Follows the example below:

Thanks in advance.

FL3MNjF.png
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
i think Aladin posted it.

but you should for sure go with marco's in my opinion :)

all the best!

but is there an X next to the the column to the right every time a fifth value appears? because the sumproduct formula depends on those X's

Edit: Dave, just to continue: When I type:

Color: Red
Values: 4
SUM: 141 (I should get 139)

It assumes that the 5th cell of the 3rd red group is a new group (4th). So, when I type Values: 3 or Values: 4, I should get 139 for both.
Its a bit trick because If I type a value for a color bigger than I actually have, I will get a wrong result.

WT4ql4A.png


All the best for you all guys!
Thanks everyone
 
Upvote 0
Edit: Dave, just to continue: When I type:

Color: Red
Values: 4
SUM: 141 (I should get 139)

It assumes that the 5th cell of the 3rd red group is a new group (4th). So, when I type Values: 3 or Values: 4, I should get 139 for both.
Its a bit trick because If I type a value for a color bigger than I actually have, I will get a wrong result.

WT4ql4A.png


All the best for you all guys!
Thanks everyone

I didnt understand. Is this a problem you need to fix? or did you figure it out?
 
Upvote 0
Lets try to explain a bit better.
The marcelo's solution probably works fine, but I was wondering how to solve this issue if I didnt have anything (X) to identify the fifth line of a group. I though the solution with { was working properly, but when I added more data at the end, it got lost.

zAXnkfu.png
 
Upvote 0
i will give you a function for column G, that will populate an X at the right place.

but:
will color A AND B always have the same borders? ie on row 27 of your last image, both colors end on the same row. is that accross the board of ur data?

ps. which website do u use to upload your photo?
 
Upvote 0
i will give you a function for column G, that will populate an X at the right place.

but:
will color A AND B always have the same borders? ie on row 27 of your last image, both colors end on the same row. is that accross the board of ur data?

ps. which website do u use to upload your photo?

Dave, it can be randon once I populate that every single day, but there is a pattern as you can see. A group has always 4 or 5 cells in a row with the same text color.

So,
Column A will be

Green / Green / Green / Green (4)
Red / Red / Red / Red / Red (5)
Green / Green / Green / Green (5)
Red / Red / Red / Red / Red (4)
Green / Green / Green / Green (4)

I will never have more than 5 in sequence for the same column.
I can have like:

Column A
A21 Red
A22 Red
A23 Red
A24 Red (4th)

B25 Red
B26 Red
B27 Red
B28 Red
B29 Red (5th)

It contains 9 red in a row but I dont consider that once 4 are on column A and 5 on column B. So, there are 2 groups of red color and the column B29 should not be calculated.

PS: imgur.com
 
Last edited:
Upvote 0
Ok,

based on the fact that all colors on BOTH columns begin and end with each other, put this formula in G1, and then copy down...

(i changed some data for my testing...)


Excel 2016 (Windows) 32 bit
BCDEFG
1blueRed105 
2blueRed2010
3blueRed3015
4blueRed4020
5greyblue24
6greyblue48
7greyblue612
8greyblue816
9greyblue152X
10yellowRed302
11yellowRed502
12yellowRed602
13yellowRed157
14whiteyellow307
15whiteyellow357
16whiteyellow408
17whiteyellow58
18whiteyellow59X
Sheet1
Cell Formulas
RangeFormula
G1{=IF((ROWS($C$1:C1)-IFERROR(MATCH("zzzz",IF($C$1:C1<>C1,$C$1:C1)),0))=5,"X","")}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
Hi,

If you're wanting to populate Column G with an "X", for the 5th occurrence of the Same color in the Same Group...
You can use this formula in G6 copied down.


Book1
BCDEFG
1Color AColor BS1S2
2BlueRed105
3BlueRed2010
4BlueRed3015
5BlueRed4020
6GreyBlue24 
7GreyBlue48
8GreyBlue612
9GreyBlue816
10YellowWhite152
11YellowWhite302
12YellowWhite502
13YellowWhite602
14WhiteYellow157
15WhiteYellow307
16WhiteYellow357
17WhiteYellow408
18RedGreen8
19RedGreen9
20RedGreen10
21RedGreen11
22RedGreen100X
23GreenRed3
24GreenRed15
25GreenRed25
26GreenRed26
27GreenRed2X
28YellowBlue2
29YellowBlue2
30YellowBlue2
31YellowBlue2
Sheet424
Cell Formulas
RangeFormula
G6=IF(COUNTIF(C2:C6,C6)=5,"X","")


PS. A reminder, Aladin in Post # 2 had asked you to upload a "readable" table (something your helpers can copy and paste into Excel for testing), rather than a picture...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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