Formula Errors

How to Fix an Excel IF Formula Based on UG or PS Conditions

Anum MushtaqAnum Mushtaq Nov 11, 2026 868 views

Question details

The user wants to return different date calculations using EDATE based on whether a cell contains 'UG' or 'PS', while outputting a blank cell if the reference date cell is empty.

How to Fix an Excel IF Formula Based on UG or PS Conditions
Product
Excel
Device & OS
not provided
Scenario
Calculating conditional future dates based on specific text codes ('UG' or 'PS') while handling blank reference date cells to avoid errors.
Observed behavior
The user needs the formula to evaluate multiple conditions accurately, returning a specific future date based on the text code, or a blank value without resulting in a #VALUE error.
Before you start

Ensure the cell containing the reference date is correctly formatted as a Date, and the cell containing the text codes 'UG' or 'PS' does not have hidden trailing spaces.

Solution 1Recommended

Use a Compact SWITCH and EDATE Formula

The most efficient way to handle multiple text conditions and date calculations is to combine the SWITCH, ISBLANK, and EDATE functions.

The SWITCH function evaluates a single value against a list of matches and returns the corresponding result. By nesting it within EDATE, you can dynamically change the number of months added to a date based on the 'UG' or 'PS' text.

1
Select the target cell

Click on the cell where you want the calculated date to be displayed.

2
Enter the SWITCH formula

Type the formula: =IF(ISBLANK(B1),"",EDATE(B1,SWITCH(A1,"UG",6,"PS",8))) (Assuming A1 contains the text code and B1 contains the start date).

3
Format the result as a Date

Press Enter. Select the cell again, right-click, choose 'Format Cells', and select your preferred 'Date' format to display the serial number correctly.

Use a Compact SWITCH and EDATE Formula
Simplified Logic: Using SWITCH avoids messy nested IF statements, making the formula easier to read and maintain.
Advanced Spreadsheet Tool

Easily Handle Complex Formulas with WPS Spreadsheet

WPS Spreadsheet fully supports advanced logical functions like SWITCH, IF, and EDATE, allowing you to execute complex conditional date calculations exactly like Microsoft Excel.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the document containing your data.
  2. 2. Start the formula: Click on the destination cell and type '=' to begin entering your formula.
  3. 3. Input the conditional logic: Type your formula, such as =IF(ISBLANK(B1),"",EDATE(B1,SWITCH(A1,"UG",6,"PS",8))).
  4. 4. Format as Date: Press Enter, then use the 'Format Cells' option in the Home tab to display the value as a Date.
Full compatibility with Microsoft Excel formulas and functions (.xlsx)Color-coded formula syntax highlighting for easier troubleshootingBuilt-in error checking for nested IF statementsFree to use with a lightweight installation
microsoft office alternative - wps office

Frequently Asked Questions

Why does my EDATE formula return a random number instead of a date?

Excel calculates dates as serial numbers. If your EDATE formula returns a number like 44927, you simply need to change the cell format to Date. Right-click the cell, select 'Format Cells', and choose a Date format.

What happens if cell A1 contains a text other than UG or PS?

In the provided formulas, if the text does not match 'UG' or 'PS', the formula evaluates to false or hits the default switch case, returning a blank cell ("") instead of an error.

Is the SWITCH function available in all Excel versions?

No, the SWITCH function was introduced in Excel 2019 and Microsoft 365. If you are using an older version, you must use the nested IF formula alternative.

Why does my IF formula return a #VALUE! error?

A #VALUE! error usually occurs if the start date cell contains text instead of a valid date, or if there are invisible spaces disrupting the evaluation. Double-check your data types and ensure the date cell is formatted correctly.