Formula Errors

How to Calculate Per-Diem Days with Min 5 and Max 7 in Excel

Phi Hung VoPhi Hung Vo Nov 11, 2026 868 views

Question details

The user needs an Excel formula to calculate per-diem or paid days based on a specific logic: assigning a default minimum of 5 days, calculating the exact number if between 5 and 7 days are worked, and capping the maximum at 7 days.

How to Calculate Per-Diem Days with a Minimum of 5 and Maximum of 7 in Excel
Product
Excel
Device & OS
not provided
Scenario
Calculating weekly per-diem payouts or billable days from a timesheet, where employees are guaranteed 5 days but cannot claim more than 7.
Observed behavior
Requires a formula to output 5 for counts less than or equal to 5, the actual count for 6 or 7, and 7 for counts greater than 7.
Before you start

Ensure your timesheet data is structured in a continuous row or column (e.g., cells G111 to M111 representing days of the week) with numeric values greater than zero indicating a worked day.

Solution 1Recommended

Use IF, MIN, and COUNTIF Functions

Combine logical and statistical functions to enforce the minimum and maximum caps dynamically based on your weekly data.

This approach counts the number of days with logged hours greater than zero. It then uses the IF function to return 5 if the count is 5 or less, and the MIN function to ensure the result never exceeds 7 if the count is higher.

1
Select the target cell

Click on the empty cell where you want the final per-diem calculation to appear.

2
Enter the combined formula

Type =IF(COUNTIF(G111:M111,">0")>5,MIN(COUNTIF(G111:M111,">0"),7),5) into the formula bar. Replace G111:M111 with your actual timesheet data range.

3
Press Enter to calculate

Hit the Enter key to apply the formula. It will now automatically calculate the per-diem days according to your minimum and maximum rules.

Use IF, MIN, and COUNTIF Functions
Formula Breakdown: The MIN function safely caps any value higher than 7, while the IF function guarantees nobody drops below the 5-day baseline.

Calculate Payroll and Per-Diem Seamlessly with WPS Spreadsheet

WPS Spreadsheet fully supports all standard Excel functions like IF, COUNTIF, MAX, and MIN, allowing you to manage timesheets and complex per-diem calculations with zero compatibility issues.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and create a new spreadsheet or open your existing timesheet document.
  2. 2. Input your data: Enter the daily worked hours across columns for your employees.
  3. 3. Apply the formula: Use the =MAX(5, MIN(COUNTIF(range,">0"), 7)) formula in the designated total column to easily calculate the capped per-diem days.
100% compatible with Microsoft Excel (.xlsx) file formats and complex formulas.Free, lightweight, and fast to install on any device.Perfect for managing timesheets, payroll calculations, and daily expense tracking.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my COUNTIF formula return 0 even though there is data?

This usually happens if the criteria is formatted incorrectly or the data contains text instead of numbers. Ensure your criteria ">0" includes the quotation marks and that the referenced cells contain actual numeric values, not text strings looking like numbers.

Can I change the minimum and maximum days dynamically instead of hardcoding them?

Yes. Instead of hardcoding 5 and 7 into your formula, you can reference specific cells (e.g., =MAX($A$1, MIN(COUNTIF(G111:M111,">0"), $B$1))) where A1 holds your minimum limit and B1 holds your maximum limit.

How do I count cells that contain specific text like "Present" instead of numbers?

You can easily modify the COUNTIF criteria. Replace ">0" with "Present" or "P" in your formula. For example: =MAX(5, MIN(COUNTIF(G111:M111,"Present"), 7)).