How to Create an Excel Formula to Count Holiday Codes with Different Values
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).

- 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.
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.
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.
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")))
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")))
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'.

Calculate Holiday Totals Using COUNTIFS
If your version of Excel does not support the LET function, you can use a combination of standard COUNTIFS formulas to count each code separately and apply the math.
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. Open your tracker in WPS: Launch WPS Spreadsheet and open your existing holiday tracker workbook.
- 2. Select your output cell: Click on the cell where you want the calculated holiday totals to be displayed.
- 3. Input the formula: Type in your COUNTIFS or dynamic array formula, and press Enter to instantly calculate your precise holiday balances.

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.




