こんにちは、NoCodeCampのツバサです。
今回は、Airtableを使ってコースごとに参加しているユーザー数と、コース合計料金を計算するTableをAirtableで作っていきます。
![](https://i.gyazo.com/54c1157a8c5ec4fc2e01baaf674a8d47.png)
Airtableで塾や、ジム、ダンスクラブなどで、レッスンがあるときに「コースにユーザーが何人いるのか?」「コースごとの売上はいくらか?」などに使えます。
Airtableデータの準備
今回は、
User2とLessonとTableを用意します。
Userは、LessonとRelationになってます。
![](https://i.gyazo.com/1f441960d47c6560b9c997b30efa3a46.png)
Lessonのtableは、以下のようになります。
name (Text)
金額 (number)
参加ユーザー(User2とのReation)
コースへの参加人数 (Count)
コースの全体の売上 (Formula)
![](https://tsubasa.tech/wp-content/uploads/2021/04/image-1024x334.png)
参加人数はCountFieldで計算します。
CountFieldは、指定のColumにあるRelationの数をカウントしてくれます。
How can I count the number of linked records in a linked record field (column)?
https://support.airtable.com/hc/en-us/articles/215456008-How-can-I-count-the-number-of-linked-records-in-a-linked-record-field-column-
![](https://tsubasa.tech/wp-content/uploads/2021/04/image-2-1024x349.png)
集計はFomulaFieldで計算してます。
今回は、人数(金額) × 金額(コースへの参加人数で計算)
Formula field reference
https://support.airtable.com/hc/en-us/articles/203255215-Formula-field-reference
最後にGroupで、Userで括ればUserごとのフィールドを計上することが可能です。
![](https://i.gyazo.com/31d7ba437d6a687e0a576fce95bf1951.png)
まとめ
今回は、AirtableのCountFieldとFomulaFieldの組み合わせですが、成績管理や、売上管理を使うときには、よく使うコンビネーションだと思います。Airtableは、Fieldを使い分ければかなり、便利な管理ツールになりますので、一つずつ覚えましょう。
Guide to the basic field types
https://support.airtable.com/hc/en-us/articles/203229705-Guide-to-the-basic-field-types