Function Problems

Return the First or Last Day of a Month in Excel Using a Condition

Rana GarciaRana Garcia Dec 2, 2026 868 views

Question details

Return the first day of the month for the first date when a condition is met, and the last day of the month for other dates.

Return the First or Last Day of a Month in Excel Using a Condition
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains dates and a condition that determines whether the first date should use the start of its month.
Observed behavior
The desired results are the first day of the month for the qualifying first date and month-end dates for all other entries.
Before you start

Make sure the source cells contain valid Excel dates. In the examples below, dates begin in B9 and the condition is in F6; adjust these references to match your worksheet.

Solution 1Recommended

Use a row-based formula for the first date in the list

Use this formula when the first date is in a known row and you want to fill the formula down.

1
Enter the formula

In an empty result cell on row 9, such as C9, enter =IF(ROW(B9)>9,EOMONTH(B9,0),IF($F$6="AR",DATE(YEAR(B9),MONTH(B9),1),EOMONTH(B9,0))).

2
Fill down the list

Drag the fill handle from C9 down alongside the dates in column B. If your data starts on another row, change both B9 and the number 9 in the formula to that starting row.

3
Format the results

Select the result cells and choose a date format from Home > Number Format so the results appear as dates rather than serial numbers.

Use a row-based formula for the first date in the list
First row versus earliest date: This formula treats the date in the starting row as the first date. Sort the dates in ascending order first if the first date must also be the earliest.
Calculate dates in WPS Spreadsheets

Return conditional month start or end dates in WPS Spreadsheets

Use the row-based IF and EOMONTH formula in WPS Spreadsheets to calculate the appropriate month boundary for each date.

  1. 1. Open your workbook: Open WPS Spreadsheets and use Open to select your Excel workbook.
  2. 2. Enter the formula: With dates starting in B9 and the condition in F6, enter =IF(ROW(B9)>9,EOMONTH(B9,0),IF($F$6="AR",DATE(YEAR(B9),MONTH(B9),1),EOMONTH(B9,0))) in C9.
  3. 3. Fill and format the results: Drag the fill handle down column C, then select the results and choose a date format from the Home tab.
Calculate month starts and ends with familiar spreadsheet functionsOpen and save Microsoft Excel XLSX filesFill a formula down a date listUse a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

What does the AR condition do in these formulas?

The formulas check whether F6 equals "AR". If it does, the qualifying first date returns its month's first day; otherwise, it returns the month's last day.

How do I change the formula if my dates start in row 12?

In the row-based formula, replace B9 with B12 and change the row comparison from >9 to >12. Enter the formula in a result cell on row 12, then fill it down.

Why do my results appear as numbers instead of dates?

Excel stores dates as serial numbers. Select the result cells and choose a date format from Home > Number Format.

What happens if the earliest date appears twice?

The dynamic array formula returns the first day of the month for every occurrence of the minimum date when F6 is AR. Use the row-based formula if only the starting row should receive that result.