A comprehensive Python utility for analyzing Profit & Loss (P&L) financial data with advanced flux analysis, department/class breakdowns, and AI-powered insights. This tool reads Excel or CSV files containing financial transactions and provides detailed month-over-month and quarter-over-quarter analysis.
- Multi-format Support: Reads both Excel (.xlsx, .xls, .xlsm) and CSV files
- Flexible Column Mapping: Automatically detects and maps common column names (Period, Amount, Memo, Department, Class)
- Comprehensive Analysis:
- Month-over-Month (MoM) flux and percentage changes
- Quarter-over-Quarter (QoQ) analysis with configurable fiscal year end
- Year-over-Year (YoY) analysis with fiscal year consideration
- Department and Class-level breakdowns
- Interactive Interface: User-friendly prompts for configuration
- AI-Powered Insights: Optional OpenAI integration for intelligent analysis
- Rich Output: Detailed Excel workbooks with multiple sheets and analysis
# Install dependencies (recommended inside virtualenv)
python3 -m pip install -r requirements.txtThe tool runs interactively and will prompt you for configuration:
python3 PL_Flux.py- Input File: Enter the Excel/CSV filename to analyze
- AI Analysis: Choose whether to run AI analysis (y/N)
- Department Analysis: Enable department-level breakdowns (y/N)
- Class Analysis: Enable class-level breakdowns (y/N)
- Fiscal Year End: Set fiscal year end month (1-12, default: 12)
- Analysis Mode: Choose MoM, QoQ, or YoY analysis (if AI enabled)
- Period: Date column (supports various date formats)
- Amount: Financial amount column (handles currency symbols, commas, parentheses)
- Memo/Description: Transaction description column (required for AI analysis)
- Department: For department-level analysis
- Class: For class-level analysis
- Summary Sheet: Monthly totals with MoM flux and percentage changes
- Quarterly Sheet: Fiscal quarter summaries with QoQ analysis
- Yearly Sheet: Fiscal year summaries with YoY analysis
- Monthly Sheets: Individual transaction details for each month (YYYY-MM format)
- Department/Class Sheets: Breakdowns by department and class (if enabled)
- AI_Analysis Sheet: AI-generated insights (if enabled)
Detailed AI analysis of financial fluctuations and trends.
The optional AI analysis provides:
- Intelligent Insights: Explains month-over-month, quarter-over-quarter, or year-over-year fluctuations
- Context-Aware Analysis: Considers department, class, and memo information
- Trend Identification: Identifies patterns and potential causes of changes
- Detailed Breakdowns: Top increases/decreases by various dimensions
The tool automatically manages OpenAI API configuration:
- Creates/updates a
.envfile with your API key - Supports custom base URLs for different OpenAI-compatible services
- Uses configurable models (default: gpt-5-2025-08-07)
- Configurable fiscal year end month (1-12)
- Automatic fiscal quarter calculation
- Quarterly analysis sheets
- Smart Column Detection: Handles case variations and whitespace
- Currency Formatting: Processes various currency formats ($, commas, parentheses)
- Date Parsing: Supports multiple date formats and period strings
- Error Handling: Graceful handling of malformed data
- Month-over-Month (MoM): Detailed monthly trend analysis
- Quarter-over-Quarter (QoQ): Fiscal quarter analysis
- Year-over-Year (YoY): Fiscal year analysis with configurable fiscal year end
- Multi-dimensional: Department and class breakdowns
- Pairwise Analysis: Detailed comparison between adjacent periods
- Prepare your financial data with Period, Amount, and Memo columns
- Run
python3 PL_Flux.py - Follow the interactive prompts
- Review the generated Excel workbook and AI analysis
- Use insights for financial planning and analysis
This project is licensed under the MIT License - see the LICENSE file for details.
For issues or questions, contact Ray Sang.