|
| 1 | +==================== |
| 2 | +Dynamic pivot tables |
| 3 | +==================== |
| 4 | + |
| 5 | +.. role:: raw-html(raw) |
| 6 | + :format: html |
| 7 | + |
| 8 | +.. |formula| replace:: :raw-html:`<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 121.83 122.88" style="enable-background:new 0 0 121.83 122.88" xml:space="preserve"><g><path d="M27.61,34.37l-4.07,4.6l0.4,1.74h10.48c-2.14,12.38-3.74,23.54-6.81,40.74c-3.67,21.94-5.78,27.33-7.03,29.3 c-1.1,1.95-2.68,2.96-4.82,2.96c-2.35,0-6.6-1.86-8.88-3.97c-0.82-0.56-1.79-0.42-2.82,0.26C2,111.74,0,114.42,0,116.82 c-0.12,3.24,4.21,6.06,8.34,6.06c3.64,0,9-2.28,14.64-7.64c7.71-7.31,13.48-17.34,18.3-39.02c3.1-13.84,4.56-22.84,6.74-35.5 l13.02-1.18l2.82-5.17H49.2C52.99,10.53,55.95,7,59.59,7c2.42,0,5.24,1.86,8.48,5.52c0.96,1.32,2.4,1.18,3.5,0.28 c1.85-1.1,4.13-3.92,4.28-6.48C75.96,3.5,72.6,0,66.82,0C61.58,0,53.55,3.5,46.8,10.38c-5.92,6.27-9.02,14.1-11.16,23.99H27.61 L27.61,34.37z M69.27,50.33c4.04-5.38,6.46-7.17,7.71-7.17c1.29,0,2.32,1.27,4.53,8.41l3.78,12.19 c-7.31,11.18-12.66,17.41-15.91,17.41c-1.08,0-2.17-0.34-2.94-1.1c-0.76-0.76-1.6-1.39-2.42-1.39c-2.68,0-6,3.25-6.06,7.28 c-0.06,4.11,2.82,7.05,6.6,7.05c6.49,0,11.98-6.37,22.58-23.26l3.1,10.45c2.66,8.98,5.78,12.81,9.68,12.81 c4.82,0,11.3-4.11,18.37-15.22l-2.96-3.38c-4.25,5.12-7.07,7.52-8.74,7.52c-1.86,0-3.49-2.84-5.64-9.82l-4.53-14.73 c2.68-3.95,5.32-7.27,7.64-9.92c2.76-3.15,4.89-4.49,6.34-4.49c1.22,0,2.28,0.52,2.94,1.25c0.87,0.96,1.39,1.41,2.42,1.41 c2.33,0,5.93-2.96,6.06-6.88c0.12-3.64-2.14-6.74-6.06-6.74c-5.92,0-11.14,5.1-21.19,20.04l-2.07-6.41 c-2.9-9-4.82-13.63-8.86-13.63c-4.7,0-11.16,5.78-17.48,14.94L69.27,50.33L69.27,50.33z"/></g></svg>` |
| 9 | + |
| 10 | +When a pivot view from an Odoo database is inserted in a spreadsheet, it is by default a static |
| 11 | +pivot table. Each cell in a static pivot table contains an :ref:`Odoo-specific function |
| 12 | +<insert/pivot-table/functions-static>` that retrieves data from your database. |
| 13 | + |
| 14 | +.. image:: dynamic_pivot_tables/pivot-function-static.png |
| 15 | + :alt: Function of static pivot table cell |
| 16 | + |
| 17 | +When the corresponding data in your database changes, e.g., the sales related to a given quarter or |
| 18 | +an individual salesperson, the cells of your static pivot table are updated. |
| 19 | + |
| 20 | +However, a static pivot table does not expand automatically to accommodate new data, e.g., sales |
| 21 | +data for a new quarter or for a newly hired salesperson. Neither is it possible to add or manipulate |
| 22 | +dimensions (i.e., columns or rows) or measures via the pivot table properties. |
| 23 | + |
| 24 | +.. note:: |
| 25 | + If you attempt to update or manipulate the properties of a pivot table that has just been |
| 26 | + inserted into a spreadsheet, an error message appears in the top right corner of the screen: |
| 27 | + |
| 28 | + .. image:: dynamic_pivot_tables/pivot-table-error.png |
| 29 | + :alt: Error message when trying to manipulate static pivot table |
| 30 | + |
| 31 | +To have more flexibility in how you can manipulate your pivot table, you can :ref:`create a dynamic |
| 32 | +pivot table <dynamic_pivot_tables/create>` from a static pivot table. |
| 33 | + |
| 34 | +.. _dynamic_pivot_tables/create: |
| 35 | + |
| 36 | +Create a dynamic pivot table |
| 37 | +============================ |
| 38 | + |
| 39 | +There are two main ways to create a dynamic pivot table from a static pivot table: |
| 40 | + |
| 41 | +- **Duplicate the static pivot table from the pivot table properties**: :ref:`Open the pivot table |
| 42 | + properties <insert/pivot-table/properties>`, click the :icon:`fa-cog` (cog) icon at the top right |
| 43 | + of the pane, then click :icon:`fa-copy` :guilabel:`Duplicate`. |
| 44 | + |
| 45 | + A new data source is created and a dynamic version of the pivot table is inserted in a new sheet. |
| 46 | + The styling of the original pivot table is maintained. |
| 47 | + |
| 48 | + .. note:: |
| 49 | + When you use this method, your new dynamic pivot table gets the next available pivot ID. This |
| 50 | + means you can create multiple pivot views that are associated with the same model, but that can |
| 51 | + have distinct settings, groupings or calculations. |
| 52 | + |
| 53 | +- **Re-insert the dynamic pivot table from the Data menu**: On the sheet that contains your static |
| 54 | + pivot, position your cursor in an empty cell. Click :menuselection:`Data --> Re-insert dynamic |
| 55 | + pivot` from the menu bar then select the relevant pivot table. A new pivot table appears with the |
| 56 | + same styling as the static pivot. |
| 57 | + |
| 58 | + .. note:: |
| 59 | + When you use this method, both your static and dynamic pivot have the same pivot ID. To avoid |
| 60 | + confusion, delete the original static pivot table. |
| 61 | + |
| 62 | +.. tip:: |
| 63 | + It is also possible to directly enter the :ref:`function <dynamic_pivot_tables/functions>` of the |
| 64 | + dynamic pivot table in an empty cell. However, with this method, the table styling needs to be |
| 65 | + re-applied manually. |
| 66 | + |
| 67 | +.. _dynamic_pivot_tables/functions: |
| 68 | + |
| 69 | +Dynamic pivot table functions |
| 70 | +----------------------------- |
| 71 | + |
| 72 | +Instead of each cell containing a unique function that retrives data from your database, as in a |
| 73 | +:ref:`static pivot table <insert/pivot-table/functions-static>`, a dynamic pivot table has one |
| 74 | +unique function: |
| 75 | + |
| 76 | +.. code-block:: text |
| 77 | +
|
| 78 | + =PIVOT( pivot_id, [row_count], [include_total], [include_column_titles], [column_count] ) |
| 79 | +
|
| 80 | +The arguments of the function are as follows: |
| 81 | + |
| 82 | +- `pivot_id`: the id assigned when the pivot table is inserted. The first pivot table |
| 83 | + inserted in a spreadsheet is assigned pivot id 1, the second, pivot id 2, etc. |
| 84 | +- `row_count` and `column count`: the number of rows and columns respectively. |
| 85 | +- `include_total` and `include_column_titles`: values of `0` remove the total and column |
| 86 | + titles respectively. |
| 87 | + |
| 88 | +This is an array function, which allows the pivot table to expand automatically to accommodate the |
| 89 | +results of the function. |
| 90 | + |
| 91 | +The top-left cell contains the editable function, while clicking on any other cell reveals this |
| 92 | +formula greyed out. |
| 93 | + |
| 94 | +.. image:: dynamic_pivot_tables/pivot-function-dynamic.png |
| 95 | + :alt: Array function of a dynamic pivot table |
| 96 | + |
| 97 | +.. tip:: |
| 98 | + If necessary, you can update the function of a dynamic pivot table, via the top-left cell, to |
| 99 | + remove elements like the total or column titles. |
| 100 | + |
| 101 | + With the function open in the formula bar or the top-left cell, position your cursor after the |
| 102 | + pivot ID then type `,` to advance to the optional field you want to modify and update as needed. |
| 103 | + For example, adding the value `0` for `[include_total]` removes the totals row and column from |
| 104 | + the pivot table. |
| 105 | + |
| 106 | +.. _dynamic_pivot_tables/manipulate: |
| 107 | + |
| 108 | +Manipulate a dynamic pivot table |
| 109 | +================================ |
| 110 | + |
| 111 | +To manipulate data in a dynamic pivot table, :ref:`open the pivot table properties |
| 112 | +<insert/pivot-table/properties>`. |
| 113 | + |
| 114 | +The following options are available by clicking the :icon:`fa-cog` icon: |
| 115 | + |
| 116 | +- :icon:`fa-exchange` :guilabel:`Flip axes`: to move the dimensions represented in columns to rows |
| 117 | + and vice versa. |
| 118 | + |
| 119 | + .. tip:: |
| 120 | + Flipping the axes presents the data from a different perspective, possibly bringing new |
| 121 | + insights. However, depending on the volume of data, it can result in #SPILL errors. This |
| 122 | + happens when a formula tries to output a range of values, but something is blocking those |
| 123 | + cells, such as other data, merged cells, or the boundaries of the current sheet. |
| 124 | + |
| 125 | + Hovering over the cell containing :guilabel:`#SPILL` details the error. |
| 126 | + |
| 127 | +- :icon:`fa-copy` :guilabel:`Duplicate`: to duplicate the dynamic pivot table and create a new data |
| 128 | + source with distinct properties. |
| 129 | +- :icon:`fa-trash` :guilabel:`Delete`: to delete the data source of the dynamic pivot table. |
| 130 | + |
| 131 | + .. note:: |
| 132 | + Deleting the data source of a pivot table does not delete the visual representation of the |
| 133 | + data. Delete the table from the spreadsheet using your preferred means. |
| 134 | + |
| 135 | +.. _dynamic_pivot_tables/manipulate/dimensions: |
| 136 | + |
| 137 | +Dimensions |
| 138 | +---------- |
| 139 | + |
| 140 | +The dimensions of your pivot table, i.e., how you are categorizing or grouping your data, are |
| 141 | +placed in :guilabel:`Columns` and :guilabel:`Rows` according to how they appeared in the |
| 142 | +:guilabel:`Pivot` :icon:`oi-view-pivot` view in your database, i.e. before the pivot table was |
| 143 | +inserted in the spreadsheet. |
| 144 | + |
| 145 | +You can: |
| 146 | + |
| 147 | +- :guilabel:`Add` new dimensions |
| 148 | +- or :icon:`fa-trash` (delete) dimensions |
| 149 | +- change the order in which dimensions are displayed in :guilabel:`Columns` or :guilabel:`Rows` by |
| 150 | + clicking then dragging the dimension to the desired position within its respective section |
| 151 | +- change the axis on which a dimension is shown, e.g., move a dimension from :guilabel:`Columns` |
| 152 | + to :guilabel:`Rows` |
| 153 | +- change how the data per column or row is ordered; the options are: :guilabel:`Ascending`, |
| 154 | + :guilabel:`Descending` and :guilabel:`Unsorted` |
| 155 | +- for date- or time-based fields, select the desired granularity of the data from the options in the |
| 156 | + drop-down menu |
| 157 | + |
| 158 | +.. _dynamic_pivot_tables/manipulate/measures: |
| 159 | + |
| 160 | +Measures |
| 161 | +-------- |
| 162 | + |
| 163 | +The measures of your pivot table, i.e., the data you are measuring, or analyzing, based on the |
| 164 | +dimensions you have chosen, are listed in the order they appeared in the |
| 165 | +:guilabel:`Pivot` :icon:`oi-view-pivot` view in your database. You can: |
| 166 | + |
| 167 | +- :guilabel:`Add` new measures, including :ref:`calculated measures |
| 168 | + <dynamic_pivot_tables/manipulate/measures-calculated-measures>` |
| 169 | +- :icon:`fa-eye` (hide), :icon:`fa-eye-slash` (show) or :icon:`fa-trash` (delete) existing measures |
| 170 | +- edit the name of existing measures by clicking on the name |
| 171 | +- change the order in which measures are displayed by clicking then dragging the measure |
| 172 | +- change how measures are displayed by clicking :icon:`fa-cog` then selecting the desired option |
| 173 | + from the drop-down menu, e.g., :guilabel:`% of grand total` or :guilabel:`Rank smallest to |
| 174 | + largest`. The pivot table data updates dynamically as different options are selected. |
| 175 | +- choose how measures are aggregated, e.g., by :guilabel:`Sum`, :guilabel:`Average`, |
| 176 | + :guilabel:`Minimum` |
| 177 | + |
| 178 | +.. _dynamic_pivot_tables/manipulate/measures-calculated-measures: |
| 179 | + |
| 180 | +Calculated measures |
| 181 | +~~~~~~~~~~~~~~~~~~~ |
| 182 | + |
| 183 | +It is possible to add :ref:`calculated measures |
| 184 | +<dynamic_pivot_tables/manipulate/measures-calculated-measures>` if such measures did not exist in |
| 185 | +the original pivot view. For example, you could add a calculated measure to show the average revenue |
| 186 | +per order, or the profit margin per product. |
| 187 | + |
| 188 | +To add a calculated measure: |
| 189 | + |
| 190 | +#. From the :guilabel:`Measures` section of the pivot table properties, click :guilabel:`Add` |
| 191 | +#. Below the scrollable list, click |formula| :guilabel:`Add calculated measure` |
| 192 | +#. Rename the calculated measure by clicking on the name and typing |
| 193 | +#. Click on the line starting with :guilabel:`=` and enter the formula. |
| 194 | + |
| 195 | + .. example:: |
| 196 | + In the below example, the average revenue per order is added by dividing the total sum of the |
| 197 | + sales per salesperson with the number of orders. |
| 198 | + |
| 199 | + .. image:: dynamic_pivot_tables/calculated-measure.png |
| 200 | + :alt: Formula for a calculated measure |
| 201 | + |
| 202 | +#. Select how the measure should be aggregated. |
| 203 | + |
| 204 | +.. tip:: |
| 205 | + There are advantages to using a static pivot table, for example, being able to see and manipulate |
| 206 | + the formulas behind individual cells. To have this possibility, select the relevant portion of |
| 207 | + your dynamic pivot table, copy it, then paste it in an empty part of the sheet. Click on any |
| 208 | + pasted cell to see the Odoo formula used to retrieve the information. |
| 209 | + |
0 commit comments