Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Power excel 2016 with mrexcel Master Pivot Tables, Subtotals, Charts, VLOOKUP, IF, Data Analysis in Excel 2010–2013 (Bill Jelen) (z-lib.org).pdf
Скачиваний:
4
Добавлен:
14.08.2022
Размер:
49.75 Mб
Скачать

208

POWER EXCEL WITH MR EXCEL

 

 

Strategy: You can use a numeric format to force dates to display the month and year instead of the spe- cific date. Here’s how:

1. Select the range of dates. If you have thousands of rows of data, you can select them all by putting the cell pointer in A2, then pressing Ctrl+Shift+Down Arrow.

2. Press Ctrl+One to display the Format Cells dialog. 3. In the Format Cells dialog, choose the Number tab. 4. In the Category list box, choose Date.

5. In the Type list box, scroll through and select either Mar-01 or March-01. Click OK.

Results: The daily dates will appear as monthly dates.

This process is fine for printing and even for doing auto- matic subtotals. It will not work for sorting, formulas, or pivot tables. See “Calculate First of Month” for details on actually transforming the column into months.

Figure 514 Excel displays the daily dates as months.

ADD A COLUMN TO SHOW MONTH OR WEEKDAY

Problem: I want to analyze sales by weekday. Can I calculate the weekday from a date?

Strategy: Use the TEXT function. The first argument for this function is a cell containing a date. The second argument is any custom number format in quotes.

=TEXT(A2,”DDDD”) will give you a week- day. =TEXT(A2,”MMM”) will give you the month abbreviation.

Figure 515 Convert dates to weekdays.

Note that unlike applying a date format, the TEXT function actually converts the date to text. You can sort by column B and all of the Mondays will sort together.

CALCULATE FIRST OF MONTH

Problem: I have a series of invoice dates, and I need to group the data by month. In “Display Monthly Dates,” I learned how to format a date to display as a month and year. However, when I format a date to look like a month, I know by looking at the formula bar that the underlying value still really includes the day as well as the month and year.

Strategy: Use a combination of YEAR(), MONTH(), DAY(), and DATE() functions. The first three func- tions will break a date into component parts.

=YEAR(A2) will return 2016 for the year ●=MONTH(A2) will return 7 for July

=DAY(A2) will return 14 from July 14th.

PART 2: CALCULATING WITH EXCEL

209

 

 

Figure 516 Break dates into component parts.

Since Excel gives you three functions to break dates apart, they also give you one amazing function to put dates back together: =DATE(Year, Month, Day) will convert the three component parts back into a real date.

To calculate the first of the month, you can use =DATE(B2,C2,1). Replacing the Day argument with a 1 will force the calculation back to the first of the month.

2

Figure 517 Calculate the first of the month.

AlternateStrategy:Youcanexpressthecalculationinasingleformulawith:=DATE(Year(A2),Month(A2),1). Or, you can use =A2-DAY(A2)+1.

CALCULATE THE LAST DAY OF THE MONTH

Problem: I need to calculate the last of the month. What the heck was that poem?

Figure 518 Don’t try the formula on the right.

Strategy: Don’t try coding that poem about the number of days. The DATE() function will handle this eas- ily, with one clever trick. Don’t try to go to the 31st or 30th or 28th of the month. Instead, go to the first of the next month and then subtract 1!

210

POWER EXCEL WITH MR EXCEL

 

 

Figure 519 Go to the first of the next month and subtract 1.

This is a clever approach, isn’t it?

How does it manage to work in December? You are ask- ing for the first of the 13th month of 2015. Excel has no problem figuring out that =DATE(2015,13,1) is January 1 of 2016. In fact, here is the 37th day of the 18th month of

2020:

Figure 520 The DATE function is incredibly versatile.

The DATE function can even sort of handle negatives, with one twist. A zero in the month or day argument is treated as “the item before 1”. Thus, using -1 as the month will actually go back two months.

Figure 521 To go back one month, use 0 as the month.

This previous trick makes the original question even easier. To go to the end of this month, you would go to the 0th of the next month. =DATE(YEAR(A2),MONTH(A2)+1,0).

Figure 522 Shorter formula for end of month.

If you are sure you won’t be sharing the workbook with anyone using Excel 2003, you can safely use the

EOMONTH function to show the end of this month, last month, two months from now, and so on.

Figure 523 Get the end of month from N months from now.

PART 2: CALCULATING WITH EXCEL

 

211

 

 

 

CALCULATE INVOICE DUE DATES

Problem: I have a spreadsheet of payables. I need to sort by Due Date, but all I have is invoice date and terms.

Figure 524 Calculate the due date for each invoice.

Strategy: This one is simple for Excel. Simply add =B2+C2. You should get a date. If you get a number, then format the result as a date.

2

Figure 525 Add a date and a number and you get a date.

CALCULATE RECEIVABLE AGING

Problem: I have a worksheet showing open invoices. I want to calculate how many days old each unpaid invoice is.

Figure 526 Which invoices are >30 days past due?

Strategy: Subtract the invoice date from the TODAY() function. The TODAY() function will give you the current date. Each day that you open the workbook, the calculation will update.