用途
named_value_format: desired_name {
value_format: "excel formatting string"
strict_value_format: yes | no
}
|
階層
named_value_format |
デフォルト値
なし
許可
カスタム形式の名前、形式を定義する Excel 形式の書式設定文字列、オプションの strict_value_format サブパラメータのブール値 |
定義
named_value_format パラメータを使用すると、複数のディメンションや指標に適用できるカスタム書式設定を作成して保存できます。
Looker のカスタム形式は、次の手順で作成して使用します。
- まず、モデルファイルで
named_value_formatを使用して、新しいカスタム形式の名前を宣言します。この名前はスペースを含まない文字列にする必要があります。 - 次に、
named_value_formatのvalue_formatサブパラメータを使用して、Excel スタイルの形式文字列を指定して、必要な形式を定義します。 - 最後に、フィールド レベルの
value_format_nameパラメータで参照して、このカスタム形式をディメンションと measure に適用します。
次の例に示すように、モデルで複数のカスタム形式を定義できます。
一般的な value_format フォーマット文字列
value_formatパラメータで使用される形式は、ビジュアリゼーションの [値の形式] フィールドで使用される形式と同じですが、value_formatパラメータでは、書式設定する文字列を二重引用符で囲む必要があります。ビジュアリゼーションの値の形式については、縦棒グラフのオプションのドキュメント ページをご覧ください。
これらの形式を指定する方法については、Excel の完全ガイドのドキュメントをご覧ください。ただし、現時点で Looker では日付の書式設定、色の書式設定、16 進変換はサポートされていません。
以下に、最も一般的な書式設定オプションを示します。国際通貨記号などのいくつかの特殊文字は、二重引用符で囲む必要があります。
value_format: "0" # Integer (123)
value_format: "*00#" # Integer zero-padded to 3 places (001)
value_format: "0 \" String\"" # Integer followed by a string (123 String)
# Please note "String" can be replaced with any other word
value_format: "0.##" # Number up to 2 decimals (1. or 1.2 or 1.23)
value_format: "0.00" # Number with exactly 2 decimals (1.23)
value_format: "*00#.00" # Number zero-padded to 3 places and exactly 2 decimals (001.23)
value_format: "#,##0" # Number with comma between thousands (1,234)
value_format: "#,##0.00" # Number with comma between thousands and 2 decimals (1,234.00)
value_format: "0.000,,\" M\"" # Number in millions with 3 decimals (1.234 M)
# Please note division by 1 million happens automatically
value_format: "0.000,\" K\"" # Number in thousands with 3 decimals (1.234 K)
# Please note division by 1 thousand happens automatically
value_format: "$0" # Dollars with 0 decimals ($123)
value_format: "$0.00" # Dollars with 2 decimals ($123.00)
value_format: "\"€\"0" # Euros with 0 decimals (€123)
value_format: "$#,##0.00" # Dollars with comma btwn thousands and 2 decimals ($1,234.00)
value_format: "$#.00;($#.00)" # Dollars with 2 decimals, positive values displayed
# normally, negative values wrapped in parenthesis
value_format: "0\%" # Display as percent with 0 decimals (1 becomes 1%)
value_format: "0.00\%" # Display as percent with 2 decimals (1 becomes 1.00%)
value_format: "0%" # Convert to percent with 0 decimals (.01 becomes 1%)
value_format: "0.00%" # Convert to percent with 2 decimals (.01 becomes 1.00%)
strict_value_format は number_format ユーザー属性をオーバーライドします
通常は、number_format ユーザー属性で設定された数値の形式は、named_value_format で作成された形式に加えて適用されます。ただし、省略可能な strict_number_format サブパラメータを yes に設定すると、number_format の形式は適用されず、フィールドは named_value_format の形式を保持します。例と詳細については、数値書式のローカライズのドキュメント ページをご覧ください。
デフォルトの書式設定オプション
Looker の組み込みの値形式のいずれかを適用する場合は、value_format_name パラメータのドキュメント ページのデフォルトの形式名セクションに記載されている形式から選択できます。value_format_name を使用して組み込み形式を適用する手順については、そのページをご覧ください。
例
€1.23K のような euro_in_thousands というカスタム形式を作成します。
named_value_format: euro_in_thousands {
value_format: "\"€\"0.000,\" K\""
}
number_formatting ユーザー属性が euro_in_thousands 形式に影響しないようにするには:
named_value_format: euro_in_thousands {
value_format: "\"€\"0.000,\" K\""
strict_value_format: yes
}
別の例については、数値書式のローカライズのドキュメント ページもご覧ください。
$1.23M のような usd_in_millions というカスタム形式と、(123) 456-7890 のような phone_number という形式を作成します。
named_value_format: usd_in_millions {
value_format: "$0.000,,\" M\""
}
named_value_format: phone_number {
value_format: "(###) ###-####"
}