11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6: Working with Dates and Times 163<br />

Counting the occurrences of a day of the week<br />

You can use the following formula to count the number of occurrences of a particular day of the<br />

week for a specified month. It assumes that cell A1 contains a date and that cell B1 contains a day<br />

number (1 for Sunday, 2 for Monday, and so on). The formula is an array formula, so you must<br />

enter it by pressing Ctrl+Shift+Enter.<br />

{=SUM((WEEKDAY(DATE(YEAR(A1),MONTH(A1),ROW(INDIRECT(“1:”&<br />

DAY(DATE(YEAR(A1),MONTH(A1)+1,0))))))=B1)*1)}<br />

If cell A1 contains the date January 8, 2010, and cell B1 contains the value 3 (for Tuesday), the formula<br />

returns 4, which reveals that January 2010 contains four Tuesdays.<br />

The preceding array formula calculates the year and month by using the YEAR and MONTH functions.<br />

You can simplify the formula a bit if you store the year and month in separate cells. The following<br />

formula (also an array formula) assumes that the year appears in cell A1, the month in cell<br />

A2, and the day number in cell B1:<br />

{=SUM((WEEKDAY(DATE(A1,A2,ROW(INDIRECT(“1:”&<br />

DAY(DATE(A1,A2+1,0))))))=B1)*1)}<br />

Refer to Chapters 14 and 15 for more information about array formulas.<br />

Figure 6-4 shows this formula used in a worksheet. In this case, the formula uses mixed cell references<br />

so that you can copy it. For example, the formula in cell C3 is<br />

{=SUM((WEEKDAY(DATE($B$2,$A3,ROW(INDIRECT(“1:”&<br />

DAY(DATE($B$2,$A3+1,0))))))=C$1)*1)}<br />

Figure 6-4: Calculating the number of each weekday in each month of a year.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!