Skip to content

Commit d74adcb

Browse files
committed
ref #65, new formula function: DGET
1 parent 695db4e commit d74adcb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

calc.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ type formulaFuncs struct {
433433
// DEGREES
434434
// DELTA
435435
// DEVSQ
436+
// DGET
436437
// DISC
437438
// DMAX
438439
// DMIN
@@ -18173,6 +18174,32 @@ func (fn *formulaFuncs) DCOUNTA(argsList *list.List) formulaArg {
1817318174
return fn.dcount("DCOUNTA", argsList)
1817418175
}
1817518176

18177+
// DGET function returns a single value from a column of a database. The record
18178+
// is selected via a set of one or more user-specified criteria. The syntax of
18179+
// the function is:
18180+
//
18181+
// DGET(database,field,criteria)
18182+
//
18183+
func (fn *formulaFuncs) DGET(argsList *list.List) formulaArg {
18184+
if argsList.Len() != 3 {
18185+
return newErrorFormulaArg(formulaErrorVALUE, "DGET requires 3 arguments")
18186+
}
18187+
database := argsList.Front().Value.(formulaArg)
18188+
field := argsList.Front().Next().Value.(formulaArg)
18189+
criteria := argsList.Back().Value.(formulaArg)
18190+
db := newCalcDatabase(database, field, criteria)
18191+
if db == nil {
18192+
return newErrorFormulaArg(formulaErrorVALUE, formulaErrorVALUE)
18193+
}
18194+
value := newErrorFormulaArg(formulaErrorVALUE, formulaErrorVALUE)
18195+
if db.next() {
18196+
if value = db.value(); db.next() {
18197+
return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
18198+
}
18199+
}
18200+
return value
18201+
}
18202+
1817618203
// DMAX function finds the maximum value in a field (column) in a database for
1817718204
// selected records only. The records to be included in the calculation are
1817818205
// defined by a set of one or more user-specified criteria. The syntax of the

calc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4632,6 +4632,7 @@ func TestCalcDatabase(t *testing.T) {
46324632
"=DCOUNTA(A4:E10,\"Profit\",A1:F2)": "2",
46334633
"=DCOUNTA(A4:E10,\"Tree\",A1:F2)": "2",
46344634
"=DCOUNTA(A4:E10,\"Age\",A2:F3)": "0",
4635+
"=DGET(A4:E6,\"Profit\",A1:F3)": "96",
46354636
"=DMAX(A4:E10,\"Tree\",A1:F3)": "0",
46364637
"=DMAX(A4:E10,\"Profit\",A1:F3)": "96",
46374638
"=DMIN(A4:E10,\"Tree\",A1:F3)": "0",
@@ -4665,6 +4666,9 @@ func TestCalcDatabase(t *testing.T) {
46654666
"=DCOUNTA(A4:E10,NA(),A1:F2)": "#VALUE!",
46664667
"=DCOUNTA(A4:E4,,A1:F2)": "#VALUE!",
46674668
"=DCOUNTA(A4:E10,\"x\",A2:F3)": "#VALUE!",
4669+
"=DGET()": "DGET requires 3 arguments",
4670+
"=DGET(A4:E5,\"Profit\",A1:F3)": "#VALUE!",
4671+
"=DGET(A4:E10,\"Profit\",A1:F3)": "#NUM!",
46684672
"=DMAX()": "DMAX requires 3 arguments",
46694673
"=DMAX(A4:E10,\"x\",A1:F3)": "#VALUE!",
46704674
"=DMIN()": "DMIN requires 3 arguments",

0 commit comments

Comments
 (0)