value_format

使用状況

ビュー: view_name {
dimension: field_name {
value_format:"$#.00;($#.00")
}
}
階層
value_format
使用可能なフィールドタイプ
ディメンション、測定

許可
Excel スタイルの書式設定を含む文字列

定義

value_format パラメータを使用すると、Excel スタイル形式を使用して Looker でデータ値をフォーマットできます。value_format は次の方法で使用できます。

  • Excel スタイルの書式設定を特定のディメンションまたはメジャーに直接適用するために、フィールド レベルで単独で調整
  • named_value_format パラメータのサブパラメータとして、モデルレベルで、複数のフィールドに適用できる再利用可能なカスタム形式を作成する

ディメンションとメジャーに value_format を直接適用しています

value_format パラメータは、ディメンションとメジャーの両方で使用できます。value_format を使用して Excel スタイルの書式設定をディメンションに適用するには、ディメンション タイプを number にする必要があります。value_format を使用して Excel スタイルの書式設定をメジャーに適用するには、メジャーが type: string ではなく数値であることを確認します。例:

dimension: order_amount {
  type: number
  sql: ${TABLE}.order_amount ;;
  value_format: "$#.00;($#.00)"
}
measure: total_order_amount {
  type: sum
  sql: ${order_amount} ;;
  value_format: "$#.00;($#.00)"
}

value_format を使用して再利用可能なカスタム形式を定義する

named_value_formatvalue_format を使用して再利用可能な形式を定義する方法については、named_value_format パラメータのドキュメントをご覧ください。

デフォルトの書式設定オプション

Looker の組み込み値の形式のいずれかを適用する場合は、value_format_name パラメータのドキュメント ページのデフォルトの形式の名前に記載されている形式から選択できます。value_format_name を使用して組み込みフォーマットを適用する手順については、このページをご覧ください。

一般的な書式設定文字列

value_format では Excel 形式の書式設定文字列を使用できます。

value_format パラメータで使用する書式は、visualizationValue 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)
                              #   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)
                              #   Note division by 1 million happens automatically
value_format: "0.000,\" K\""  # Number in thousands with 3 decimals (1.234 K)
                              #   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%)

value_format パラメータを使用した高度な条件付き書式の例については、value_format を使用した条件付き書式をご覧ください。

一般的な課題

除算の小数点以下が切り捨てられる

value_format の使用時によく発生する落とし穴の 1 つは、SQL が整数数学を処理する方法です。5 を 2 で割ると、たいていの場合、結果は 2.5 になると予想されます。ただし、多くの SQL 言語では、結果を 2 として返します。2 つの整数を除算すると、結果が整数として返されるためです。これに対処するには、分子に 10 進数(1.0、100.0 など)を掛けて、SQL が小数の結果を返すよう強制します。例:

measure: active_users_percent {
  type: number
  sql: 100.000 * ${active_users} / ${users} ;;
  value_format: "0.000"
}

value_formatnumber_format ユーザー属性とともに使用する

モデルのフィールドの書式設定に value_format を使用する場合、number_format ユーザー属性で選択された数値形式は、value_format で適用される形式の上に適用されます。例と詳細については、数値の形式をローカライズするをご覧ください。