-
Notifications
You must be signed in to change notification settings - Fork 689
Description
Hello,
Thank you for making this great library!!
I am testing out alasql for SharePoint lists reports. It looks like MIN() and MAX() are not working for dates (but things like COUNT() and YEAR() work so I know the date format is OK). I'm not 100% sure but I think the issue maybe that alasql is using JavaScript Math functions for aggregates, which do not support dates. I would expect this to work as it is very basic functionality for reports and dashboards.
I made a temporary fix in my project by adding two new functions, like this:
// ==========================================
// ALASQL CUSTOM AGGREGATORS
// ==========================================
alasql.aggr.MAXDATE = function(v, s, stage) {
if (stage === 1) return v;
if (stage === 2) {
if (v == null || v === '') return s;
if (s == null || s === '') return v;
return (v > s) ? v : s;
}
if (stage === 3) return s;
};
alasql.aggr.MINDATE = function(v, s, stage) {
if (stage === 1) return v;
if (stage === 2) {
if (v == null || v === '') return s;
if (s == null || s === '') return v;
return (v < s) ? v : s;
}
if (stage === 3) return s;
};
I would encourage you to implement some kind of support for dates in the aggregate functions MIN, MAX, FIRST, LAST, whether it's a fix similar to the above or an automatic conversion of date to number+unix epoch or similar.
Gabriel Mongefranco
Mobile Data Architect
Eisenberg Family Depression Center, University of Michigan