Database Table Reference

LibreOffice 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:

Příklad

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

A

B

C

D

1

Name

Region

Prodeje

Seniorita

2

Smith

západ

21

5

3

Jones

východ

23

11

4

Johnson

západ

9

7

5

Taylor

západ

34

11

6

Brown

východ

23

15

7

Walker

východ

12

4

8

Edwards

East

15

12

9

Thomas

západ

17

10

10

Wilson

západ

31

3

11

Celkem

2

185

8.67


The cell range A1:D11 was defined as the database range "myData ". The options Contains column labels and Contains totals row were checked when defining the database range.

Referencing data in tables

A database table reference has the form name of database_range[…]. The part inside the square brackets can be a reserved reference keyword, a field name in square brackets, or a combination of the two.

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

Příklad

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

Vyhrazená klíčová slova v odkazech

Klíčové slovo

Použití

Příklad

[#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.


Field name in square brackets

To reference the array of all values in the records that belong to the same field, use the form [field name]. The referenced cell range does not include label and totals.

Příklad

Výraz myData[[Region]] nebo jeho zjednodušená forma myData[Region] odkazuje na buňky B2:B10. Pokud nemá databázová oblast popisky řádků, lze použít obecné popiskyColumn1, Column2.

Ikona poznámky

Pokud v aplikaci Microsoft Excel patří buňka se vzorcem do tabulky, lze název tabulky vynechat. Například vzorec =SUM(myData[Sales]) by mohl být zapsán v buňce C11 jako =SUM([Sales]). Vynechání názvu tabulky zatím v aplikaci Calc není možné.


Kombinace

Sloupce a datové záznamy

Pro odkazování na kombinaci popisků sloupců a datových záznamů použijte formát [#Headers];[#Data] nebo [#Headers],[#Data], kde oddělovač je stejný jako oddělovač pro parametry funkcí, který je definován v Nástroje - Možnosti - Calc - Vzorec - Oddělovače.

Datové záznamy a řádek součtu

Pro odkazování na kombinaci datových záznamů a řádku součtu použijte [#Data];[#Totals]. Například myData[[#Data];[#Totals]] odkazují na buňky A2:D11.

Kombinace, jako je například [#Headers];[#Totals], není možná, protože by vedla ke dvěma nesouvislým obdélníkům buněk.

Sousední sloupce

To reference several adjacent columns, use the range operator “:”. For example, the formula myData[[Name]:[Sales]] addresses the cells A2:C10.

Non-adjacent columns

The use of non-adjacent columns is not possible since it would reference two separate cell rectangles.

Field name and keyword

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.

Podpořte nás!

Podpořte nás!