# Need help combining 4 Excel formulas please

Note: this is a follow-up to this thread:
Use a function as the criteria in the Excel =COUNTIF() function

Hello,

The screenshot (with details) shown below is from an Excel (2010) spreadsheet which is attached. The purpose of the spreadsheet is to:

Display the Running Total of Col A dates which are in 2013 but are not Sundays.

The objective has already been achieved (I believe) in the attachment with the results shown here in Col G:

The data range includes Rows 2:100 and has the following columns:

Col A_a random date between 2011-Jan-01 & 2013-Jun-05
Col B_the day of the week
Col C_spacer
Col D_shows dates in 2013 ("`" if not)
Col E_shows non-Sundays ("`" if not)
Col F_shows when both Cols D & E are True ("`" if not)
Col G_shows running total of "Boths" in Col F

A2    =RANDBETWEEN(40544,41430)
B2    =TEXT(A2,"ddd")
C2       n/a
D2    =IF(YEAR(A2)=2013,2013,"`")
E2    =IF(B2<>"Sun","NotSun","`")
F2    =IF(AND(D2=2013,E2="NotSun"),"Both","`")
G2    =COUNTIF(\$F\$2:\$F2,"Both")

However, the question now is:

Can the same endpoint be achieved in a single column?

I have always assumed that any number of formulas—each of which builds upon the previous—can be nested into a single formula. However, that may be a very naïve assumption and not true. If it is true though, I cannot figure out how to put the formulas together in this case.

Thanks
2013-06-05a-EE-function-for-crit.xlsx
###### Who is Participating?

IT Services ConsultantCommented:
Hi,

Expanding on bhess1's suggestion, combining the test for the year (2013) & the day of the week (not Sunday) within the same initial IF condition:

Please paste this formula into cell [G2]:

=IF(AND(YEAR(A2)=2013,TEXT(A2,"ddd")<>"Sun"),IF(ISNUMBER(G1),G1,0)+1,IF(ISNUMBER(G1),G1,0))

Then copy cell [G2] to the Windows Clipboard & paste down column [G] to cell [G11] (i.e. [G3:H11]).

Also copy [G2] to [G15:G24] (or as far down column [G] as required).

BFN,

fp.
Q-28149033.xlsx
0

Senior DBACommented:
I believe you need at least two formulas.  One to generate your data, one to interpret it.

As I see it, the formula for generating the running total would be:

=IF(YEAR(A2)=2013,IF(TEXT(A2, "ddd")<>"Sun",IF(ISNUMBER(G1), G1+1, 1), IF(ISNUMBER(G1), G1, 0)), IF(ISNUMBER(G1), G1, 0))

Where A is the column with the date data, and G is the running total column.
0

Commented:
Have you tried:

=SUM(N(YEAR(A\$2:A2)=2013)*N(WEEKDAY(A\$2:A2)<>1)) {cse}

See attached
2013-06-05a-EE-function-for-crit.xlsx
0

Commented:
Of course if you use * to multiply the two conditions then the Boolean co-ercion is done implicitly by * so you don't need the N functions or any replacement for them, so this works too

=SUM((YEAR(A\$2:A2)=2013)*(WEEKDAY(A\$2:A2)>1))

confirmed with CTRL+SHIFT+ENTER

.....but I prefer bhess1/fanpages' approach, for a running total why re-calculate all the previous rows each time, that's just wasted effort, you can simply ascertain whether each row meets the conditions and add that to the previous row total, e.g. with this formula in G2 copied down

=SUM((YEAR(A2)=2013)*(WEEKDAY(A2)>1),G1)

regards, barry
0

Author Commented:
Great responses. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.