|
| 1 | +--- |
| 2 | +navigation_title: Tables |
| 3 | +applies_to: |
| 4 | + stack: ga |
| 5 | + serverless: ga |
| 6 | +description: Instructions and best practices for building tables with {{kib}} Lens in Elastic. |
| 7 | +--- |
| 8 | + |
| 9 | +# Build tables with {{kib}} |
| 10 | + |
| 11 | +Tables are versatile visualizations that display your data in rows and columns, making them ideal for detailed data analysis and comparison. They're perfect for displaying multiple metrics side-by-side, showing individual records, or creating pivot tables that summarize data across different dimensions. |
| 12 | + |
| 13 | +Tables work with any type of data: numeric values, strings, dates, and more. You can organize data using rows, add metrics to analyze, and optionally split metrics into separate columns to create pivot-style views. Tables offer extensive customization options including sorting, filtering, formatting, and coloring. |
| 14 | + |
| 15 | +You can create tables in {{kib}} using [**Lens**](../lens.md). |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +## Build a table |
| 21 | + |
| 22 | +To build a table: |
| 23 | + |
| 24 | +:::::{stepper} |
| 25 | + |
| 26 | +::::{step} Access Lens |
| 27 | +**Lens** is {{kib}}'s main visualization editor. You can access it: |
| 28 | +- From a dashboard: On the **Dashboards** page, open or create the dashboard where you want to add a table, then add a new visualization. |
| 29 | +- From the **Visualize library** page by creating a new visualization. |
| 30 | +:::: |
| 31 | + |
| 32 | +::::{step} Set the visualization to Table |
| 33 | +New visualizations default to creating **Bar** charts. |
| 34 | + |
| 35 | +Using the dropdown indicating **Bar**, select **Table**. |
| 36 | +:::: |
| 37 | + |
| 38 | +::::{step} Define the data to show |
| 39 | +1. Select the {{data-source}} that contains your data. |
| 40 | +2. Define your table structure by dragging fields defining functions for one or more of these dimensions: |
| 41 | + - **Metrics**: The values to display in columns. You can use aggregation functions like `Sum`, `Average`, and `Count`, or create custom calculations with formulas. |
| 42 | + - **Rows** (optional): Fields that create the rows of your table. Each unique value becomes a row. You can use functions like **Top values**, **Date histogram**, **Intervals**, or **Filters** to organize your rows. You can add multiple fields as rows to create hierarchical groupings and break down the data more granularly. |
| 43 | + - **Split metrics by** (optional): Break metrics into separate columns based on a categorical field, creating a pivot table view. |
| 44 | +3. Optionally, customize individual columns by clicking on any dimension in the layer pane to configure formatting, alignment, coloring, and more. |
| 45 | + |
| 46 | +Refer to [](#settings) to find all configuration options for your table. |
| 47 | +:::: |
| 48 | + |
| 49 | +::::{step} Customize the table to follow best practices |
| 50 | +Tweak the appearance of the table to your needs. Consider the following best practices: |
| 51 | + |
| 52 | +**Make it scannable** |
| 53 | +: Use consistent formatting and alignment. For example, you can right-align numbers for easier comparison, and left-align text for readability. |
| 54 | + |
| 55 | +**Use color purposefully** |
| 56 | +: Apply color to values or cells to highlight important data or patterns. Avoid using too many colors that might distract from the data. |
| 57 | + |
| 58 | +**Add context with summary rows** |
| 59 | +: Use summary rows to show totals, averages, or other aggregate values that help users understand the overall picture. |
| 60 | + |
| 61 | +**Enable interactivity** |
| 62 | +: Turn on **Directly filter on click** to let users click on values to filter the dashboard or drill down into data. |
| 63 | + |
| 64 | +**Control density** |
| 65 | +: Adjust table density based on your use case. Use **Compact** for fitting more rows, **Expanded** for better readability. |
| 66 | + |
| 67 | +Refer to [](#settings) for a complete list of options. |
| 68 | +:::: |
| 69 | + |
| 70 | +::::{step} Save the table |
| 71 | +- If you accessed Lens from a dashboard, select **Save and return** to save the visualization and add it to that dashboard, or select **Save to library** to add the visualization to the Visualize library and be able to add it to other dashboards later. |
| 72 | +- If you accessed Lens from the Visualize library, select **Save**. A menu opens and offers you to add the visualization to a dashboard and to the Visualize library. |
| 73 | +:::: |
| 74 | + |
| 75 | +::::: |
| 76 | + |
| 77 | +## Advanced table scenarios |
| 78 | + |
| 79 | +### Create pivot tables |
| 80 | + |
| 81 | +Tables can display data in a pivot-style format by using the **Split metrics by** dimension. This creates separate columns for each unique value of the split field, which is great for comparing metrics across different categories. |
| 82 | + |
| 83 | +To create a pivot table: |
| 84 | + |
| 85 | +1. Create a **Table** visualization. |
| 86 | +2. Add a dimension to **Rows**. |
| 87 | +3. Add one or more metrics. |
| 88 | +4. Drag a categorical field to **Split metrics by** to create separate columns for each unique value. |
| 89 | + |
| 90 | +For example, you could show visits per date in rows, split by continent in columns, with visit count as the metric. This creates a pivot table showing visit counts for each continent over time. |
| 91 | + |
| 92 | +Refer to [Analyze the data in a table](../../dashboards/create-dashboard-of-panels-with-ecommerce-data.md#view-customers-over-time-by-continents) for a detailed example. |
| 93 | + |
| 94 | +### Use formulas in tables |
| 95 | + |
| 96 | +Tables support Lens formulas, which lets you create calculated columns with custom logic. You can use formulas to: |
| 97 | + |
| 98 | +* Calculate percentages or ratios between metrics |
| 99 | +* Compare current values to time-shifted values |
| 100 | +* Apply mathematical operations across multiple fields |
| 101 | +* Create conditional calculations |
| 102 | + |
| 103 | +To add a formula to a table: |
| 104 | + |
| 105 | +1. In the **Metrics** dimension, select **Add a field**. |
| 106 | +2. Select **Formula** from the function list. |
| 107 | +3. Enter your formula using the available functions and fields. |
| 108 | +4. Customize the column name and formatting. |
| 109 | + |
| 110 | +Refer to [](/explore-analyze/visualize/lens.md#lens-formulas) for formula examples and the {icon}`documentation` **Formula reference** available from Lens. |
| 111 | + |
| 112 | + |
| 113 | +## Table settings [settings] |
| 114 | + |
| 115 | +Customize your table to display exactly the information you need, formatted the way you want. |
| 116 | + |
| 117 | +### Metrics settings [metrics-options] |
| 118 | + |
| 119 | +**Value** |
| 120 | +: The metrics to display in your table columns. When you drag a field onto the table, {{kib}} suggests a function based on the field type. You can change it and use aggregation functions like `Sum`, `Average`, `Count`, `Median`, and more, or create custom calculations with formulas. |
| 121 | + |
| 122 | + Each metric becomes its own column in the table. If you use [**Split metrics by**](#columns-options), each metric is further split into multiple columns. |
| 123 | + |
| 124 | + Refer to [](/explore-analyze/visualize/lens.md#lens-formulas) for examples, or to the {icon}`documentation` **Formula reference** available from Lens. |
| 125 | + |
| 126 | + :::{include} ../../_snippets/lens-value-advanced-settings.md |
| 127 | + ::: |
| 128 | + |
| 129 | +**Appearance** |
| 130 | +: Define the formatting and behavior of each metric column, including: |
| 131 | + |
| 132 | + - **Name**: The column header label. By default, the chart uses the function or formula name. It's a best practice to customize this with a meaningful title. |
| 133 | + |
| 134 | + :::{include} ../../_snippets/lens-tables-column-appearance-settings.md |
| 135 | + ::: |
| 136 | + |
| 137 | + - **Summary row**: Add a row at the bottom of the table showing an aggregate value for this column. You can choose the aggregation function (`Sum`, `Average`, `Min`, `Max`, `Count`) and customize the **Summary label**. |
| 138 | + |
| 139 | +### Rows settings [rows-options] |
| 140 | + |
| 141 | +**Data** |
| 142 | +: Define which fields create the rows of your table. Drag a field to the **Rows** dimension, and {{kib}} suggests an appropriate function based on the field type. |
| 143 | + |
| 144 | + - **Functions**: |
| 145 | + - **Top values**: Show the most common values of a categorical field. Configure the number of values to display, ranking criteria, and sort direction. |
| 146 | + - **Number of values**: How many top values to display |
| 147 | + - **Rank by**: Which metric to use for ranking |
| 148 | + - **Rank direction**: Ascending or descending order |
| 149 | + - **Date histogram**: Group data by time intervals. Configure the time interval and how to handle date formatting. |
| 150 | + - **Intervals**: Create numeric ranges for continuous data. Useful for grouping numeric fields into buckets. |
| 151 | + - **Filters**: Define custom KQL filters to create specific row groups. Each filter creates one row in the table. |
| 152 | + |
| 153 | + - **Collapse by**: Aggregate rows that share the same value for this field into a single row, combining their metrics (for example, sum or average for each group). This is useful when you want to display a consolidated result for grouped values instead of individual rows. |
| 154 | + |
| 155 | + :::{include} ../../_snippets/lens-breakdown-advanced-settings.md |
| 156 | + ::: |
| 157 | + |
| 158 | +**Appearance** |
| 159 | +: - **Name**: Customize the column header label for the row dimension. |
| 160 | + :::{include} ../../_snippets/lens-tables-column-appearance-settings.md |
| 161 | + ::: |
| 162 | + - **Directly filter on click**: Make the values in this column clickable, so clicking a value adds a filter to your visualization or dashboard for that value. This interactivity is helpful for quickly drilling down into data. |
| 163 | + |
| 164 | +### Split metrics by settings [columns-options] |
| 165 | + |
| 166 | +**Data** |
| 167 | +: Optionally split your metrics into separate columns based on a categorical field. This creates a pivot table view where each unique value of the split field becomes its own column. This is useful for comparing the same metric across different categories side by side. |
| 168 | + |
| 169 | + You can configure: |
| 170 | + - **Number of values**: How many columns to create |
| 171 | + - **Rank by**: Which metric determines the top values |
| 172 | + - **Rank direction**: Sort order for selecting top values |
| 173 | + |
| 174 | + :::{include} ../../_snippets/lens-breakdown-advanced-settings.md |
| 175 | + ::: |
| 176 | + |
| 177 | +**Appearance** |
| 178 | +: - **Name**: Customize the split dimension. This name is not used on the table. |
| 179 | + |
| 180 | + |
| 181 | +### General table settings [appearance-options] |
| 182 | + |
| 183 | +```{applies_to} |
| 184 | +stack: ga 9.1 |
| 185 | +serverless: ga |
| 186 | +``` |
| 187 | + |
| 188 | +When creating or editing a table visualization, you can customize several appearance options. To do that, look for the {icon}`brush` icon. |
| 189 | + |
| 190 | +**Density** {applies_to}`stack: ga 9.1` {applies_to}`serverless: ga` |
| 191 | +: Control how much space each row occupies. Choose between: |
| 192 | + - **Compact**: Minimal spacing, fits more rows in less space |
| 193 | + - **Normal**: Balanced spacing (default) |
| 194 | + - **Expanded**: More generous spacing for improved readability |
| 195 | + |
| 196 | +**Max header cell lines** |
| 197 | +: Set the maximum number of lines that column headers can span. When header text is longer than this setting, it is truncated with an ellipsis. Use `Auto` to let {{kib}} determine the appropriate height, or set a specific number like `1`, `2`, or `3`. |
| 198 | + |
| 199 | +**Body cell lines** |
| 200 | +: Set the number of lines that body cells display. When cell content exceeds this limit, it is truncated with an ellipsis. Use `Auto` to automatically adjust based on content, or set a specific number like `1`, `2`, or `3` for consistent row heights. Setting this to `1` creates more compact tables, while higher values allow more content to be visible. |
| 201 | + |
| 202 | +**Paginate table** |
| 203 | +: Toggle pagination on or off. When enabled: |
| 204 | + - The table displays a limited number of rows per page. |
| 205 | + - Navigation controls appear at the bottom of the table when the table contains at least 10 items. By default, 10 rows appear per page. Users of the dashboard will be able to select a different number. |
| 206 | + - This is helpful for tables with many rows to improve performance and readability. |
| 207 | + |
| 208 | + When disabled, all rows appear in a scrollable view (up to the maximum returned by the query). |
| 209 | + |
| 210 | +## Table examples |
| 211 | + |
| 212 | +The following examples show various configuration options you can use for building effective tables. |
| 213 | + |
| 214 | +**Top pages by unique visitors** |
| 215 | +: Display the most visited pages on your website with the number of unique visitors: |
| 216 | + |
| 217 | + * **Rows**: `request.keyword` field using **Top values** function |
| 218 | + * **Number of values**: `5` |
| 219 | + * **Metrics**: `clientip` field using **Unique count** function |
| 220 | + * **Value format**: `Number` |
| 221 | + * **Text alignment**: `Right` |
| 222 | + |
| 223 | +  |
| 224 | + |
| 225 | +**Sales by date and continent (pivot table)** |
| 226 | +: Create a pivot table showing customer counts across different continents over time: |
| 227 | + |
| 228 | + * **Rows**: `order_date` field using **Date histogram** function |
| 229 | + * **Minimum interval**: `1d` |
| 230 | + * **Name**: `Sale per day` |
| 231 | + * **Metrics**: `customer_id` field using **Unique count** function |
| 232 | + * **Split metrics by**: `geoip.continent_name` field using **Top values** set to `3` |
| 233 | + |
| 234 | +  |
| 235 | + |
| 236 | +**Document comparison with custom ranges** |
| 237 | +: Compare metrics across custom-defined ranges: |
| 238 | + |
| 239 | + * **Rows**: `bytes` field using **Intervals** function |
| 240 | + * **Ranges**: |
| 241 | + * `0` → `10240`, labeled `Below 10KB` |
| 242 | + * `10240` → `+∞`, labeled `Above 10KB` |
| 243 | + * **Name**: `File size` |
| 244 | + * **Metrics**: `bytes` field using **Sum** function |
| 245 | + * **Name**: `Total bytes transferred` |
| 246 | + * **Value format**: `Bytes` |
| 247 | + * **Text alignment**: `Right` |
| 248 | + * **Additional styling**: |
| 249 | + * **Color by value**: Dynamic coloring to highlight ranges with higher byte transfers |
| 250 | + |
| 251 | +**Weekly sales with percentage change** |
| 252 | +: Show week-over-week sales trends with calculated percentage changes: |
| 253 | + |
| 254 | + * **Rows**: `order_date` field using **Date histogram** function |
| 255 | + * **Minimum interval**: `1w` |
| 256 | + * **Name**: `Week` |
| 257 | + * **Metrics** (two columns): |
| 258 | + 1. `Records` using **Count** function |
| 259 | + * **Name**: `Orders this week` |
| 260 | + 2. **Formula**: `count() / count(shift='1w') - 1` |
| 261 | + * **Name**: `Change from last week` |
| 262 | + * **Value format**: `Percent`, 2 decimals |
| 263 | + * **Color by value**: Dynamic (green for positive growth, red for negative) |
| 264 | + * **Text alignment**: `Right` |
| 265 | + |
0 commit comments