コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要
Billing
税金
レポート機能
データ
    概要
    スキーマ
    カスタムレポート
    Sigma API
    カスタムレポートを作成
    Sigma を使用してクエリを作成
    組織全体のデータに対してクエリを実行
    Stripe データを同期
    Data Pipeline
    データウェアハウスにデータをエクスポート
    クラウドストレージにデータをエクスポート
    データ管理
    データの鮮度
    ビジネスと商品データのユースケース
      取引データ
      不審請求の申し立てと不正利用データ
      すべての手数料データ
      Billing のデータ
      税務データ
      連結アカウントデータ
      カードの発行データ
    外部データをインポート
スタートアップの企業設立
ホーム財務の自動化DataBusiness and product data use cases

請求データのクエリ

Sigma または Data Pipeline を使用して、請求情報を取得します。

ページをコピー

Billing は、相互に連携する複数のコンポーネントで構成され、複数のテーブルのさまざまな側面の請求データを使用して、1 回限りの請求書や定期請求に対応します。主要なテーブルである subscriptions、invoices をはじめ、Billing 固有のテーブルはすべて、スキーマの Billing セクションにあります。

請求データをさらに調べるには、prices、products、coupons など、サブスクリプションや請求書のコンポーネントを示すその他のテーブルも利用できます。また、customers テーブルは Billing の基本的部分であり、レポート作成に必要なデータが収録されています。

サブスクリプション

subscriptions テーブルの各行は、個別の Subscription (サブスクリプション) オブジェクトに関するデータを示します。API でも、Stripe ダッシュボード内でも、同じ情報を取得できます。アカウントで作成するすべてのサブスクリプションに関するレポートを作成できます。

現在のサブスクリプション登録者についてのレポートを作成する際には、このテーブルから開始することをお勧めします。このテーブルは、他の関連テーブルに結合できるため、データをさらに詳細に調べることができます。

以下の例では、未払いとしてマークされたサブスクリプションと、その顧客の利用可能な連絡先情報のリストを取得します。

select subscriptions.id, subscriptions.customer_id, customers.email from subscriptions inner join customers on customers.id = subscriptions.customer_id where subscriptions.status = 'unpaid' limit 5
idcustomer_idメールアドレス
sub_RzsjuxM3jwoDvKKcus_7rfmUI5TJFhrSKejenny.rosen@example.com
sub_mSmqW5k0WiZOwCxcus_JSXGTZNNkcbI6ZGnoah.wilson@example.com
sub_fz7NJRwW67UFy68cus_H6goqdzl017nxj0joshua.miller@example.com
sub_AHztrVhjjJN7V2Qcus_MqaFdfuLQSqMo7Umadison.jackson@example.com
sub_JjWMVRuM2VXhfYScus_FNfX1We6gR6kp07elijah.smith@example.com

顧客

Customer (顧客) オブジェクトに関するデータは、customers テーブルに収録されています (これは、Billing テーブルグループには含まれません)。一般に請求ベースのレポートの一部として使用され、多数のテーブルと結合できます。保存された決済情報を使用して支払いを作成する場合にも利用できます。

次の例では、現在トライアル期間中のサブスクリプションの顧客のリストを取得します。各顧客の ID とメールアドレスの両方が取得されます。

select customers.id, customers.email, subscriptions.price_id from subscriptions inner join customers on customers.id = subscriptions.customer_id where subscriptions.status = 'trialing' limit 5
idメールアドレスprice_id
cus_gwpGPcJbozqOdCjjenny.rosen@example.comruby-pro-522
cus_xMF3WYHPyPr77DJnoah.wilson@example.comruby-pro-522
cus_6j8Aq5NOlCggujFrichard.jones@example.comgold-basic-221
cus_JApcxLfmhHvXbHFmadison.jackson@example.comgold-basic-221
cus_8L16HDQtMxZCN5Velijah.smith@example.comsilver-pro-498

商品と価格

商品は、顧客がサブスクリプションで購入できるアイテムを記述します。価格は商品に関連付けられており、コスト、請求期間、通貨を設定します。 subscriptions テーブルのデータを表示するときは、subscription_items と結合できます。さらに、アイテムの price_product_id を使用して、products.id に結合できます。

次の例では、有効なサブスクリプションのリストと、商品名およびその明細書表記を返します。

active_subscription_products.sql
with active_subscriptions as ( select s.id as subscription_id, p.name as product_name, p.statement_descriptor from subscriptions s join subscription_items si on s.id = si.subscription_id join products p on si.price_product_id = p.id where s.status = 'active' ) select subscription_id, subscription_item_id, price_id, product_name, statement_descriptor from active_subscriptions order by 1,2
id名前statement_descriptor
sub_ToVW5lowhz6QQdrruby-pro-522Ruby Pro
sub_1TQyjZkGVzPplzFgold-basic-221Gold Basic
sub_4QsTZ3wcDFCHCVXsilver-pro-498Silver Pro
sub_OyitMFug8UBCT6ydiamond-mid-244Diamond Mid
sub_WC0a6udGVZstonWruby-standard-196Ruby Standard

段階制料金

サブスクリプションで段階が設定された価格を使用している場合は、price_tiers テーブルで各段階に固有のデータを取得できます。たとえば、最初の段階の最大数量と使用されるユニット金額を含む、サブスクリプションの初期段階を把握するには、次のクエリを参照してください。

tiered_prices.sql
with subscription_item_prices as ( select si.subscription_id, si.price_id, p.currency from subscription_items si join prices p on si.price_id = p.id ), price_tier_details as ( select sp.subscription_id, pt.price_id, pt.upto, stringify_amount(sp.currency, pt.amount, '.') as tier_price, sp.currency from subscription_item_prices sp join price_tiers pt on sp.price_id = pt.price_id ) select ptd.subscription_id, ptd.price_id, ptd.upto, ptd.tier_price, ptd.currency from price_tier_details ptd order by ptd.subscription_id, ptd.price_id, ptd.upto asc
subscription_idprice_id最大tier_price通貨
sub_z9UUurfHq06JDZVprice_WRV2xeTt8s1PIoY302.00usd
sub_CmJEAM6VlbjczNvprice_fay3klUFtnBV84H601.00usd
sub_Ybg7jmmr1q00hktprice_OwQf25DNel9WkeU900.50usd

請求書

請求書の使用

請求書、請求書アイテム、請求書のラインアイテムについて、詳細は Stripe の請求書のドキュメントをご覧ください。

invoices テーブルには、個別の Invoice (請求書) オブジェクトに関するデータが収録されます。サブスクリプションのそれぞれから、顧客が支払うべき金額を示す請求書が反復的に生成されます。これにはサブスクリプションに必要な金額のほかに、追加で Invoice Item (請求書アイテム) が (ラインアイテムとして) 作成されている場合はそれらも自動的に含められます。

請求書は、個々の (Invoice) Line Items ((請求書) ラインアイテム) から構成されます。これらのラインアイテムは、顧客に対して請求されるサブスクリプションと、その請求書 に対して作成および適用される請求書アイテムを表します。請求書の内訳を調べてラインアイテムのそれぞれを分析するには、invoice_line_items テーブルを使用します。

このテーブルの source_id 列には、そのラインアイテムに対応するサブスクリプション (例: sub_6e4L66zjqYeSdm7) または請求書アイテム (例: ii_1M3oqBCmRiqg2Rd) の ID が記載されます。source_type 列では、そのラインアイテムがサブスクリプションと請求書アイテムのいずれを表しているかが示されます。

他の外部キーとは異なり、invoice_line_items テーブルの subscription 列は、必ず入力されるとは限りません。対応する請求書アイテムがサブスクリプションである場合は、この列がブランクになります (その ID はすでに source_id 列に表示されています)。

請求書アイテム

請求書アイテムに関するデータは、invoice_items テーブルに示されます。一般に請求書アイテムは、次の請求サイクルの開始時に次回の請求書に適用される追加金額 (または差し引き金額) の指定に使用されます。請求書アイテムは、たとえば月間使用量を超えた顧客に請求する必要がある場合や、次回の請求書で未使用分のサービスのクレジットを提供する必要がある場合に作成します。

次の例では、特定のサブスクリプションのすべての請求書と関連する支払い ID を取得します。

select id, charge_id, amount_due from invoices where subscription_id = 'sub_ALJXL9gBYtv6GJ'
id名前
in_jG31ilJhzdVTjQWch_PYgLZbIRg15RDBE1999
in_1CkzEJh8OpOHo8Ych_0uitaTLLV5yQu6r1999
in_S8tpZD08GWBbvxq1999ch_eSRdDwoX78VLPux
in_gR5pHR2G7xCb4gO1999ch_yb9REefsoKgTztZ
in_yufqj6WZ1BSNu1Z1999ch_qAjYojyyePBOaos

請求書の合計と割引

請求書の小計は、割引適用前のサブスクリプション、請求書アイテム、および請求書の比例配分 (日割り / 秒割り計算) のすべての金額を表します。請求書の合計は割引および税の適用後の金額を表します。

invoice.total = invoice.subtotal - discount + invoice.tax

割引額を請求書に表示するための列はありません。代わりに、ラインアイテムの割引額を集計することでこれを計算できます。以下のクエリは、請求書、その期間の開始日と終了日、請求書の合計割引額のリストを返します。

invoice_discounts.sql
with invoices_with_discounts as ( select invoice_id, sum(amount) as total_discount_amount from invoice_line_item_discount_amounts group by invoice_id ) select i.id as invoice_id, i.period_start, i.period_end, stringify_amount(i.currency, ilda.total_discount_amount, '.') as total_discount_amount i.currency from invoices i join invoices_with_discounts ilda on i.id = ilda.invoice_id order by i.id
invoice_idperiod_startperiod_endtotal_discount_amount通貨
in_uQSqcPUH4gwtGJR2024 年 5 月 1 日2024 年 6 月 1 日24.66usd
in_cacyApaFFUSELtk2024 年 6 月 1 日2024 年 7 月 1 日24.34usd
in_d0YvbAEglot4XdT2024-04-012024 年 5 月 1 日45.96usd

請求書の日付と期間の処理

サブスクリプションの請求書は事前に請求されるため、顧客は請求サイクルの開始時に支払いを行います。これは、ラインアイテムの period 値で表されます。たとえば、月次のサブスクリプションを利用している顧客は、毎月始めに請求されます。 cancel_at_period_end を選択すると、サブスクリプションは月末まで有効であり、その後サブスクリプションは終了します。

請求書の period_start と period_end の値は、請求書アイテムがいつ作成されたかを表しますが、必ずしも顧客に請求されるサービス期間を完全に表しているわけではありません。たとえば、毎月 1 日に請求を受ける顧客が、15 日にその月間使用量を超えた場合、 顧客に請求される追加費用の請求書アイテムを作成することができます。この請求書アイテムは翌月 1 日に作成される次回の請求書に含まれます。次回の請求書を生成するときは、period_start は前月の 15 日 (追加のラインアイテムが最初に作成された日付) になります。

従量課金

従量課金を使用すると、商品やサービスの使用量に基づいて顧客に請求できます。

請求メーター

Meter オブジェクトは、請求期間中のメーターイベントを集計する方法を指定します。メーターイベントは、顧客がシステムで実行するすべてのアクション (API リクエストなど) を表します。メーターは価格に関連付けられ、請求内容の基礎を形成します。これらのオブジェクトは、billing_meters テーブルから使用できます。

次のクエリは、有効な請求メーターをすべて返します。

meters.sql
select id, status, display_name, default_aggregation_formula from billing_meters where status = 'ACTIVE' and livemode
IDstatusdisplay_namedefault_aggregation_formula
mtr_LbInxkxA5oVYLU1ACTIVEalpaca_ai_tokenSUM
mtr_seE4HfbHuOCYyWIACTIVEalpaca_ai_image_tokenCOUNT

請求メーターイベントのサマリー

Billing Meter Event Summary オブジェクトは、指定した期間内の顧客の請求メーターイベントの集計ビューを表します。これは、その期間に顧客が発生した使用量を表します。これらのオブジェクトは、billing_meter_event_summaries テーブルから使用できます。value_grouping_window 列に示されているように、時間ごとのサマリーを使用できます。

次のクエリは、特定の顧客の請求メーターイベントの合計を返します。

billing_meter_event_summaries.sql
select billing_meters.display_name, sum(billing_meter_event_summaries.aggregated_value) AS total_usage from billing_meter_event_summaries join billing_meters on billing_meters.id = billing_meter_event_summaries.meter_id where billing_meter_event_summaries.customer_id = 'cus_EDQkYj7P2Jf3sJ1' and billing_meter_event_summaries.start_time >= timestamp '2025-02-01 08:00' and billing_meter_event_summaries.end_time <= timestamp '2025-02-01 20:00' and value_grouping_window = 'hourly' group by display_name
display_nametotal_usage
alpaca_ai_token128433
alpaca_ai_image_token71

請求メーターの無効なイベント

Billing Meter Invalid Event オブジェクトは、正常に検証されなかった請求メーターイベントを表します。これらのオブジェクトは、billing_meter_invalid_events テーブルから使用できます。関連付けられた billing_meter_invalid_events_payload テーブルには、元のイベントのイベントペイロードが含まれています。

次のクエリは、特定の顧客の無効な請求メーターイベントをすべて返します。

billing_meter_invalid_events.sql
SELECT billing_meter_invalid_events.id as event_id, billing_meter_invalid_events.error_code, billing_meter_invalid_events.error_message FROM billing_meter_invalid_events JOIN billing_meter_invalid_events_payload ON billing_meter_invalid_events_payload.event_id = billing_meter_invalid_events.id WHERE billing_meter_invalid_events_payload.key = 'stripe_customer_id' AND billing_meter_invalid_events_payload.value = 'cus_EDQkYj7P2Jf3sJ1'
event_iderror_codeerror_message
3dnBhECkJXFh6zHLIh1nhQMRziKBgSESMETER_NOT_FOUNDevent_name mtr_TYerjV2LT9xZtSm に一致するメーターが見つかりませんでした。
9bXZf7f5ClwlsSnMkDHuUMZwI0gHozGMMETER_NOT_FOUNDevent_name mtr_v4qyGdgUHOdJyoQ に一致するメーターが見つかりませんでした。

クーポン

Coupon (クーポン) オブジェクトは、サブスクリプションや顧客に適用できる、金額または率による割引を表します。

coupons.sql
select coupons.id, coupons.amount_off, coupons.percent_off from coupons where valid = false limit 5
idamount_offpercent_off
10FF10
SUMMER2525
10FREE10
15OFF15
FALL3030

割引

割引はクーポンの適用であり、Discount オブジェクトで表されます。以下のクエリは、サブスクリプションとそれに関連付けられた割引とクーポンのリストを返します。

discounts.sql
select subscriptions.id as subscription_id, t.discount_id, coupons.id as coupon_id from subscriptions cross join unnest(split(subscriptions.discounts, ',')) as t(discount_id) join discounts on discounts.id = t.discount_id join coupons on coupons.id = discounts.coupon_id limit 3
subscription_iddiscount_idcoupon_id
sub_Fjews1VxNPgh141di_QkLMGErBbFYTW3V10OFF
sub_BP9JbpzghHlgOs6di_bM7yARVxwpEQenz25OFF
sub_5ByvoA5TgdYTCDFdi_J0ZqzQhKoND1Ajl10FREE

プロモーションコード

プロモーションコード は、顧客が引き換え可能なクーポンのコードを表します。以下のクエリは、特定のクーポンに関連するプロモーションコードのリストを提供し、各コードが引き換えられた回数を表示します。

promotion_codes.sql
select promotion_codes.id as promotion_code_id, promotion_codes.code as promotion_code, promotion_codes.times_redeemed from promotion_codes limit 3
promotion_code_idcodetimes_redeemed
promo_EjDCvCuQupHsobm10OFF1
promo_xeCRyKihClrXUeZ25OFF2
promo_vgUvN4Q5ERDy07H10FREE3

サブスクリプションアイテム変更イベント

subscription_item_change_events テーブルは、月間経常収益 (MRR) に影響するサブスクリプションアイテムおよびサブスクリプションの数量の変更を追跡します。この表を使用して、個人顧客、商品、プランの MRR を計算し、ビジネスモデルのカスタム指標定義を作成し、サブスクリプションの数量の変更を追跡します。

注意

この表は、Stripe ダッシュボードの Billing の概要に表示される MRR 基準を構成するソースよりも最新のデータを提供します。このため、ここの前日の MRR のデータはより正確である可能性があり、ダッシュボードでの表示とは異なる可能性があります 。

local_event_timestamp と event_timestamp

このテーブルには、次の 2 つのタイムスタンプ列が含まれます。

  • event_timestamp: これは UTC タイムスタンプです。
  • local_event_timestamp: このタイムスタンプは、お客様のタイムゾーン (通常は、お客様の Stripe アカウントを作成した人物のタイムゾーン) です。

通貨

ここでは、サブスクリプションアイテムの売上処理通貨が、小文字の 3 文字の ISO 通貨コードとして記載されています。通貨は、Stripe がサポートしているものでなければなりません。

mrr_change

mrr_change 列は、イベントが MRR に与えるプラスまたはマイナスの影響を、サブスクリプションアイテムの売上処理通貨の補助通貨単位 (USD の場合はセントなど) で示します。

quantity_change

quantity_change 列は、顧客が登録しているサブスクリプションアイテムの数量に関わる、プラスまたはマイナスの変化を表します。

event_type

イベントタイプ定義
ACTIVE_STARTサブスクリプションアイテムが MRR への入金を開始した。
ACTIVE_ENDサブスクリプションアイテムが MRR への入金を停止した。
ACTIVE_UPGRADEサブスクリプションアイテムの MRR は増加しました。これは、サブスクリプションアイテムの価格が上がった場合、またはそのサブスクリプションアイテムの数量が増えた場合に発生する場合があります。
ACTIVE_DOWNGRADEサブスクリプションアイテムの MRR は減少しました。これは、サブスクリプションアイテムの価格が下がった場合、またはそのサブスクリプションアイテムの数量が減った場合に発生する場合があります。
ACTIVE_QUANTITY_INCREASEサブスクリプションアイテムの数量は増えましたが、MRR には影響しませんでした。段階制料金を使用していて、価格変更の前に数量が特定のしきい値を上回る必要がある場合に、これが表示されることがあります。
ACTIVE_QUANTITY_DECREASEサブスクリプションアイテムの数量は減りましたが、MRR には影響しませんでした。段階制料金を使用していて、価格変更の前に数量が特定のしきい値を下回る必要がある場合に、これが表示されることがあります。

注

一部のユーザーアクションでは複数のイベントが作成されることがあります。このため、あるアイテムで event_type が ACTIVE_END のイベントが表示され、その後すぐに、同じ subscription_id の別のアイテムで event_type が ACTIVE_START のイベントが表示されることがあります。

その他の列

その他の列 (product_id、price_id、customer_id、subscription_id、subscription_item_id) には、サブスクリプションアイテム変更イベントに関連する ID が格納されます。

クエリの例

その他の最新の例については、Sigma サイドバーのクエリテンプレートライブラリーのサブスクリプションセクションをご覧ください。

このテーブルから月間経常収益 (MRR) と有効な登録者の数を計算するには、ウィンドウ関数を使用する必要があります。さらに、異なる通貨を使用する顧客が存在する場合は、外貨為替を計算する必要があります。この計算の目的は、月次の MRR と有効なサブスクリプション登録者の変化を追跡し、新規追加、再有効化、拡大、縮小、解約を区別することです。最終結果は、USD のセントなどの補助通貨単位で表示されます。

WITH ts_grouped_sub_item_events AS ( SELECT local_event_timestamp, customer_id, currency, sum(mrr_change) AS mrr_change FROM subscription_item_change_events GROUP BY 1, 2, 3 ), ts_grouped_sub_item_events_with_mrr AS ( SELECT *, date_trunc( 'day', date(local_event_timestamp) ) AS local_event_date, -- Stripe defines an "active subscriber" as a customer with non-zero MRR. -- Therefore instead of summing up event_type to get subscription count (and its diff), -- We count the amount of revenue on each customer instead and later check its movement from / to zero sum(mrr_change) over ( PARTITION by customer_id ORDER BY local_event_timestamp ASC ) AS mrr, -- We count the # of times MRR has actually changed, and use nullif to ignore events that do not impact MRR -- Otherwise we may confuse between new vs. reactivation count(nullif(mrr_change, 0)) over ( PARTITION by customer_id ORDER BY local_event_timestamp ASC ) AS mrr_change_count FROM ts_grouped_sub_item_events ), ts_grouped_sub_item_events_with_previous_mrr AS ( SELECT *, coalesce( last_value(mrr) IGNORE nulls OVER ( PARTITION by customer_id ORDER BY local_event_timestamp ASC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ), 0 ) AS previous_mrr FROM ts_grouped_sub_item_events_with_mrr ), customer_events AS ( SELECT *, CASE WHEN mrr = 0 AND previous_mrr > 0 THEN 'ACTIVE_END' WHEN mrr > 0 AND previous_mrr = 0 AND mrr_change_count = 1 THEN 'ACTIVE_START' WHEN mrr > 0 AND previous_mrr = 0 AND mrr_change_count > 1 THEN 'REACTIVATE' WHEN mrr > previous_mrr THEN 'ACTIVE_UPGRADE' WHEN mrr < previous_mrr THEN 'ACTIVE_DOWNGRADE' ELSE NULL END AS cus_event_type FROM ts_grouped_sub_item_events_with_previous_mrr ), date_grouped_customer_events AS ( SELECT local_event_date, currency, sum(mrr_change) AS mrr_change, sum( CASE cus_event_type WHEN 'ACTIVE_START' THEN mrr_change ELSE 0 END ) AS new_mrr, sum( CASE cus_event_type WHEN 'REACTIVATE' THEN mrr_change ELSE 0 END ) AS reactivation_mrr, sum( CASE cus_event_type WHEN 'ACTIVE_UPGRADE' THEN mrr_change ELSE 0 END ) AS expansion_mrr, sum( CASE cus_event_type WHEN 'ACTIVE_DOWNGRADE' THEN mrr_change ELSE 0 END ) AS contraction_mrr, sum( CASE cus_event_type WHEN 'ACTIVE_END' THEN mrr_change ELSE 0 END ) AS churn_mrr, sum( CASE WHEN mrr = 0 AND previous_mrr > 0 THEN -1 WHEN mrr > 0 AND previous_mrr = 0 THEN 1 ELSE 0 END ) AS active_subscribers_change, sum( CASE cus_event_type WHEN 'ACTIVE_END' THEN 1 ELSE 0 END ) AS churned_subscribers, sum( CASE cus_event_type WHEN 'ACTIVE_START' THEN 1 ELSE 0 END ) AS new_subscribers, sum( CASE cus_event_type WHEN 'REACTIVATE' THEN 1 ELSE 0 END ) AS reactivated_subscribers FROM customer_events GROUP BY 1, 2 ), -- Prepare the multi dimensional table with all days + currency combinations and conversion rate metadata -- note that exchange_rates_from_usd contains one row for every date from 2010-01-07 until today -- which is why we don't need to generate a separate date series for the full table dates_with_rate_per_usd AS ( SELECT -- We use previous day's closing rates in precomputed metrics date - INTERVAL '1' DAY AS fx_date, cast( json_parse(buy_currency_exchange_rates) AS map(varchar, double) ) AS rate_per_usd FROM exchange_rates_from_usd ), currencies AS ( SELECT DISTINCT(currency) FROM subscription_item_change_events ), first_default_currency AS ( SELECT default_currency FROM accounts WHERE default_currency IS NOT NULL LIMIT 1 ), dates_x_currencies_with_conversion_rate AS ( SELECT fx_date as local_date, currency, default_currency, 1 / rate_per_usd [currency] * rate_per_usd [coalesce(default_currency, 'usd')] AS conversion_rate FROM dates_with_rate_per_usd CROSS JOIN currencies CROSS JOIN first_default_currency ORDER BY 1, 2 ), daily_metrics_by_currency AS ( SELECT dpc.local_date, dpc.currency, dpc.conversion_rate, coalesce( sum(mrr_change) over ( PARTITION by dpc.currency ORDER BY dpc.local_date ASC ), 0 ) AS mrr, coalesce( round( sum(mrr_change) over ( PARTITION by dpc.currency ORDER BY dpc.local_date ASC ) * dpc.conversion_rate ), 0 ) AS converted_mrr, coalesce(round(new_mrr * conversion_rate), 0) AS converted_new_mrr, coalesce(round(reactivation_mrr * conversion_rate), 0) AS converted_reactivation_mrr, coalesce(round(expansion_mrr * conversion_rate), 0) AS converted_expansion_mrr, coalesce(round(contraction_mrr * conversion_rate), 0) AS converted_contraction_mrr, coalesce(round(churn_mrr * conversion_rate), 0) AS converted_churn_mrr, coalesce(dgce.mrr_change, 0) AS mrr_change, coalesce(dgce.new_mrr, 0) AS new_mrr, coalesce(dgce.reactivation_mrr, 0) AS reactivation_mrr, coalesce(dgce.expansion_mrr, 0) AS expansion_mrr, coalesce(dgce.contraction_mrr, 0) AS contraction_mrr, coalesce(dgce.churn_mrr, 0) AS churn_mrr, coalesce( sum(active_subscribers_change) over ( PARTITION by dpc.currency ORDER BY dpc.local_date ASC ), 0 ) AS active_subscribers, coalesce(dgce.active_subscribers_change, 0) AS active_subscribers_change, coalesce(dgce.churned_subscribers, 0) AS churned_subscribers, coalesce(dgce.new_subscribers, 0) AS new_subscribers, coalesce(dgce.reactivated_subscribers, 0) AS reactivated_subscribers FROM dates_x_currencies_with_conversion_rate dpc LEFT JOIN date_grouped_customer_events dgce ON dpc.local_date = dgce.local_event_date AND dpc.currency = dgce.currency ), daily_metrics AS ( SELECT local_date, sum(converted_mrr) AS mrr, sum(converted_new_mrr) AS new_mrr, sum(converted_reactivation_mrr) AS reactivation_mrr, sum(converted_expansion_mrr) AS expansion_mrr, sum(converted_contraction_mrr) AS contraction_mrr, sum(converted_churn_mrr) AS churn_mrr, -- Customer can only have active subscription in a single currency at a time, as a result this does not result in over-counting subscriber changes -- This also matches the precomputed metrics logic in billing dashboard / CSV download sum(active_subscribers) AS active_subscribers, sum(churned_subscribers) AS churned_subscribers, sum(new_subscribers) AS new_subscribers, sum(reactivated_subscribers) AS reactivated_subscribers FROM daily_metrics_by_currency GROUP BY 1 ), daily_metrics_with_derived AS ( SELECT *, mrr - lag(mrr) over ( ORDER BY local_date ) - new_mrr - reactivation_mrr - expansion_mrr - contraction_mrr - churn_mrr AS fx_adjustment_mrr, lag(mrr) over ( ORDER BY local_date ) AS previous_mrr FROM daily_metrics ), -- Turn daily into monthly metrics monthly_metrics_with_derived AS ( SELECT date_trunc('month', local_date) AS local_month_start, max_by(mrr, local_date) AS ending_mrr, sum(new_mrr) AS new_mrr, sum(reactivation_mrr) AS reactivation_mrr, sum(expansion_mrr) AS expansion_mrr, sum(contraction_mrr) AS contraction_mrr, sum(churn_mrr) AS churn_mrr, sum(fx_adjustment_mrr) AS fx_adjustment_mrr, max_by(active_subscribers, local_date) AS ending_subscribers, sum(churned_subscribers) AS churned_subscribers, sum(new_subscribers) AS new_subscribers, sum(reactivated_subscribers) AS reactivated_subscribers FROM daily_metrics_with_derived GROUP BY 1 ) SELECT local_month_start, ending_mrr - fx_adjustment_mrr - churn_mrr - contraction_mrr - expansion_mrr - reactivation_mrr - new_mrr AS beginning_mrr, new_mrr, reactivation_mrr, expansion_mrr, contraction_mrr, churn_mrr, fx_adjustment_mrr, ending_mrr, -- Churned subscribers is a positive number in CSV reports instead of negative for churn / contraction mrr ending_subscribers - (-1 * churned_subscribers) - reactivated_subscribers - new_subscribers AS beginning_subscribers, new_subscribers, reactivated_subscribers, churned_subscribers, ending_subscribers FROM monthly_metrics_with_derived ORDER BY 1 DESC
local_month_startbeginning_mrrnew_mrrreactivation_mrrexpansion_mrrcontraction_mrrchurn_mrrfx_adjustment_mrrending_mrrbeginning_subscribersnew_subscribersreactivated_subscriberschurned_subscribersending_subscribers
2024 年 5 月 1 日100072149104000040000000100216149930012
2024-04-011000651497180000-1800100072149730012
2024 年 3 月 1 日100066099124000-1074010006514972027
2024 年 2 月 1 日1000660991000000-1000010006609971017
2024 年 1 月 1 日1000381022921601998-175-3042010006609954027
2023 年 12 月 1 日10003810200000010003810250005
2023 年 11 月 1 日10003710210000000010003810241005
2023 年 10 月 1 日10003710200000010003710240004
2023 年 9 月 1 日10003710200000010003710240004
2023 年 8 月 1 日1000339020050000-1800010003710250014
2023 年 7 月 1 日1000370650000-3159-410003390260015
2023/06/0110003640235 カ国336900-2742110003706561346
2023 年 5 月 1 日1000348982748030437-83-31598010003640273046
2023 年 4 月 1 日100034065933000-100010003489862017
2023 年 3 月 1 日100002715313500000010003406542006
2023 年 2 月 1 日1000060486086060880-15507010000271552034
2023 年 1 月 1 日1000060483043000-3043010000604851015
2022 年 12 月 1 日1001521342591001363600-30000-1505574-22100006048960105
2022 年 11 月 1 日100178232486883333621878-10600-68939701001521347161159
2022 年 10 月 1 日10003619313633312000020600-10000-124894010017823274267
このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc