# Calculation Templates

**Last Updated:** 2025-11-20

## Overview

Calculation templates provide reusable calculation patterns for Excel templates. These templates can be referenced in template definitions to ensure consistent calculations across templates.

## Available Templates

### Basic Calculations

- **Percentage Calculation:** Calculate percentage of a value
- **Growth Rate:** Calculate growth rate between two values
- **Weighted Average:** Calculate weighted average
- **Running Total:** Calculate running total with absolute references

### Advanced Calculations

- **Year-to-Date:** Calculate year-to-date totals
- **Moving Average:** Calculate moving average over n periods
- **Conditional Calculations:** IF-THEN-ELSE patterns
- **Nested Conditions:** Multiple nested IF statements
- **Multiple Criteria:** COUNTIF and SUMIF with multiple conditions

## Usage

Reference calculation templates in template definitions:

```json
{
  "formulas": {
    "my_calculation": {
      "template_id": "percentage_calculation",
      "parameters": {
        "Wert": "A1",
        "Prozentsatz": "0.19"
      }
    }
  }
}
```

## Workflows

### HR Cost Calculation Workflow

1. Enter base hourly wage
2. Enter weekly hours
3. Calculate weekly costs
4. Calculate monthly costs
5. Calculate overtime if applicable
6. Add shift premiums
7. Calculate total costs

### Compliance Check Workflow

1. Check daily working hours (max 10h)
2. Check break requirements
3. Check rest periods
4. Check minimum wage
5. Mark violations and summarize

## Best Practices

1. **Use Named Ranges:** Make formulas more readable
2. **Error Handling:** Always use WENNFEHLER for error handling
3. **Documentation:** Document complex calculations
4. **Testing:** Test calculations with sample data
5. **Consistency:** Use same calculation patterns across templates

## Examples

See `v2/systems/excel-template-generator/data/template-formulas/calculation-templates.json` for complete examples.
