Function Problems

How to Create an Excel Formula to Count Holiday Codes with Different Values

Steven ParkerSteven Parker Nov 10, 2026 868 views

Question details

The user needs to calculate holiday totals based on specific letter codes, where different codes correspond to different day values (e.g., code H counts as 1 day, code L subtracts 1 day, and code PH adjusts by 0.5 days).

How to Create an Excel Formula to Count Holiday Codes with Different Values
Product
Excel
Device & OS
not provided
Scenario
Tracking employee holiday allowances (taken and booked) using letter codes in an attendance spreadsheet.
Observed behavior
The user wants to streamline the calculation process by substituting multiple complex conditions with a simplified LET formula or standard COUNTIFS calculations.
Before you start

Ensure your holiday tracker dates are properly formatted and that the letter codes (such as H, L, and PH) are consistently entered in your specified data range without hidden spaces.

Solution 1Recommended

Use the LET Function to Simplify Holiday Calculations

The LET function allows you to define a range once and perform multiple mathematical operations on it, resulting in a shorter, cleaner, and more efficient formula.

This method calculates 'Holiday taken' (dates before your target date in cell A1) and 'Holiday booked' (dates after cell A1) using the same logic. By defining the variable 'rng', you avoid repeating the INDEX and date calculation functions.

1
Set up the formula for 'Holiday taken'

Select the cell where you want the 'Holiday taken' total to appear. Enter the formula: =LET(rng,Q13:INDEX(Q13:Q378,A1-DATE(YEAR(A1),1,0)),SUM((rng="H")-(rng="L")+0.5*(rng="PH")))

2
Set up the formula for 'Holiday booked'

Select the cell for your 'Holiday booked' total. Enter the formula: =LET(rng,INDEX(Q13:Q378,A1-DATE(YEAR(A1),1,0)):Q378,SUM((rng="H")-(rng="L")+0.5*(rng="PH")))

3
Apply the calculation

Press Enter to apply the formulas. Excel will calculate the range dynamically based on the current date in cell A1, automatically adding 1 for 'H', subtracting 1 for 'L', and adding 0.5 for 'PH'.

Use the LET Function to Simplify Holiday Calculations
Dynamic Range Sizing: If row 378 is blank in non-leap years, you can safely include it in the INDEX range without needing an additional IF statement.
Manage Spreadsheets Easily

Easily Manage Formulas and Holiday Trackers with WPS Spreadsheet

WPS Office provides a powerful, free Spreadsheet tool that fully supports advanced functions like COUNTIFS and complex array calculations, allowing you to track custom holiday codes effortlessly.

  1. 1. Open your tracker in WPS: Launch WPS Spreadsheet and open your existing holiday tracker workbook.
  2. 2. Select your output cell: Click on the cell where you want the calculated holiday totals to be displayed.
  3. 3. Input the formula: Type in your COUNTIFS or dynamic array formula, and press Enter to instantly calculate your precise holiday balances.
100% compatible with Microsoft Excel (.xlsx, .xls) formats, ensuring your formulas work perfectly.Supports advanced functions including COUNTIFS, INDEX, and array calculations for robust holiday tracking.Lightweight software with a familiar, user-friendly interface for seamless migration.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my LET formula return a #NAME? error?

The LET function was introduced in newer versions of Excel and modern spreadsheet software. If you see a #NAME? error, your current software version may not support this specific function. You should use the COUNTIFS alternative method instead.

How can I add a new code, like 'S' for sick leave, to the calculation?

In the LET formula, you can easily add another condition inside the SUM function. For example, append `+ (rng="S")` to the formula logic, or multiply it by a different number if sick leave represents a different value.

Can I apply this formula to reference ranges across multiple sheets?

Yes, you can reference ranges from other sheets by adding the sheet name followed by an exclamation mark before the range (e.g., `Sheet2!Q13:Q378`). However, you must ensure that both the date arrays and code arrays refer to identically sized ranges to avoid array mismatch errors.