Fiscal Quarter UDF - 1033 - Learn Excel from MrExcel Podcast - YouTube

Channel: MrExcel.com

[0]
Hey, welcome back to the MrExcel netcast.
[1]
I'm Bill Jelen.
[3]
Basically, we start out with massive amounts of data.
[6]
So, how we're gonna analyze this. Well, let's plus fire up a pivot table.
[9]
Let's see if you can solve this problem.
[15]
Hey Welcome back to the MrExcel netcast. I'm bill Jelen.
[17]
And today's question comes in from live why Bob is creating a pivot table
[20]
He wants to take daily dates
[22]
and roll them up to quarters and years.
[25]
But that works great in a pivot table if your fiscal year ends on December 31st.
[29]
But for all the companies whose fiscal year ends somewhere else
[32]
Well, you know Microsoft really doesn't handle this very well
[35]
and so why Babb had a
[37]
horrible formula now you had to enter all the time to convert the daily date to fiscal quarter and up to fiscal year in the
[43]
Original Data set he said is there some easier way to do this. Well? Yeah, there is an easier way to do it
[47]
We can create a custom
[49]
User-defined function and store it in your personal macro Workbook now. How do we do that?
[53]
Well first of all you need to make sure there is a personal Macro workbook
[56]
And if you've never used Macros before you may not have one so go to the view Tab Macros record Macro
[62]
And it's really important that we restore this in the personal Macro workbook
[66]
This is the step to make sure that you have a personal Macro workbook
[69]
So we'll just click ok and do anything type anything press enter and then stop recording that
[75]
Will force a personal macro workbook to be there, okay? Now. We want to go look at VBA so we press alt f 11 and
[84]
Open up personal Xls and open up modules and so you see that we have on this case
[90]
I have three different modules module one
[91]
You'll always have a module one because of that thing you just recorded and you can actually get rid of that tiny little macro
[97]
We just needed to force personal dot xls to be there now. Here's what we're going to do
[102]
I'm going to already wrote the code here
[104]
You can copy the code from the screen. I'll try and make it big
[107]
I wrote two custom macros one of them called FQ for fiscal quarter
[111]
It takes a date and then the month the year fiscal year-end so like for example if your fiscal year ends march 31st
[117]
You'd put a three there as the second primary now for you
[121]
You work for a company and the fiscal year is really hard coded so you could shorten this dramatically?
[125]
I try to make it generic so that will work for anyone with any kind of a fiscal year-end
[130]
Calculate what the month number is using the month function
[133]
And then checks to see if the month number is less than the fiscal year end
[137]
And then has a select case to parent returns values qtr one two three or four depending on the quarter if it's anything else
[144]
Then we came up with ten here are returned the F5 function takes my date and a fiscal year end
[151]
That's pretty simple
[152]
We just figure out if the month of my date is less than or equal to the fiscal year end and then format
[160]
Appropriately now we put this in the personal Macro workbooks that way
[163]
It'll be available to any workbook that you ever opened on this computer. We can close visual basic here and go back
[170]
let's just create a
[172]
Simple Little one here. We'll put in a date of 6 15
[177]
2009
[179]
And then when we want to use the FQ function we have to use equal personal
[187]
XLs exclamation point Fq the date and then the fiscal year ending let's say that our fiscal year ends at the end of september
[195]
See we've got quarter three there if we put in a different date for example 1 15 2009
[200]
At his quarter 2 and then to get the fiscal year equal personal
[206]
tod Xls exclamation point Fy and that date comma 9
[214]
It returns
[216]
2008-2009 so now we have those functions
[218]
You don't have to enter the big huge if function all the time
[221]
And it will be available to all the workbooks that you open on this computer again
[225]
Just a little bit of code here. This code is generic enough
[227]
they don't handle any fiscal year-end actually you could probably simplify it quite a bit if
[233]
Your fiscal year end is of course fixed for the company that you work for
[236]
Whether you have it great question from Lab app want to thank you for stopping by we'll see you next time for another net cast
[241]
From Mr.. Excel
[247]
Well, thanks for stopping bye.
[249]
We'll see you next time for another netcast from MrExcel.