Welcome to Excel Magic Trick number 1,103. If you want to download this workbook, click on the link below the video. In this video, we want to talk about how to go from serial number dates to quarters, and then we want to talk about what happens when fiscal quarters and fiscal years don't match up perfectly. For example, January is not in quarter 1; it's in quarter 4.
I've done some other videos on quarters, but let's remind ourselves that there are a number of different formulas we can use. The formula I like to use, and the one I showed in my Control Shift Enter book, uses CEILING. CEILING is a type of function that rounds a number up to a multiple of a significance you give it. The number we're going to round comes from the MONTH function, which looks at a serial number and returns the month: 1, 2, 3, all the way up to 12. We take that month and round it up using CEILING to a significance of three.
Let's check what this gives us. Four rounded up to the nearest three is six. When I double-click and send this down, I'm getting multiples of three. Now I can simply divide by three. I'll press F2 in the whole highlighted column, divide by three, and press Control Enter. That changed the number format, so I'll use the keyboard shortcut Control Shift Grave Accent, or Tilde, to remove the date formatting and return to General. We can clearly see that months 4, 5, and 6 are in the second quarter, months 7, 8, and 9 are in the third quarter, months 10 through 12 are in the fourth quarter, and the first quarter is January through March.
If we need the quarter and year together, I have a formula over here that uses the year and month. I can type the text "Q" in double quotes, a space, and then join it with the ampersand symbol to the quarter. Then I join again with an ampersand and double quotes containing a space, a dash, and a space, and join the year. This is standard and gives us results such as "Q2 2013," "Q3 2013," "Q4 2013," and, down here, "Q1 2014." All of these are in the proper year.
Now, what happens if you have a fiscal quarter? For example, a fiscal year that runs from a given month through the next year's January, February, and March. Those months should be considered quarter 1, 2, 3, and 4, and they should carry the fiscal year. There are a couple of ways to do this. One way is to build a lookup table and use an approximate-match lookup. If the first column of the lookup table contains month numbers 1, 2, and 3, the value returned from the table will be four; months 4, 5, and 6 will return one, and so on. I learned this technique from Barry Houdini. We look up the month, which goes in as the lookup value. LOOKUP has two forms; we're going to use the second, which takes a lookup vector and a result vector. Since we're using an array, we don't need to specify a column number, and LOOKUP only performs an approximate match. You do need to realize that when you give it a table as the array, it always takes its result from the last column. Here there are only two columns, so it takes from the last one. If there were three, it would take from the third. I'll press F4 to lock the reference, close the parentheses, press Control Enter, and double-click to send it down. That gives us 1 for April, May, and June, and 4 for the first, second, and third months.
If this really is a hardcoded table in your business that won't change, here's a useful trick. I'll highlight the array and press the F9 key to evaluate it. Excel shows it with array syntax: curly brackets surround the array, commas separate columns, and semicolons separate rows. I can enter this as an array constant. Press Control Enter, double-click to send it down, and we get our fiscal quarters.
Next, I want to show a different form, because I've been learning Power Pivot, and Power Pivot doesn't have all the functions you'd like from an Excel spreadsheet. Let's use the IF function. This formula works both in a column of a spreadsheet and in Power Pivot. We take the month and ask whether it is less than four, which covers months 1, 2, and 3. If true, the result is 4; otherwise, we use the same CEILING approach again: CEILING of the month, with a significance of three, divided by three. The ScreenTip says it takes a serial number. That isn't quite what we want, so I'll backspace and subtract one from the false branch. Otherwise, the months that should be 1 would be taken up as 2, so subtracting one fixes it. I'll press Control Enter and double-click to send it down. That works, and it's a helpful alternative if you're working in Power Pivot.
Now for the fiscal year. If we took a straight year, months 1, 2, and 3 would show 2014 when they should show 2013. So for those first three months we need to subtract one from the year. I'll type an equals sign, the year reference, and copy the formula all the way down. Those results are fine for the later months, but for the first three months I need to subtract one only when the month is 1, 2, or 3. We use a little Boolean logic here: subtract, and in parentheses, ask whether the month is less than four. For months 1, 2, and 3, this evaluates to TRUE; for any other month, it evaluates to FALSE. Any math operation converts TRUE and FALSE to one and zero, so subtracting the Boolean subtracts one only for those months. I'll double-click and send it down. You can see the results, and you can also click a cell and press Alt, M, V to evaluate the formula step by step. When we subtract the TRUE value with a math operation, it gives us one, and we get 2013.
We can combine this with the quarter the same way we did before, using "Q" or quarter, whatever you prefer, and then join in the fiscal year. I'll double-click and send it down, and now we're getting the correct results: quarter 4, 2013, even though the serial number says month one and year 2014.
That's a little fun with fiscal quarters and fiscal years. We'll see you next trick.
