mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Better Max and Min shortcut funtions in the new column menu.
Summary: Using the lookup shortcut in the add column menu to find a max or min value is a buggy experience. MAX and MIN returns 0 for empty collections which can be interpreted as 1970.1.1 in date or date time columns. It is better to just return None (empty cell) when there are no records. Test Plan: Updated Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D4206
This commit is contained in:
@@ -426,13 +426,17 @@ function buildLookupSection(gridView: GridView, index?: number){
|
||||
function formula() {
|
||||
switch(fun) {
|
||||
case 'list': return `${referenceToSource}.${col.colId()}`;
|
||||
case 'average': return `AVERAGE(${referenceToSource}.${col.colId()})`;
|
||||
case 'min': return `MIN(${referenceToSource}.${col.colId()})`;
|
||||
case 'max': return `MAX(${referenceToSource}.${col.colId()})`;
|
||||
case 'average': return `ref = ${referenceToSource}\n` +
|
||||
`AVERAGE(ref.${col.colId()}) if ref else None`;
|
||||
case 'min': return `ref = ${referenceToSource}\n` +
|
||||
`MIN(ref.${col.colId()}) if ref else None`;
|
||||
case 'max': return `ref = ${referenceToSource}\n` +
|
||||
`MAX(ref.${col.colId()}) if ref else None`;
|
||||
case 'count':
|
||||
case 'sum': return `SUM(${referenceToSource}.${col.colId()})`;
|
||||
case 'percent':
|
||||
return `AVERAGE(map(int, ${referenceToSource}.${col.colId()})) if ${referenceToSource} else None`;
|
||||
return `ref = ${referenceToSource}\n` +
|
||||
`AVERAGE(map(int, ref.${col.colId()})) if ref else None`;
|
||||
default: return `${referenceToSource}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user