Skip to content

Commit 695db4e

Browse files
committed
ref #65, new formula functions: DPRODUCT, DSTDEV, DSTDEVP, DSUM, DVAR, and DVARP
1 parent a77d38f commit 695db4e

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
lines changed

calc.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,13 @@ type formulaFuncs struct {
438438
// DMIN
439439
// DOLLARDE
440440
// DOLLARFR
441+
// DPRODUCT
442+
// DSTDEV
443+
// DSTDEVP
444+
// DSUM
441445
// DURATION
446+
// DVAR
447+
// DVARP
442448
// EFFECT
443449
// EDATE
444450
// ENCODEURL
@@ -18090,6 +18096,18 @@ func (fn *formulaFuncs) database(name string, argsList *list.List) formulaArg {
1809018096
return fn.MAX(args)
1809118097
case "DMIN":
1809218098
return fn.MIN(args)
18099+
case "DPRODUCT":
18100+
return fn.PRODUCT(args)
18101+
case "DSTDEV":
18102+
return fn.STDEV(args)
18103+
case "DSTDEVP":
18104+
return fn.STDEVP(args)
18105+
case "DSUM":
18106+
return fn.SUM(args)
18107+
case "DVAR":
18108+
return fn.VAR(args)
18109+
case "DVARP":
18110+
return fn.VARP(args)
1809318111
default:
1809418112
return fn.AVERAGE(args)
1809518113
}
@@ -18176,3 +18194,67 @@ func (fn *formulaFuncs) DMAX(argsList *list.List) formulaArg {
1817618194
func (fn *formulaFuncs) DMIN(argsList *list.List) formulaArg {
1817718195
return fn.database("DMIN", argsList)
1817818196
}
18197+
18198+
// DPRODUCT function calculates the product of a field (column) in a database
18199+
// for selected records, that satisfy user-specified criteria. The syntax of
18200+
// the function is:
18201+
//
18202+
// DPRODUCT(database,field,criteria)
18203+
//
18204+
func (fn *formulaFuncs) DPRODUCT(argsList *list.List) formulaArg {
18205+
return fn.database("DPRODUCT", argsList)
18206+
}
18207+
18208+
// DSTDEV function calculates the sample standard deviation of a field
18209+
// (column) in a database for selected records only. The records to be
18210+
// included in the calculation are defined by a set of one or more
18211+
// user-specified criteria. The syntax of the function is:
18212+
//
18213+
// DSTDEV(database,field,criteria)
18214+
//
18215+
func (fn *formulaFuncs) DSTDEV(argsList *list.List) formulaArg {
18216+
return fn.database("DSTDEV", argsList)
18217+
}
18218+
18219+
// DSTDEVP function calculates the standard deviation of a field (column) in a
18220+
// database for selected records only. The records to be included in the
18221+
// calculation are defined by a set of one or more user-specified criteria.
18222+
// The syntax of the function is:
18223+
//
18224+
// DSTDEVP(database,field,criteria)
18225+
//
18226+
func (fn *formulaFuncs) DSTDEVP(argsList *list.List) formulaArg {
18227+
return fn.database("DSTDEVP", argsList)
18228+
}
18229+
18230+
// DSUM function calculates the sum of a field (column) in a database for
18231+
// selected records, that satisfy user-specified criteria. The syntax of the
18232+
// function is:
18233+
//
18234+
// DSUM(database,field,criteria)
18235+
//
18236+
func (fn *formulaFuncs) DSUM(argsList *list.List) formulaArg {
18237+
return fn.database("DSUM", argsList)
18238+
}
18239+
18240+
// DVAR function calculates the sample variance of a field (column) in a
18241+
// database for selected records only. The records to be included in the
18242+
// calculation are defined by a set of one or more user-specified criteria.
18243+
// The syntax of the function is:
18244+
//
18245+
// DVAR(database,field,criteria)
18246+
//
18247+
func (fn *formulaFuncs) DVAR(argsList *list.List) formulaArg {
18248+
return fn.database("DVAR", argsList)
18249+
}
18250+
18251+
// DVARP function calculates the variance (for an entire population), of the
18252+
// values in a field (column) in a database for selected records only. The
18253+
// records to be included in the calculation are defined by a set of one or
18254+
// more user-specified criteria. The syntax of the function is:
18255+
//
18256+
// DVARP(database,field,criteria)
18257+
//
18258+
func (fn *formulaFuncs) DVARP(argsList *list.List) formulaArg {
18259+
return fn.database("DVARP", argsList)
18260+
}

calc_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,6 +4621,7 @@ func TestCalcDatabase(t *testing.T) {
46214621
assert.NoError(t, f.SetCellFormula("Sheet1", "A3", "=\"=Pear\""))
46224622
assert.NoError(t, f.SetCellFormula("Sheet1", "C8", "=NA()"))
46234623
formulaList := map[string]string{
4624+
"=DAVERAGE(A4:E10,\"Profit\",A1:F3)": "73.25",
46244625
"=DCOUNT(A4:E10,\"Age\",A1:F2)": "1",
46254626
"=DCOUNT(A4:E10,,A1:F2)": "2",
46264627
"=DCOUNT(A4:E10,\"Profit\",A1:F2)": "2",
@@ -4635,7 +4636,12 @@ func TestCalcDatabase(t *testing.T) {
46354636
"=DMAX(A4:E10,\"Profit\",A1:F3)": "96",
46364637
"=DMIN(A4:E10,\"Tree\",A1:F3)": "0",
46374638
"=DMIN(A4:E10,\"Profit\",A1:F3)": "45",
4638-
"=DAVERAGE(A4:E10,\"Profit\",A1:F3)": "73.25",
4639+
"=DPRODUCT(A4:E10,\"Profit\",A1:F3)": "24948000",
4640+
"=DSTDEV(A4:E10,\"Profit\",A1:F3)": "21.077238908358",
4641+
"=DSTDEVP(A4:E10,\"Profit\",A1:F3)": "18.2534243362718",
4642+
"=DSUM(A4:E10,\"Profit\",A1:F3)": "293",
4643+
"=DVAR(A4:E10,\"Profit\",A1:F3)": "444.25",
4644+
"=DVARP(A4:E10,\"Profit\",A1:F3)": "333.1875",
46394645
}
46404646
for formula, expected := range formulaList {
46414647
assert.NoError(t, f.SetCellFormula("Sheet1", "A11", formula))
@@ -4644,6 +4650,9 @@ func TestCalcDatabase(t *testing.T) {
46444650
assert.Equal(t, expected, result, formula)
46454651
}
46464652
calcError := map[string]string{
4653+
"=DAVERAGE()": "DAVERAGE requires 3 arguments",
4654+
"=DAVERAGE(A4:E10,\"x\",A1:F3)": "#VALUE!",
4655+
"=DAVERAGE(A4:E10,\"Tree\",A1:F3)": "#DIV/0!",
46474656
"=DCOUNT()": "DCOUNT requires at least 2 arguments",
46484657
"=DCOUNT(A4:E10,\"Age\",A1:F2,\"\")": "DCOUNT allows at most 3 arguments",
46494658
"=DCOUNT(A4,\"Age\",A1:F2)": "#VALUE!",
@@ -4660,9 +4669,18 @@ func TestCalcDatabase(t *testing.T) {
46604669
"=DMAX(A4:E10,\"x\",A1:F3)": "#VALUE!",
46614670
"=DMIN()": "DMIN requires 3 arguments",
46624671
"=DMIN(A4:E10,\"x\",A1:F3)": "#VALUE!",
4663-
"=DAVERAGE()": "DAVERAGE requires 3 arguments",
4664-
"=DAVERAGE(A4:E10,\"x\",A1:F3)": "#VALUE!",
4665-
"=DAVERAGE(A4:E10,\"Tree\",A1:F3)": "#DIV/0!",
4672+
"=DPRODUCT()": "DPRODUCT requires 3 arguments",
4673+
"=DPRODUCT(A4:E10,\"x\",A1:F3)": "#VALUE!",
4674+
"=DSTDEV()": "DSTDEV requires 3 arguments",
4675+
"=DSTDEV(A4:E10,\"x\",A1:F3)": "#VALUE!",
4676+
"=DSTDEVP()": "DSTDEVP requires 3 arguments",
4677+
"=DSTDEVP(A4:E10,\"x\",A1:F3)": "#VALUE!",
4678+
"=DSUM()": "DSUM requires 3 arguments",
4679+
"=DSUM(A4:E10,\"x\",A1:F3)": "#VALUE!",
4680+
"=DVAR()": "DVAR requires 3 arguments",
4681+
"=DVAR(A4:E10,\"x\",A1:F3)": "#VALUE!",
4682+
"=DVARP()": "DVARP requires 3 arguments",
4683+
"=DVARP(A4:E10,\"x\",A1:F3)": "#VALUE!",
46664684
}
46674685
for formula, expected := range calcError {
46684686
assert.NoError(t, f.SetCellFormula("Sheet1", "A11", formula))

0 commit comments

Comments
 (0)