作成日:2022年8月29日
Tableauは、計算フィールドという機能を利用することで複雑な計算が必要な項目を作成することが出来ます。ここでは、二つのデータソースでIDのデータ型が異なる場合に、計算フィールドでデータ型を揃えて結合する方法を説明します。
完成図(例)

出典:Tableau標準「Join Calculations Starter.twbx」
1.「Join Calculations Starter.twbx」を開き、[データソース]ページ右上[追加] > [その他]を選択し、「Sales by Member.xlsx」データソースへの接続を追加します。

2.[シート]セクションで[データの表示]アイコンをクリックし、データソースのフィールドを確認します。

「メンバーシップコード」は5桁のID,コロン(:),姓名、「ID」フィールドは5桁の数値になっています。

4.シート[Club Membership]をダブルクリックし、シート[Sales]を「移行済みデータ」枠内にドラッグします。[結合計算の作成]を選択し、下記のように入力します。


※LEFT(string,number)関数は、文字列の一番左からnumberで指定された数の文字を返します。
※INT(expression)関数はexpression(今回は文字列)を整数に変換して返します。
※[Sales]の[ID]はデータ型が整数であり、LEFT関数は文字列を返すため上記型変換関数を使用しています。
5.[メンバーシップの分析]ワークシートで列に「総売上高」、行に「メンバーシップコード(Membership Code)」「入会年(Member Since)」をドラッグし、ツールバーで降順を選択してビュー作成完了です。

DMP構築のご相談
お気軽にお問い合わせください