As many of us return to work at the beginning of the new year, many of us reflect on our new year resolutions already broken, stalled weight loss programmes, giving up smoking failures, and, er, automating month end reporting. Well, maybe not the last one. However, monthly reporting is here to stay and the more we can reduce manual intervention the better. With 2026 now fully under way, I thought this would be a good time to consider how to work out – and automate – those month end dates for reporting purposes for once and for all.
Imagine you have four years’ worth of daily sales (not all sales are displayed):
Well, here is a request I get asked all the time: how can I calculate my month end reporting dates when my month doesn’t end at the end of the month? A common issue, for example, that I shall tackle here, is when the month end is defined as the final particular day of the month (e.g. the final Friday). This is a common issue and accountants frequently just type the dates in when Excel could do it simply for you!
There is a starter file you can use to play along with, should you wish.
Here, I am going to use Power Query. I’ve done this for two reasons:
- It keeps the Excel file cleaner
- It allows the introduction of a very useful feature in Power Query that few seem to know about – Fill Up. But more on that shortly…
To begin, I will import the table (already called Sales_Data) into Get & Transform / Power Query.
Here, having selected the Table, I have clicked on the Data tab in the Ribbon and clicked ‘From Table / Range’. This loads the Sales_Data into the Power Query Editor, viz.
I remove the ‘Changed Type’ step automatically undertaken in ‘APPLIED STEPS’ and, instead, manually change the Data Types of the fields Date and Sales to Date and Currency respectively:
Now I will create a new column that will display the end of the month for each record – a bit like the formula =EOMONTH(Date,0) in Excel. To do this, I click back on the Date field, then from the ‘Add Column’ tab, I click on Date -> Month -> End of Month:
This gives me the end of the month for each sales record (already given the ‘Date’ Data Type):
I want to subtract the Date from the End of Month, so that I can see how many days are left until the end of the month. Normally, I would use the Standard button in the ‘From Number’ section of the ‘Add Column’ tab, but it is greyed out since our Data Types are Dates, not numbers.
No matter: I shall have to write some very complex M code instead. On the ‘Add Column’ tab, I click the ‘Custom Column’ button in the General section and write the following:
=[End of Month] – [Date]
Hopefully, you can follow that formula!
I change the resulting Days to End of Month field to a Whole Number Data Type, and I can immediately see how many days there are to the end of the month.
Now I have a plan:
- I need to add another field which identifies the day of the week
- I then add another Custom Column to flag the Fridays (one [1] for Friday, zero [0] otherwise)
- The final Friday will occur in the last week of each month, so when the Days to End of Month value is between zero (0) and six (6) inclusive. Therefore, I add a flag to highlight this last week (one [1] for record is in last week, zero [0] otherwise)
- Simply multiplying these last two flags together will show me the final Friday
- For this Final Friday flag, I simply replace the one [1] with the Date value at that point and replace all the zeroes [0] with null
- I then may Fill Up on this Reporting Month End date, which will be used to populate my PivotTable date.
Simple! All I have to do is, er, do it.
Step 1: Add Day of Week Identifier
This is a real toughie. Here, I simply click back on the Date field, then from the ‘Add Column’ tab, I click on Date -> Day -> Name of Day:
This gives me the new field Day Name, which is already given the Data Type Text, viz.
Step 2: Identify the Fridays using a Flag
This requires more nightmarish M code. Again, from the ‘Add Column’ tab, I click the ‘Custom Column’ button in the General section and write the following:
=if [Day Name] = “Friday” then 1 else 0
Notice, the text must be in quotation marks as it is a Text Data Type.
Alternatively, the same result could have been achieved by going to the ‘Add Column’ tab, but clicking on the ‘Conditional Column’ button instead:
After changing the Friday Flag Data Type to Whole Number, we get:
Each Friday displays a ‘1’ in the Friday Flag field, with all other dates showing zero. That’s just what we wanted.
Step 3: Create a Last Week Flag
This works similarly to the last step. I simply add another ‘Conditional Column’:
Here, if the value in the Days to End of Month field is less than or equal to six (6), then the Final Week Flag is one (1), else zero (0). Changing the Data Type of this flag to Whole Number as well yields the following:
Some of you may have been wondering why I have been persevering with 1 and 0 rather than TRUE and FALSE. It’s because multiplication is trivial with numbers…
Step 4: Creating a Final Friday Flag
To reiterate, the final Friday is the Friday that occurs in the last week of the month. I already have a flag to identify each Friday, and another to denote the final week of each month. Given these are both Boolean flags [1, 0], all I need to do is multiply them together to generate my Final Friday Flag.
Multiplication is easy when the Data Types of both fields are numbers, which they are here. I simply highlight the Friday Flag and Final Week Flag fields and then select Multiply from the ‘Standard’ button dropdown on the ‘Add Column’ tab, viz.
I then rename this Multiplication field Final Friday Flag:
Due to what I do next, there is no need to change the Data Type yet…
Step 5: Replace the Final Friday Indicator with the Date
‘Replace Values’ will not work here, as this will substitute the same value on each occurrence of a one (1). This is not what we require: we want the date for that record to be used instead. This is still trivial using the ‘Conditional Column’ feature:
Using the ‘Add Conditional Column’ dialog, I am replacing each one (1) with the corresponding Date and making all other values null. Be careful here: the ‘Output’ field must select a column, not a value (see image above).
For this new field, Reporting Month End, I can change the Data Type to Date, and delete all the fields except for Date, Sales and Reporting Month End:
Step 6: Fill Up the Reporting Month End Dates
This Reporting Month End date is the date for all days prior to this final Friday. I need to Fill Up – and fortunately, Power Query has just the thing:
With the Reporting Month End field selected, I right-click and select Fill -> Up from the shortcut menus (as shown above). This is a seriously underestimated feature in Power Query, as you often need to cut off a selection by determining the end point. It is possible to do this in Excel, of course, but it usually requires offsetting or fiddling the ranges in the VLOOKUP, INDEX MATCH or XLOOKUP formulae, whereas this is quite a neat solution. That’s why I have used Power Query this month.
There is a little bit of tidying up to do, which includes avoiding a classic Power Query gotcha. Unless the final date in our Sales_Data table is the final Friday of a month, we will have some remaining null values in the Reporting Month End field. Using the dropdown filter may not appear to assist initially:
There appears to be no null. However, note the warning triangle: ‘List may be incomplete’. Remember to ‘Load more’ and then de-select null:
Finally, using the Reporting Month End field (not the Date field), I would add the Reporting Month (Date -> Month -> Name of Month), the Reporting Month Number (Date -> Month -> Month) and the Reporting Year (Date -> Year -> Year) as additional columns, using the ‘Date’ button on the ‘Add Column’ tab:
Date -> Month -> Month
Renaming the query ‘Sales Reporting’, I then ‘Close and Load To…’:
I only create a connection (no need to display this Table), but it is important that I ‘Add this data to the Data Model’. This is so this Table may be accessed in Power Pivot:
You may wish to change the formatting (something you cannot do in Power Query).
One more thing: given we don’t want the Reporting Month to be displayed alphanumerically, we need to sort the Reporting Month by the Reporting Month No. This is easily managed, by clicking the ‘Sort by Column’ button on the Home tab:
Once satisfied, from the Home tab, I can insert a PivotTable:
And there you have it: one PivotTable with the sales summarised by Reporting Month, where each reporting ends on the final Friday of that month.
Archive and Knowledge Base
This archive of Excel Community content from the ION platform will allow you to read the content of the articles but the functionality on the pages is limited. The ION search box, tags and navigation buttons on the archived pages will not work. Pages will load more slowly than a live website. You may be able to follow links to other articles but if this does not work, please return to the archive search. You can also search our Knowledge Base for access to all articles, new and archived, organised by topic.