Databasefunksjoner

Oversikt

De tolv funksjonene i Database-kategorien hjelper deg med å analysere en enkel database som opptar et rektangulært regnearkområde som består av kolonner og rader, med dataene organisert som én rad for hver post. Overskriften celle i hver kolonne viser navnet på kolonnen, og det navnet gjenspeiler vanligvis innholdet i hver celle i den kolonnen.

Funksjonene i kategorien Database har tre argumenter som følger:

  1. Database. Celleområdet til databasen.

  2. Databasefelt. Kolonnen som inneholder dataene som skal brukes i funksjonens beregninger.

  3. Søkekriterier. Celleområdet til et eget område av regnearket som inneholder søkekriterier.

Disse argumentene er beskrevet mer fullstendig nedenfor.

Alle funksjoner har samme driftskonsept. Det første logiske trinnet er å bruke de spesifiserte Søkekriteriene for å identifisere undersettet av poster i Databasen som skal brukes under påfølgende beregninger. Det andre trinnet er å trekke ut dataverdiene og utføre beregningene knyttet til den spesifikke funksjonen (gjennomsnitt, sum, produkt og så videre). Verdiene som behandles er de i Database Felt-kolonnen i de valgte postene.

note

Calc behandler datoer og logiske verdier (SANN og USANN) som numeriske ved beregning med disse funksjonene.


Databasefunksjonsargumenter

Følgende argumentdefinisjoner gjelder for alle funksjoner i databasekategorien:

  1. Database argumenter

    Database spesifiserer celleområdet som er okkupert av databasetabellen. Den første raden i området inneholder feltnavnene, og påfølgende rader er poster med tilsvarende feltverdier.

    En måte å definere celleområdet på er å angi cellereferansen for den øvre venstre cellen, etterfulgt av et kolon (:), og deretter den nedre høyre cellereferansen. Et eksempel kan være A1:E10.

    Argumentet Database kan også spesifiseres ved å sende navnet på et navngitt område eller databaseområde. Å bruke et meningsfylt navn for å definere celleområdet kan forbedre formellesbarheten og dokumentvedlikeholdet. Hvis navnet ikke samsvarer med navnet på et definert område, rapporterer Calc et #NAME? feil.

    Andre feil som kan rapporteres som et resultat av et ugyldig Database-argument er #VALUE! og Err:504 (feil i parameterlisten).

  2. Databasefelt argument

    DatabaseField spesifiserer kolonnen som funksjonen vil bruke for sine beregninger etter at søkekriteriene er brukt og dataradene er valgt. Det er ikke relatert til søkekriteriene.

    Spesifiser DatabaseFelt-argumentet på en av følgende måter:

    • Ved å skrive inn en referanse til en overskriftscelle i Database-området. Alternativt, hvis cellen har fått et meningsfylt navn som et navngitt område eller databaseområde, skriv inn det navnet. Hvis navnet ikke samsvarer med navnet på et definert område, rapporterer Calc et #NAME? feil. Hvis navnet er gyldig, men ikke bare tilsvarer én celle, rapporterer Calc Err:504 (feil i parameterlisten).

    • Ved å angi et tall for å spesifisere kolonnen innenfor Database-området, som starter med 1. For eksempel, hvis en Database okkuperte celleområdet D6:H123, skriv inn 3 for å indikere overskriftscellen ved F6. Calc forventer en heltallsverdi som ligger mellom 1 og antall kolonner definert i Database og ignorerer alle sifre etter et desimaltegn. Hvis verdien er mindre enn 1, rapporterer Calc Err:504 (feil i parameterlisten). Hvis verdien er større enn antall kolonner i Database, rapporterer Calc en #VERDI! feil.

    • Ved å skrive inn det bokstavelige kolonneoverskriftsnavnet fra den første raden i Database-området, plasserer du anførselstegn rundt overskriftsnavnet. For eksempel "Avstand til skolen". Hvis strengen ikke samsvarer med en av Database-områdets kolonneoverskrifter, rapporterer Calc Err:504 (feil i parameterlisten). Du kan også gi en referanse til en vilkårlig celle (ikke innenfor Database- og Søkekriterier-områdene) som inneholder den nødvendige strengen.

    Argumentet DatabaseFelt er valgfritt for funksjonene DCOUNT og DCOUNTA, men det kreves for de ti andre databasefunksjonene.

  3. Argument for søkekriterier

    Søkekriterier spesifiserer celleområdet som inneholder søkekriterier. I likhet med Database er dens første rad også feltnavn, og påfølgende rader er betingelser for relaterte felt. Områdene Database og Søkekriterier trenger ikke være tilstøtende, eller til og med på samme ark.

    En måte å definere celleområdet på er å angi cellereferansen for den øvre venstre cellen, etterfulgt av et kolon (:), og deretter den nedre høyre cellereferansen. For eksempel A13:B14. Celleområdet kan også spesifiseres ved å sende navnet på et definert navngitt område eller databaseområde. Hvis navnet ikke samsvarer med navnet på et definert område, rapporterer Calc et #NAME? feil.

    Err:504 (feil i parameterlisten) kan også rapporteres som et resultat av et ugyldig Søkekriterie-argument.

    Innholdet i Søkekriterier-området er beskrevet mer detaljert i neste avsnitt.

Definere søkekriterier

Antallet kolonner som er brukt av Søkekriterier-området trenger ikke være det samme som bredden på Database-området. Alle overskrifter som vises i den første raden i Søkekriterier må være identiske med overskriftene i den første raden i Database. Imidlertid trenger ikke alle overskrifter i Database vises i den første raden i Søkekriterier, mens en overskrift i Database kan vises flere ganger i den første raden av Søkekriterier.

Søkekriterier legges inn i cellene i den andre og påfølgende raden i Søkekriterier-området, under raden som inneholder overskrifter. Tomme celler i Søkekriterier-området ignoreres.

Lag kriterier i cellene i Søkekriterier-området ved å bruke sammenligningsoperatorene <, <=, =, <>, >= og >. = antas hvis en celle ikke er tom, men ikke starter med en sammenligningsoperator.

Hvis du skriver flere kriterier på en rad, er de koblet sammen med OG. Hvis du skriver flere kriterier i forskjellige rader, er de forbundet med OR.

Kriterier kan opprettes ved hjelp av jokertegn, forutsatt at jokertegn er aktivert via Aktiver jokertegn i formler-alternativet på - LibreOffice Calc - Beregn dialog. Når interoperabilitet med Microsoft Excel er viktig for regnearket ditt, bør dette alternativet være aktivert.

Enda kraftigere kriterier kan opprettes ved bruk av regulære uttrykk, forutsatt at regulære uttrykk er aktivert via Aktiver regulære uttrykk i formler-alternativet på - LibreOffice Calc - Beregn dialog.en

warning

Når du bruker funksjoner der ett eller flere argumenter er søkekriterier, som representerer et regulært uttrykk, er det første forsøket å konvertere strengkriteriene til tall. For eksempel vil ".0" konverteres til 0.0 og så videre. Hvis det lykkes, vil matchingen ikke være et vanlig uttrykk, men en numerisk match. Imidlertid, når du bytter til et sted der desimalskilleren ikke er punktum, får det konvertering av regulære uttrykk å fungere. For å tvinge evalueringen av det regulære uttrykket i stedet for et numerisk uttrykk, bruker du et uttrykk som ikke kan feilleses som numerisk, for eksempel ". [0]" eller ". \ 0" eller "(? I) .0".


En annen innstilling som påvirker hvordan søkekriteriene håndteres er Søkekriterier = og <> må gjelde for hele celler alternativet på - LibreOffice Calc - Beregn dialog. Dette alternativet kontrollerer om søkekriteriene du angir for databasefunksjonene må samsvare nøyaktig med hele cellen. Når interoperabilitet med Microsoft Excel er viktig for regnearket ditt, bør dette alternativet være aktivert.

Eksempler på bruk av databasefunksjoner

Tabellen nedenfor gir et eksempel på en databasetabell som brukes til å demonstrere hvordan du bruker funksjonene i kategorien Database. Celleområdet A1:E10 inneholder fiktiv informasjon om gjestene som er invitert til Joes bursdagsfest. Følgende informasjon er gitt for hver gjest - navn, skolekarakter, alder i år, avstand til skolen i meter og vekt i kilo.

A

B

C

D

E

1

Navn

Karakter

Alder

Avstand

Vekt

2

Andy

3

9

150

40

3

Betty

4

10

1000

42

4

Charles

3

10

300

51

5

Daniel

5

11

1200

48

6

Eva

2

8

650

33

7

Frank

2

7

300

42

8

Greta

1

7

200

36

9

Harry

3

9

1200

44

10

Irene

2

8

1000

42

11


De følgende seks eksemplene bruker databasetabellen ovenfor, kombinert med ulike søkekriterieområder.

Eksempel 1

A

B

C

D

E

12

Navn

Karakter

Alder

Avstand

Vekt

13

>600

14


Som i dette enkle eksemplet, er det noen ganger ønskelig (men ikke avgjørende) å plassere søkekriterieområdet direkte under databasetabellen, med kolonnene til de to områdene vertikalt justert. Tomme oppføringer i søkekriterieområdet ignoreres. Med eksempeldatabasetabellen ovenfor og dette søkekriterieområdet setter du inn formelen =DCOUNT(A1:E10;;A12:E14) i en tom celle et annet sted i arket for å telle hvordan mange av Joes gjester reiser lenger enn 600 meter til skolen. Verdien 5 returneres (teller Betty, Daniel, Eva, Harry og Irene).

Merk også at formelen =DCOUNT(A1:E10;;D12:D13) returnerer nøyaktig samme verdi, noe som viser at det bare er nødvendig at søkekriterieområdet inneholder relevant kolonne overskrifter.

Example 2

   A   

   B   

   C   

   D   

   E   

12

Age

Grade

13

>7

2

14


In this example the search criteria area contains only two headings and these are not vertically aligned with the corresponding headings in the example database table. Since there are two conditions in the same row, these are connected by AND. With the above example database table and this search criteria area, insert the formula =DCOUNT(A1:E10;;B12:C13) into an empty cell elsewhere in the sheet to count how many of Joe’s guests are in grade 2 and greater than 7 years old. The value 2 is returned (counting Eva and Irene).

Example 3

   A   

   B   

   C   

   D   

   E   

12

Age

13

9

14

10


In this example the search criteria area contains only one heading. Since there are two conditions in consecutive rows, these are connected by OR. With the above example database table and this search criteria area, insert the formula =DCOUNT(A1:E10;;B12:B14) into an empty cell elsewhere in the sheet to count how many of Joe’s guests are either 9 or 10 years old. The value 4 is returned (counting Andy, Betty, Charles, and Harry).

Example 4

   A   

   B   

   C   

   D   

   E   

12

Age

Age

13

>=8

<=10

14


In this example the search criteria area contains two occurrences of the same heading. Since there are two conditions in the same row, these are connected by AND. With the above example database table and this search criteria area, insert the formula =DCOUNT(A1:E10;;B12:C13) into an empty cell elsewhere in the sheet to count how many of Joe’s guests are aged between 8 and 10 (inclusive). The value 6 is returned (counting Andy, Betty, Charles, Eva, Harry, and Irene).

Example 5

   A   

   B   

   C   

   D   

   E   

12

Name

13

F*

14


This simple example shows the use of wildcards. For this example to work as intended, select to enable wildcards at - LibreOffice Calc - Calculate. With the above example database table and this search criteria area, insert the formula =DCOUNT(A1:E10;;A12:A13) into an empty cell elsewhere in the sheet to count how many of Joe’s guests have names that begin with the letter “F”. The value 1 is returned (counting Frank).

Example 6

   A   

   B   

   C   

   D   

   E   

12

Name

13

[ABC].*

14


This simple example shows the use of regular expressions. For this example to work as intended, select to enable regular expressions at - LibreOffice Calc - Calculate. With the above example database table and this search criteria area, insert the formula =DCOUNT(A1:E10;;A12:A13) into an empty cell elsewhere in the sheet to count how many of Joe’s guests have names that begin with the letters “A”, “B”, or “C”. The value 3 is returned (counting Andy, Betty, and Charles).

DANTALLA (DCOUNTA på engelsk)

DCOUNTA counts the number of cells (fields) of the specified column that are not blank, for all rows (database records) that match the specified search criteria. Blank cells of the specified column are not counted. However, if no column is specified, DCOUNTA returns the count of all records that match the specified search criteria irrespective of their contents.

Syntax

DCOUNT(Database; [DatabaseField]; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">600" (this search criterion will match records in the database table that have a value greater than 600 in the Distance column).

Insert the formula =DCOUNTA(A1:E10;; A12:E13) into an empty cell elsewhere in the sheet to calculate how many of Joe’s party guests travel further than 600 meters to school. The value 5 is returned.

The same result is obtained if you use the formula =DCOUNTA(A1:E10; "Distance"; A12:E13) or the formula =DCOUNTA(A1:E10; "Name"; A12:E13). The latter case reflects that in contrast to DCOUNT, DCOUNTA counts both numeric and alphanumeric values in the column indicated by the DatabaseField argument.

DANTALL (DCOUNT på engelsk)

DCOUNT counts the number of cells (fields) of the specified column that contain numeric values, for all rows (database records) that match the specified search criteria. However, if no column is specified, DCOUNT returns the count of all records that match the specified search criteria irrespective of their contents.

Syntax

DCOUNT(Database; [Databasefelt]; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">600" (this search criterion will match records in the database table that have a value greater than 600 in the Distance column).

Insert the formula =DCOUNT(A1:E10;; A12:E13) into an empty cell elsewhere in the sheet to calculate how many of Joe’s party guests travel further than 600 meters to school. The value 5 is returned.

The same result is obtained if you use the formula =DCOUNT(A1:E10; "Distance"; A12:E13), because all entries in the Distance column are numeric. However, if you use the formula =DCOUNT(A1:E10; "Name"; A12:E13), the value 0 is returned because all entries in the Name column are non-numeric.

DHENT

DGET returns the contents of the cell (field) of the specified column, for the single row (database record) that matches the specified search criteria.

Calc reports Err:502 (invalid argument) if multiple matches are found, or a #VALUE! error (wrong data type) if no matches are found. A #VALUE! error is also reported if a single match is found but the relevant cell is empty.

Syntax

DHENT(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell C13 which should contain "11" (this search criterion will match records in the database table that have a value of 11 in the Age column).

Insert the formula =DGET(A1:E10; "Name"; A12:E13) into an empty cell elsewhere in the sheet to find the name of Joe’s party guest who is age 11. The name Daniel is returned.

If you change the value in cell C13 to “10”, then the formula =DGET(A1:E10; "Name"; A12:E13) returns an invalid argument error (Err:502). The reflects that multiple records match the specified criterion (both Betty and Charles are age 10).

DMAKS

DMAX calculates the maximum value across the cells (fields) of the specified column that contain numeric values, for all rows (database records) that match the specified search criteria. Blank cells or cells containing non-numeric characters are not included.

Returns 0 if no matches are found, or if there are no non-zero numeric values in the cells of the specified column for the matching records.

Syntax

DMAKS(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DMAX(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to find the maximum distance in meters that any of Joe’s party guests travel to school. The value 1200 is returned.

DMIDDEL

DAVERAGE calculates the average of the numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Non-numeric values in those cells are ignored.

Returns a #DIV/0! error if no records match the specified search criteria, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DMIDDEL(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DAVERAGE(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to calculate the average distance in meters travelled to school by Joe’s party guests. The value 666.67 is returned.

DMIN

DMIN calculates the minimum value across the cells (fields) of the specified column that contain numeric values, for all rows (database records) that match the specified search criteria. Blank cells or cells containing non-numeric characters are not included.

Returns 0 if no matches are found, or if there are no non-zero numeric values in the cells of the specified column for the matching records.

Syntax

DMIN(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DMIN(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to find the minimum distance in meters that any of Joe’s party guests travel to school. The value 150 is returned.

DPRODUKT

DPRODUCT calculates the product of all numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Blank cells or cells containing non-numeric characters are not included.

Returns 0 if no matches are found, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DPRODUKT(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell C13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DPRODUCT(A1:E10; "Age"; A12:E13) into an empty cell elsewhere in the sheet to calculate the product of the ages in years of Joe’s party guests. The value 279417600 is returned.

DSTDAV

DSTDEV calculates the sample standard deviation based on the numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Non-numeric values are ignored.

Returns a #NUM! error if exactly one record matches the specified search criteria, or if there is only one numeric value in the cells of the specified column for the matching records.

Returns 0 if no matches are found, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DSTDAV(Database; Databasefelt; Søkekriterier)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:D13 are blank and that cell E13 contains ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DSTDEV(A1:E10; "Weight"; A12:E13) into an empty cell elsewhere in the sheet to calculate the sample standard deviation of the weights in kg of Joe’s party guests. The value 5.5 is returned.

DSTDAVP

DSTDEVP calculates the population standard deviation based on the numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Non-numeric values are ignored.

Returns a #NUM! error if no records match the specified search criteria, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DSTDAVP(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:D13 are blank and that cell E13 contains ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DSTDEVP(A1:E10; "Weight"; A12:E13) into an empty cell elsewhere in the sheet to calculate the population standard deviation of the weights in kg of Joe’s party guests. The value 5.18545 is returned.

DSUM

DSUM calculates the sum of all numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Blank cells or cells containing non-numeric characters are not included.

Returns 0 if no matches are found, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DSUM(Database; Databasefelt; Søkekriterier)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DSUM(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to find the total distance in meters that all of Joe’s party guests travel to school. The value 6000 is returned.

DVARIANS

DVAR calculates the sample variance based on the numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Non-numeric values are ignored.

Returns a #NUM! error if exactly one record matches the specified search criteria, or if there is only one numeric value in the cells of the specified column for the matching records.

Returns 0 if no matches are found, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DVARIANS(Database; Databasefelt; Søkekriterium)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DVAR(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to find the sample variance of the distances in meters that Joe’s party guests travel to school. The value 193125 is returned.

DVARIANSP

DVARP calculates the population variation based on the numeric values in the cells (fields) of the specified column, for all rows (database records) that match the specified search criteria. Non-numeric values are ignored.

Returns a #NUM! error if no records match the specified search criteria, or if there are no numeric values in the cells of the specified column for the matching records.

Syntax

DVARIANSP(Database; Databasefelt; Søkekriterier)

Example

The example database table giving information about the guests invited to Joe’s birthday party (described above) should occupy cells A1:E10. The content of cells A12:E12 should be identical to the header labels for the database table in cells A1:E1. Make sure that cells A13:E13 are blank, except for cell D13 which should contain ">0" (this search criterion is intended to match all records in the database table).

Insert the formula =DVARP(A1:E10; "Distance"; A12:E13) into an empty cell elsewhere in the sheet to find the population variance of the distances in meters that Joe’s party guests travel to school. The value 171666.67 is returned.