Database Table Reference

LibreOfficeDev Calc lets you reference data in Database tables by using a special notation, a “database table reference”, for cell references inside the table. This special notation aims to improve the readability of formulas that reference cells inside a database table.

Database tables

Spreadsheet "tables" are defined by database ranges (Data - Define Range). In addition to the name of the database, the following is mandatory for using database table references:

Example

The table below contains values used in examples later on in this document.

A

B

C

D

1

Name

Region

Sales

Seniority

2

Smith

West

21

5

3

Jones

East

23

11

4

Johnson

Aust

9

7

5

Taylor

Vest

34

11

6

Brown

Aust

23

15

7

Walker

Aust

12

4

8

Edwards

East

15

12

9

Thomas

Vest

17

10

10

Wilson

Vest

31

3

11

Totalar

2

185

8.67


Celleområdet A1:D11 vart definert som databaseområdet "myData ". Alternativa Inneheld kolonneetikettar og Inneheld totalrad vart kontrollertt ved defineringa av databaseområdet.

Referer til data i tabellar

Ein databasetabellreferanse har formnamnet databaseområde[…]. Delen innanfor hakeparentesane kan vera eit reservert referansenøkkelord, eit feltnamn i hakeparenteser, eller ein kombinasjon av desse to.

In cases where a single keyword or a single field name is used, use single brackets instead of double brackets.

Example

myData[#Headers] instead of myData[[#Headers]] or myData[Region] instead of myData[[Region]].

Reserved reference keywords

Keyword

Usage

Example

[#Headers]

The keyword [#Headers] references the row of field names (column labels). It is the first row of the database range.

If the database range has no labels row defined (Contains columns row), a #REF! error is generated.

The expression myData[#Headers] references the cells A1:D1.

[#Data]

The keyword [#Data] references the data records of the database range, excluding the column label row and the totals row.

The short form myData[] can be used as well.

The expression myData[#Data] references the cell rectangle A2:D10.

[#Totals]

The keyword [#Totals] references the row of totals. It is the last row of the database range.

If the database range has no line of totals defined (Contains totals row), a #REF! error is generated.

The expression myData[#Totals] references the cells A11:D11.

[#All]

The keyword [#All] references the entire database range including column labels and totals.

The expression myData[#All] references the cells A1:D11.

[#This Row]

This keyword describes an implicit intersection.

If the expression myData[#This Row] is used in a formula in cell F2, it references A2:D2. If the same expression is used in a formula in cell F5, it references A5:D5.


Feltnamn i hakeparentesar

For å referera til matrisa med alle verdiane i postane som høyrer til det same feltet, bruk skjemaet [feltnamn]. Det refererte celleområdet tek ikkje med etikett og totalar.

Eksempel

The expression myData[[Region]] or its simplified form myData[Region] references the cells B2:B10. If the database range has no label row, generic labels like Column1, Column2 can be used.

note

In Microsoft Excel, if the formula cell belongs to the table, then the name of the table may be omitted. For example, the formula =SUM(myData[Sales]) in cell C11 could be written as =SUM([Sales]). Omission of the table name is not yet possible in Calc.


Combinations

Kolonnar og datapostar

For å referera til ein kombinasjon av kolonneetikettane og datapostane, bruk formatet [#Headers];[#Data] eller [#Headers],[#Data], der skiljeteikna er dei same som for funksjonsparameterane som er definerte i Verktøy → Innstillingar → Calc → Formel → Skiljeteikn.

Datapostar og totalrad

For å referera til ein kombinasjon av datapostar og totalrader, bruk [#Data];[#Totals]. For eksempel refererer myData[[#Data];[#Totals]] til cellene A2:D11.

Ein kombinasjon som [#Headers];[#Totals] er ikkje mogleg sidan det vil resultera i to usamanhengande cellerektangel.

Tilstøytande kolonnar

For å referera til fleire tilstøytande kolonnar, bruk områdeoperatoren «:». For eksempel vil formelen myData[[Namn]:[Sal]] adressera cellene A2:C10.

Ikkje-tilstøytande kolonnar

Bruk av ikkje-tilstøytande kolonnar er ikkje mogleg sidan det vil referera til to åtskilde cellerektangel.

Feltnamn og nøkkelord

The reference via field name and the use of a reference keyword can be combined. First state the keyword, then the function separator, and last the field name in brackets. For example, myData[[#Totals];[Sales]] references the cell C11.