Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Enhancement][Grid][kendo-data-query] Average aggregate is calculated incorrectly when null values are present #2151

Open
fnkear opened this issue Apr 8, 2024 · 2 comments
Labels
Bug Item which indicates that something is not working

Comments

@fnkear
Copy link

fnkear commented Apr 8, 2024

I'm submitting a...

  • Bug report
  • Suggestion for improvement

Current behavior

  • if there is null or other non-numeric value in the last row, result of average aggregate will be null
  • if there are some null or other non-numeric value in rows between numeric values, result of average aggregate will be incorrect number

Expected behavior

The best would be if average ignores non-numeric values in presence of numeric (and it can use last non-numeric if there were no numeric values at all)

Minimal reproduction of the problem with instructions

The sandbox ( forked from https://www.telerik.com/kendo-react-ui/components/grid/grouping/grouping/ )

https://stackblitz.com/edit/react-6oe2cf?file=app%2Fmain.jsx
https://react-6oe2cf.stackblitz.io

Please check Average Unit Price for "Beverages" and "Condiments"

What is the motivation or use case for changing the behavior?

Sometimes data has items "with value" and "without value" mixed; but it still makes sense to calculate Average for items having value :)

Environment

Browser:

  • Chrome (desktop) version 123.0.6312.106
  • Firefox version 124.0.2

System:

  • Platform: Windows 11

Suggested solution

the piece of code which I would suggest for "Average" aggregate:

average: () => {
    let value = 0;
    let count = 0;
    let lastNonNumeric = undefined;
    return {
        calc: (curr) => {
            if (isNumeric(curr)) {
                value += curr;
                count++;
            } else {
                lastNonNumeric = curr;
            }
        },
        result: () => count ? value / count : lastNonNumeric
    };
},
@zdravkov
Copy link
Member

Hi @fnkear ,

Thank you for reporting the issue and suggesting a fix. I have isolated it to a '@progress/kendo-data-query' bug in this example - https://stackblitz.com/edit/react-6oe2cf-eewany?file=app%2Fmain.jsx and will suggest the fix to our responsible dev team for research.

If you have any other questions, you could also submit a ticket in our support system.

Greetings,
Plamen

@zdravkov zdravkov added the Bug Item which indicates that something is not working label Apr 12, 2024
@fnkear
Copy link
Author

fnkear commented Apr 15, 2024

Hi @zdravkov ! Yes, your reproduction is much cleaner 👍 Thank you a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Item which indicates that something is not working
Projects
None yet
Development

No branches or pull requests

2 participants