Skip to content

fix: Incorrect percentage and average calculation for calculated values in graphs#3152

Merged
mtrezza merged 3 commits intoparse-community:alphafrom
mtrezza:fix/graph-pct-calc
Jan 26, 2026
Merged

fix: Incorrect percentage and average calculation for calculated values in graphs#3152
mtrezza merged 3 commits intoparse-community:alphafrom
mtrezza:fix/graph-pct-calc

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Jan 26, 2026

Pull Request

Issue

Incorrect percentage and average calculation for calculated values in graphs

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of percent operator calculations for grouped data.
    • Enhanced average operator calculations to properly aggregate across multiple fields.
    • Fixed calculation behavior for multi-field aggregations.
  • Tests

    • Added comprehensive test coverage for percent and average operator scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@parse-github-assistant
Copy link

🚀 Thanks for opening this pull request!

@parseplatformorg
Copy link
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

This change introduces per-group tracking structures for percent and average calculations in GraphDataUtils. It replaces previous heuristic-based aggregation with explicit logic that computes totals based on sums of numerators/denominators or field values. Calculation propagation is extended to handle enhanced items consistently across grouped and non-grouped scenarios.

Changes

Cohort / File(s) Summary
Percent and Average Aggregation Logic
src/lib/GraphDataUtils.js
Introduces percentComponents and averageComponents per-group tracking structures. Replaces previous average-based heuristic with explicit branches for percent (sum numerators / sum denominators) and average (sum all field values / numFields) operators. Updates calculation propagation to incorporate calcVals from enhanced items. Adjusts aggregation logic for both pie data processing and bar/line data processing in grouped and non-grouped scenarios.
Test Coverage for Aggregation Changes
src/lib/tests/GraphDataUtils.test.js
Adds comprehensive test cases for percent operator across multiple rows and aggregated data, percent calculations using input from other calculated values, average operator aggregation behavior, and edge cases including empty and invalid formulas. Validates dataset structure, labels, and numeric results.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it lacks the required 'Approach' section and 'Tasks' checklist, containing only the issue statement without explaining the changes or implementation details. Add an 'Approach' section describing the changes made to fix the calculations, and complete the 'Tasks' section by checking relevant boxes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main bug fix: correcting percentage and average calculations for calculated values in graphs, which aligns with the changeset's core modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mtrezza mtrezza merged commit 14b4d48 into parse-community:alpha Jan 26, 2026
12 checks passed
@mtrezza mtrezza deleted the fix/graph-pct-calc branch January 26, 2026 17:20
parseplatformorg pushed a commit that referenced this pull request Jan 26, 2026
# [8.3.0-alpha.32](8.3.0-alpha.31...8.3.0-alpha.32) (2026-01-26)

### Bug Fixes

* Incorrect percentage and average calculation for calculated values in graphs ([#3152](#3152)) ([14b4d48](14b4d48))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 8.3.0-alpha.32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants