Skip to content

Commit

Permalink
moved 'unique list' hack to summary tables
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliemisasi committed Dec 7, 2022
1 parent c286de9 commit 587fd2b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 53 deletions.
81 changes: 30 additions & 51 deletions help/formula-cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,43 +755,6 @@ sorted(
</details>
</section>

<span></span><section class="cheat-sheet">
#### Creating a Table of Unique Records
Quickly create a table of unique values by creating a [summary table](summary-tables.md) then [detach it](summary-tables.md#detaching-summary-tables) to turn it into an independant data table.

<span></span><details><summary>
#### Examples of Creating a Table of Unique Records
</summary>

<span class="screenshot-large">*![unique-values-initial-list](images/formula-cheat-sheet/unique-values-initial-list.png)*</span>
{: .screenshot-half }

We have a table of Students where some names are duplicated. Our first step in creating a unique table is to create a [summary table](summary-tables.md).

Under the green 'Add New' button, select 'Add New Page' then select 'Table' under 'Select Widget' and under 'Select Data' we'll choose the table with the duplicated values. In this example, that is our Students table. To create a summary table, click the green summation icon (<span class="grist-icon" style="--icon: var(--icon-Pivot)"></span>) then under 'Group By', select the column(s) where data is duplicated.

Click the green 'Add to Page' button to create the summary table.

<span class="screenshot-large">*![unique-values-create-summary-table](images/formula-cheat-sheet/unique-values-create-summary-table.png)*</span>
If you select multiple columns, the values across all selected columns create a single unique value. In our example, we have `McFly` duplicated in the 'Last Name' column, but each of these records has a different value in the 'First Name' column, `Marty` and `George`, making these their own unique record. You can see that in the summary table below.

<span class="screenshot-large">*![unique-values-summary-table](images/formula-cheat-sheet/unique-values-summary-table.png)*</span>
{: .screenshot-half }

Next, we want to turn our summary table into an independent data table. Open the table configuration panel on the right-hand side of the screen. Select the Data tab then 'Detach'.

<span class="screenshot-large">*![unique-values-detach](images/formula-cheat-sheet/unique-values-detach.png)*</span>

We now have a table containing all unique records.

<span class="screenshot-large">*![unique-values-final](images/formula-cheat-sheet/unique-values-final.png)*</span>
{: .screenshot-half }

**Video Walkthrough: [Back to Basics: Migrating from spreadsheet to Grist](https://www.youtube.com/watch?v=-mNh2P_Wa6c&t=2311s){:target="\_blank"}**

</details>
</section>

<span></span><section class="cheat-sheet">
#### Setting Default Values for New Records

Expand All @@ -818,6 +781,22 @@ For more examples from the Community, check out [Default values on the widget](h
</details>
</section>

<span></span><section class="cheat-sheet">
#### Formatting Telephone Numbers [ NEW ]

Format a phone number using the [PHONE_FORMAT()](https://support.getgrist.com/functions/#phone_format) function.

<span></span><details><summary>
#### Examples of Formatting Phone Numbers
</summary>

**Community Example: [Formatting Telephone Numbers](https://public.getgrist.com/kpjkFrJPRepr/Formula-Cheat-Sheet-Examples/p/2/m/fork){:target="\_blank"}**

*![formatting-us-phone-numbers](images/formula-cheat-sheet/formatting-us-phone-numbers.png)*</span>

</details>
</section>

<span></span><section class="cheat-sheet">
#### Formatting Telephone Numbers

Expand Down Expand Up @@ -1027,7 +1006,7 @@ You can find the number of days between two [Date](col-types.md#date-columns) va
<span></span><details><summary>
#### Example of Calculating the Difference Between Two Dates
</summary>
**Community Example:** [Difference Between 2 Dates](https://public.getgrist.com/kpjkFrJPRepr/Formula-Cheat-Sheet-Examples/p/6/m/fork)
**Community Example:** [Difference Between 2 Dates](https://public.getgrist.com/kpjkFrJPRepr/Formula-Cheat-Sheet-Examples/p/6/m/fork){:target="\_blank"}

<span class="screenshot-large">*![days-til-due](images/formula-cheat-sheet/days-til-due.png)*</span>

Expand All @@ -1051,7 +1030,7 @@ Here, we subtract today's date from the date in the Renewal Date column to find

You can also use the [DAYS()](functions.md#days) function to find difference in years. Take a look at our example in the Age column of the Calculating Age table.

**Community Example:** [Calculating Age in Years](https://public.getgrist.com/kpjkFrJPRepr/Formula-Cheat-Sheet-Examples/p/3/m/fork)
**Community Example:** [Calculating Age in Years](https://public.getgrist.com/kpjkFrJPRepr/Formula-Cheat-Sheet-Examples/p/3/m/fork){:target="\_blank"}

<span class="screenshot-large">*![diff-in-years](images/formula-cheat-sheet/diff-in-years.png)*</span>

Expand Down Expand Up @@ -1106,13 +1085,13 @@ Because we round to a whole number of years, the partial day (represented in sec
<span></span><section class="cheat-sheet">
#### Calculating the Difference Between Two Times

You can find the difference between two [DateTime](col-types.md#datetime-columns) values using Python's [divmod](https://docs.python.org/3/library/functions.html#divmod) function.
You can find the difference between two [DateTime](col-types.md#datetime-columns) values using Python's [divmod](https://docs.python.org/3/library/functions.html#divmod){:target="\_blank"} function.

<span></span><details><summary>
#### Example of Calculating the Difference Between Two Times
</summary>

**Community Example:** [Calculating Hours Worked](https://public.getgrist.com/a3HWPxrhNwJa/1863/p/4)
**Community Example:** [Calculating Hours Worked](https://public.getgrist.com/a3HWPxrhNwJa/1863/p/4){:target="\_blank"}

<span class="screenshot-large">*![hours-worked](images/formula-cheat-sheet/hours-worked.png)*</span>

Expand All @@ -1130,13 +1109,13 @@ The first two lines remove errors if there are no values in the Check In Time or

`s = ($Check_Out_Time - $Check_In_Time).total_seconds()` calculates the difference between Check In and Check Out then converts the time to seconds. This value is assigned to the variable `s`.

`hours = divmod(abs(s), 3600)` takes the absolute value of our total seconds and gets the number of hours (3600 seconds in 1 hour) using Python's [divmod](https://docs.python.org/3/library/functions.html#divmod) function. This number is assigned to the variable `hours`.
`hours = divmod(abs(s), 3600)` takes the absolute value of our total seconds and gets the number of hours (3600 seconds in 1 hour) using Python's [divmod](https://docs.python.org/3/library/functions.html#divmod){:target="\_blank"} function. This number is assigned to the variable `hours`.

`minutes = divmod(hours[1], 60)` uses the remainder of hours to calculate minutes. This is assigned to the variable `minutes`.

`"%dhr %dmin" % (hours[0], minutes[0])` uses the [`%`](https://docs.python.org/2/library/stdtypes.html#string-formatting-operations) string formatting operator to format our string, `%dhr %dmin`. Format specifiers begin with `%` followed by a character that represents the data type. %d is a placeholder for an integer. The first `%d` is replaced with `hours[0]` and the second `%d` is replaced with `minutes[0]`.
`"%dhr %dmin" % (hours[0], minutes[0])` uses the [`%`](https://docs.python.org/2/library/stdtypes.html#string-formatting-operations){:target="\_blank"} string formatting operator to format our string, `%dhr %dmin`. Format specifiers begin with `%` followed by a character that represents the data type. %d is a placeholder for an integer. The first `%d` is replaced with `hours[0]` and the second `%d` is replaced with `minutes[0]`.

Check out our [Time Tracker template](https://templates.getgrist.com/np7TVHmuvFcH/Simple-Time-Tracker) for another example!
Check out our [Time Tracker template](https://templates.getgrist.com/np7TVHmuvFcH/Simple-Time-Tracker){:target="\_blank"} for another example!

</details>

Expand All @@ -1159,13 +1138,13 @@ Check out our [Time Tracker template](https://templates.getgrist.com/np7TVHmuvFc
<span></span><section class="cheat-sheet">
#### Formatting Dates

Use Python's [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime) method to create a string representing the time with an explicit format. Bookmark the [Format Code Cheat Sheet](https://strftime.org/) for easy reference. You can also pull the year with [YEAR()](functions.md#year). This returns an integer. The same is true for [MONTH()](functions.md#month).
Use Python's [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime){:target="\_blank"} method to create a string representing the time with an explicit format. Bookmark the [Format Code Cheat Sheet](https://strftime.org/){:target="\_blank"} for easy reference. You can also pull the year with [YEAR()](functions.md#year). This returns an integer. The same is true for [MONTH()](functions.md#month).

<span></span><details><summary>
#### Examples of Formatting Dates
</summary>

**[Sales Commission Dashboard](https://templates.getgrist.com/pVq4xESKtU24/Sales-Commissions-Dashboard) Template**
**[Sales Commission Dashboard](https://templates.getgrist.com/pVq4xESKtU24/Sales-Commissions-Dashboard){:target="\_blank"} Template**

<span class="screenshot-large">*![strftime-year-month](images/formula-cheat-sheet/strftime-year-month.png)*</span>

Expand All @@ -1175,7 +1154,7 @@ $Date.strftime("%Y-%m")
```
`$Date` is the column where our initial date value is.

Next, we use the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime) method to format the date value from the `$Date` column, using the formatting codes found in the [Cheat Sheet](https://strftime.org/).
Next, we use the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime){:target="\_blank"} method to format the date value from the `$Date` column, using the formatting codes found in the [Cheat Sheet](https://strftime.org/){:target="\_blank"}.

Our formatting codes fall between quotes `""` because this is a string format.

Expand All @@ -1185,7 +1164,7 @@ We can include characters to separate our formatting codes. Here, we use `-` to

This is handy for summarizing data over each month. Create a column with year-month, like we saw in this example, then create a [summary table](summary-tables.md) grouped by the year-month column.

If you wish to summarize your data over each year, you would only include the formatting code for year within the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime) function.
If you wish to summarize your data over each year, you would only include the formatting code for year within the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime){:target="\_blank"} function.

The Year column of the Sales table is great example of of this.

Expand All @@ -1195,7 +1174,7 @@ The formula used in the Year column of the Sales table is:
```
$Date.strftime("%Y")
```
Again, we pull our initial date value from the `$Date` column. Next, we use the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime) method and format code `%Y` to show the year as a decimal number, e.g. 2022.
Again, we pull our initial date value from the `$Date` column. Next, we use the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime){:target="\_blank"} method and format code `%Y` to show the year as a decimal number, e.g. 2022.

Note that you can also use the built-in [YEAR()](functions.md#year) function to do the same thing.

Expand All @@ -1217,9 +1196,9 @@ MONTH($Date)
```
This formula returns the month value from the date in our Date column.

If you were to create a summary table grouped by Month, all data across different years of that month would be summarized. For example, if you have data from March 2021 and March 2022, it would all be summarized under `March`. This is where the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime) method comes in handy, allowing you to join Month and Year so you can report across each individual month of each year.
If you were to create a summary table grouped by Month, all data across different years of that month would be summarized. For example, if you have data from March 2021 and March 2022, it would all be summarized under `March`. This is where the [strftime()](https://docs.python.org/3/library/datetime.html#datetime.date.strftime){:target="\_blank"} method comes in handy, allowing you to join Month and Year so you can report across each individual month of each year.

Check out this [Community Forum post](https://community.getgrist.com/t/summary-table-with-content-from-multiple-tables/894) for an example using the [MONTH()](functions.md#month) and [YEAR()](functions.md#year) functions to summarize data across multiple tables.
Check out this [Community Forum post](https://community.getgrist.com/t/summary-table-with-content-from-multiple-tables/894){:target="\_blank"} for an example using the [MONTH()](functions.md#month) and [YEAR()](functions.md#year) functions to summarize data across multiple tables.

</details>

Expand Down
7 changes: 5 additions & 2 deletions help/summary-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ words, if a never-before-seen position (perhaps "Chief Troublemaker") appears in
data, a summary table would update automatically to include it, but a detached table will not.

!!! note "Use a detached Summary Table to create a table of unique values"
Create a summary table grouped by the column(s) that you wish to create a unique list of. Then, detach it. Now you have a table of unique values!
1. Create a summary table grouped by the column(s) that you wish to create a unique list of.
If you select multiple columns under 'Group By', the values across all selected columns create a single unique value.

2. Detach the Summary Table. Now you have a table of unique values!

If you select multiple columns under 'Group By', the values across all selected columns create a single unique value.
For a video walkthrough, check out [Back to Basics: Migrating from spreadsheet to Grist](https://www.youtube.com/watch?v=-mNh2P_Wa6c&t=2311s){:target="\_blank"}.

0 comments on commit 587fd2b

Please sign in to comment.