

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# の販売者レポート、データフィード、ダッシュボード AWS Marketplace
<a name="reports-and-data-feed"></a>

 AWS Marketplace 販売者は、次のツールを使用して製品の販売に関する情報を収集および分析できます。
+ [データフィード](data-feeds.md)。レポートに示された取引の顧客情報を識別するための追加の顧客情報を提供します。
+ [Amazon Quick](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) [を利用したダッシュボード](dashboards.md)には、財務データへのアクセスと分析に役立つグラフ、グラフ、インサイトがあります。

AWS Marketplace は、以下に従いながら、レポート、データフィード、ダッシュボードにできるだけ多くのデータを提供します。
+ 顧客データの保護に関する Amazon の標準と規定。
+ 購入者が AWS Marketplaceで製品を購入する際に承諾する利用規約。販売者は、購入者のデータを安全に管理し、購入者からリクエストがあり次第、データを削除することが契約上義務付けられています。

**注記**  
レポートの通知 E メールをキャンセルするには、[AWS Marketplace Seller Operations](https://aws.amazon.com/marketplace/management/contact-us/) チームまでお問い合わせください。

のレポート、データフィード、ダッシュボードの詳細については AWS Marketplace、以下のトピックを参照してください。

**Topics**
+ [AWS Marketplace の販売者配信データフィード](data-feed-service.md)
+ [補足レポート](supplementary-reports.md)
+ [販売者ダッシュボード](dashboards.md)

# AWS Marketplace の販売者配信データフィード
<a name="data-feed-service"></a>

AWS Marketplace は、構造化された最新の製品および顧客情報を AWS Marketplace システムから販売者の Amazon S3 バケットに送信し、販売者が所有するビジネスインテリジェンスツール間の ETL (抽出、変換、ロード) を行うためのメカニズムとしてデータフィードを提供します。データフィードは、カンマ区切り値 (CSV) ファイルを収集し、これを指定先の暗号化された Amazon S3 バケットに配信します。データフィードは 1 日以内に生成され、前日の 24 時間のデータが含まれます。このセクションでは、データフィードの概要を示し、データフィードにアクセスして使用する方法について説明します。以降のセクションでは、各データフィードについて説明します。

取引データは双時構造で配信および追加されるため、販売者は両方のタイムスタンプ付きの 2 つのタイムラインに沿ってデータを保存し、クエリを実行できます。
+ 有効時間: 現実世界で事実が発生した日時 (「知ったこと」)
+ システム時間: その事実がデータベースに記録された日時 (「知ったとき」)

データフィードは、UTC 午前 0 時に毎日配信され、前日からの 24 時間分のデータを含む更新が実行されます。更新内容は、購読している顧客、請求を受ける顧客、または支払いを行う AWS によって定義できます。

**Topics**
+ [AWS Marketplace データフィードのストレージと構造](data-feed-details.md)
+ [データフィードへのアクセス](data-feed-accessing.md)
+ [データフィードを使用したデータ収集と分析](data-feed-using.md)
+ [データフィードテーブルの概要](data-feed-joining.md)
+ [データフィードクエリの例](data-feed-full-examples.md)
+ [データフィード](data-feeds.md)

# AWS Marketplace データフィードのストレージと構造
<a name="data-feed-details"></a>

AWS Marketplace は、構造化された最新の製品および顧客情報を AWS Marketplace システムから販売者の Amazon S3 バケットに送信し、販売者が所有するビジネスインテリジェンスツール間の ETL (抽出、変換、ロード) を行うためのメカニズムとしてデータフィードを提供します。このトピックでは、データフィードの構造とストレージについて詳述します。

データフィードは、カンマ区切り値 (CSV) ファイルを収集し、これを指定先の暗号化された Amazon S3 バケットに配信します。CSV ファイルの特性は次のとおりです。
+ [4180 標準](https://tools.ietf.org/html/rfc4180)に準拠しています。
+ 文字エンコーディングは UTF-8 (BOM なし) です。
+ カンマは、値間の区切り文字として使用されます。
+ フィールドは二重引用符でエスケープ 
+ `\n` は改行文字です。
+ 日付は UTC タイムゾーンで報告され、日時形式は ISO 8601 に従い、精度は 1 秒以内です。
+ すべての `*_period_start_date` 値および `*_period_end_date` 値は包括的です。つまり、`23:59:59` は任意の日の最後のタイムスタンプです。
+ すべての金銭情報フィールドの先頭に通貨フィールドが付きます。
+ 金銭情報フィールドでは、小数点の区切り文字としてピリオド (`.`) を使用し、3 桁の区切り文字としてカンマ (,) を使用しません。

データフィードは次のように生成されて保存されます。
+ データフィードは 1 日以内に生成され、前日の 24 時間のデータが含まれます。
+ Amazon S3 バケットの場合、データフィードは次の形式を使用して月別に整理されます。

  `bucket-name/data-feed-name_version/year=YYYY/month=MM/data.csv`
+ 毎日のデータフィードが生成されると、当月の既存の CSV ファイルに追加されます。新しい月が始まると、データフィードごとに新しい CSV ファイルが生成されます。
+ データフィードの情報は、2010 年 1 月 1 日から 2020 年 4 月 30 日 (当日を含む) にバックフィルされ、`year=2010/month=01` サブフォルダの [CSV ファイル](#data-feed-details)で確認できます。

  特定のデータフィードの当月のファイルに列ヘッダーのみが含まれ、データが含まれていない場合があります。これは、当月のフィードに新しいエントリがなかったことを意味します。製品フィードなど、更新頻度が低いデータフィードで発生する場合があります。このような場合、データはバックフィルされたフォルダで利用できます。
+ Amazon S3 では、[Amazon S3 ライフサイクルポリシー](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-lifecycle.html)を作成して、バケットにファイルを保持する期間を管理できます。
+ 暗号化された Amazon S3 バケットにデータが配信されたときに通知するように Amazon SNS を設定できます。通知を設定する方法の詳細については、「*Amazon Simple Notification Service デベロッパーガイド*」の「[Amazon SNS の開始方法](https://docs.aws.amazon.com/sns/latest/dg/sns-getting-started.html)」を参照してください。

## データの履歴化
<a name="data-feed-historization"></a>

各データフィードには、データの履歴を示す列があります。`valid_to` を除き、これらの列はすべてのデータフィードに共通です。これらは共通の履歴スキーマとして含まれており、データのクエリに役立ちます。


| 列名  | 説明  | 
| --- | --- | 
| valid\$1from | 主キーの値が他のフィールドの値に関連して有効である最初の日付。 | 
| valid\$1to | この列は[住所](data-feed-address.md)データフィードにのみ表示され、常に空白です。 | 
| insert\$1date | レコードがデータフィードに挿入された日付。 | 
| update\$1date | レコードが最後に更新された日付。 | 
| delete\$1date | この列は常に空白です。 | 

これらの列の例を次に示します。


|  valid\$1from  |  valid\$1to  |  insert\$1date  |  update\$1date  |  delete\$1date  | 
| --- | --- | --- | --- | --- | 
|  2018-12-12T02:00:00Z  |   |  2018-12-12T02:00:00Z  |  2018-12-12T02:00:00Z  |   | 
|  2019-03-29T03:00:00Z  |   |  2019-03-29T03:00:00Z  |  2019-03-29T03:00:00Z  |   | 
|  2019-03-29T03:00:00Z  |   |  2019-03-29T03:00:00Z  |  2019-04-28T03:00:00Z  |   | 

`valid_from` と `update_date` フィールドが一緒になって双時データモデルを形成します。**`valid_from` フィールドは、その名のとおり、アイテムがいつ有効になるかがわかります。項目が編集された場合、フィードにはそれぞれ、`update_date` が異なり、`valid_from` の日付が同じレコードが複数含まれている可能性があります。例えば、ある項目の現在の値を調べるには、最新の `valid_from` の日付があるレコードのリストから最新の `update_date` のレコードを検索します。

上の例では、レコードは元々 2018 年 12 月 12 日に作成されたものです。その後、2019 年 3 月 29 日に変更されました (レコード内のアドレスが変更された場合など)。その後、2019 年 4 月 28 日に、アドレスの変更が修正されました (`valid_from` は変更されず、`update_date` は変更されました)。アドレスを修正すると (まれなイベント)、レコードが元の `valid_from` の日付から遡って変更されるため、そのフィールドは変更されませんでした。最新の `valid_from` レコードを検索するクエリでは 2 つのレコードが返され、最新の `update_date` から現在の実際のレコードが得られます。

# データフィードへのアクセス
<a name="data-feed-accessing"></a>

AWS Marketplace では、AWS Marketplace システムから Amazon S3 バケットに構造化された最新の製品および顧客情報を送信し、販売者所有のビジネスインテリジェンスツール間で、ETL (Extract/Transform/Load) を行う仕組みとして、データフィードを使用できます。暗号化された Amazon S3 バケットでデータフィードを受信するように環境を設定する必要があります。このトピックでは、データフィードにアクセスしてサブスクライブを解除する方法について説明します。

**Topics**
+ [データフィードにアクセスする](#data-feed-accessing-procedure)
+ [データフィードポリシー](#data-feed-policies)
+ [データフィードからサブスクリプションを解除する](#data-feed-unsubscribing)

## データフィードにアクセスする
<a name="data-feed-accessing-procedure"></a>

1. SQL と ETL (Extract/Transform/Load) の経験があるビジネスインテリジェンスまたはデータエンジニアを割り当てます。また、API の設定経験も必要です。

1. Amazon Simple Storage Service バケットとデータフィードのサブスクリプションを設定します。Marketplace 製品リストに関連付けられている AWS 販売者アカウント ID を使用します。これを行うには、[この YouTube 動画を視聴](https://www.youtube.com/watch?v=heCsZdOT-hw)するか、次の手順を実行します。

   ビデオと手順では、設定を簡素化する[CloudFormation テンプレート](https://s3.amazonaws.com/aws-marketplace-reports-resources/DataFeedsResources.yaml)の使用方法が説明されています。

   1. ウェブブラウザを開いて [AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインし、「[顧客データストレージの設定](https://aws.amazon.com/marketplace/management/reports/data-feed-configuration)」に進みます。

   1. [**Create resources with CloudFormation (CloudFormatiion テンプレートを使用してリソースを作成する)**] を選択して、CloudFormation コンソールの別のウィンドウでテンプレートを開きます。

   1. テンプレートで以下を指定し、[**Next (次へ)**] を選択します。
      + スタック名 - データフィードへのアクセスを有効にするために作成するリソースのコレクション。
      + Amazon S3 バケット名 - データフィードを保存する先のバケット。
      + (オプション) Amazon SNS トピック名 - Amazon Simple Storage Service バケットに配信されたときに、通知を受信するためのトピック。

   1. [**Review (確認)**] ページで入力内容を確認し、[**Create stack (スタックの作成)**] を選択します。これにより、CloudFormation のステータスと詳細が記載された新しいページが開きます。

   1. **[リソース]** タブから、次のリソースの Amazon リソースネーム (ARN) を CloudFormation ページから AWS Marketplace の [[顧客データストレージの設定]](https://aws.amazon.com/marketplace/management/reports/data-feed-configuration) ページのフィールド内にコピーします。
      + データフィードを保存する先の Amazon S3 バケット
      + Amazon S3 バケットを暗号化するための AWS KMS キー
      + (オプション) AWS が新しいデータを Amazon S3 バケットに配信したときに、通知を受信するための Amazon SNS トピック。

   1. [**Set up customer data storage (顧客データストレージの設定)**] ページで、[**Submit (送信)**] を選択します。

   1. (オプション) CloudFormation テンプレートによって作成されたポリシーを編集します。詳細については、「[データフィードポリシー](#data-feed-policies)」を参照してください。

      これで、データフィードにサブスクライブしました。次回にデータフィードが生成されると、データにアクセスできます。

1. ETL (Extract/Transform/Load) オペレーションを使用すると、データフィードをデータウェアハウスまたはリレーショナルデータベースに接続します。
**注記**  
データツールにはさまざまな機能があります。ツールの機能に合わせて統合を設定するには、ビジネスインテリジェンスエンジニアまたはデータエンジニアを関与させる必要があります。

1. SQL クエリを実行または作成するには、データツールでプライマリキーと外部キーを適用するようにデータフィードを設定します。各データフィードは一意のテーブルを表し、エンティティ関係を使用してデータスキーマ内のすべてのデータフィードを設定する必要があります。テーブルとエンティティの関係の詳細については、このガイドの「[データフィードテーブルの概要](data-feed-joining.md)」を参照してください。

1. Amazon Simple Notification Service をセットアップして、データウェアハウスまたはリレーショナルデータベースを自動的に更新します。各一意のフィードからのデータが Amazon S3 バケットに配信されたときにアラートを送信するように Amazon SNS 通知を設定できます。これらの通知を使用すると、販売者データツールがこの機能をサポートし、データフィードを介して新しいデータを受信する際に、販売者データウェアハウスを自動更新できます。詳細については、「*Amazon Simple Notification Service デベロッパーガイド*」の「[Amazon SNS の開始方法](https://docs.aws.amazon.com/sns/latest/dg/sns-getting-started.html)」を参照してください。

   通知の例

   ```
   {
           "mainExecutionId": "1bc08b11-ab4b-47e1-866a-9c8f38423a98",
           "executionId": "52e862a9-42d2-41e0-8010-810af84d39b1",
           "subscriptionId": "27ae3961-b13a-44bc-a1a7-365b2dc181fd",
           "processedFiles": [],
           "executionStatus": "SKIPPED",
           "errors": [],
           "feedType": "[data feed name]"
           }
   ```

   通知には次の `executionStatus` ステータスがあります。
   + `SKIPPED` – 販売者に対するその日の新しいデータはありません。
   + `COMPLETED` – フィードに新しいデータを提供しました。
   + `FAILED` – フィード配信に問題があります。

1. SQL クエリを実行してセットアップを検証します。この[ガイドの サンプルクエリ](https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed-full-examples.html)、または GitHub のクエリは、[https://github.com/aws-samples/aws-marketplace-api-samples/tree/main/seller-data-feeds/queries](https://github.com/aws-samples/aws-marketplace-api-samples/tree/main/seller-data-feeds/queries) で使用できます。
**注記**  
このガイドのサンプルクエリは、AWS Athena 用に記述されています。ツールで使用するクエリは変更する必要がある場合があります。

1. ビジネスユーザーがデータを使用する場所を決定します。例えば、以下のことが可能です。
   + データウェアハウスまたは SQL データベースから .csv データをエクスポートします。
   + PowerBI や Tableau などの視覚化ツールにデータを接続します。
   + Salesforce、Infor、Netsuite などの CRM、ERP、財務ツールにデータをマッピングします。

CloudFormation テンプレートの詳細については、「*AWS CloudFormation ユーザーガイド*」にある「[CloudFormation テンプレートの使用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)」を参照してください。

## データフィードポリシー
<a name="data-feed-policies"></a>

Amazon S3 バケットが CloudFormation テンプレートによって作成されると、そのバケット、AWS KMS キー、および Amazon SNS トピックにアタッチされたアクセスに関するポリシーが作成されます。このポリシーにより、AWS Marketplace レポートサービスはデータフィード情報をバケットと SNS トピックに書き込むことができます。各ポリシーには次のようなセクションがあります (この例は Amazon S3 バケットのものです)。

```
        {
            "Sid": "AwsMarketplaceDataFeedsAccess",
            "Effect": "Allow",
            "Principal": {
                "Service": "reports.marketplace.amazonaws.com"
            },
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:PutObject",
                "s3:GetEncryptionConfiguration",
                "s3:GetBucketAcl",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket",
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        },
```

このポリシーでは、AWS Marketplace は `reports.marketplace.amazonaws.com` サービスプリンシパルを使用して、データを Amazon S3 バケットにプッシュします。CloudFormation テンプレートでは、*amzn-s3-demo-bucket* が指定されています。

AWS Marketplace レポートサービスが Amazon S3、AWS KMS、または Amazon SNS を呼び出すと、バケットに書き込む予定のデータの ARN が提供されます。バケットに書き込まれるデータが、ユーザーに代わって書き込まれるデータだけになるようにするには、ポリシーの条件に `aws:SourceArn` を指定します。次の例では、*account-id* を自分の AWS アカウント の ID に置き換える必要があります。

```
        {
           "Sid": "AwsMarketplaceDataFeedsAccess",
           "Effect": "Allow",
           "Principal": {
                "Service": "reports.marketplace.amazonaws.com"
            },
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:PutObject",
                "s3:GetEncryptionConfiguration",
                "s3:GetBucketAcl",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket",
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ,
            "Condition": {
                "StringEquals": {
                        "aws:SourceAccount": "account-id",
                        "aws:SourceArn": ["arn:aws:marketplace::account-id:AWSMarketplace/SellerDataSubscription/DataFeeds_V1",
                        "arn:aws:marketplace::account-id:AWSMarketplace/SellerDataSubscription/Example-Report"]
                        }
                }
        },
```

## データフィードからサブスクリプションを解除する
<a name="data-feed-unsubscribing"></a>

ウェブブラウザを開き、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/)にサインインします。次に、[[お問い合わせ]](https://aws.amazon.com/marketplace/management/contact-us/) ページに移動して、AWS Marketplace Seller Operations チームに受信解除のリクエストを送信します。受信解除のリクエストの処理が完了するのに、最大で 10 営業日かかる場合があります。

# データフィードを使用したデータ収集と分析
<a name="data-feed-using"></a>

AWS Marketplace は、構造化されたup-to-date製品および顧客情報を AWS Marketplace システムから販売者 Amazon S3 バケットに送信し、販売者所有のビジネスインテリジェンスツール間で ETL (抽出、変換、ロード) するためのメカニズムとしてデータフィードを提供します。Amazon S3 バケットのデータが使用可能な場合、次の方法でデータフィードを使用できます。
+ [データフィードへのアクセス](data-feed-accessing.md) で作成した Amazon S3 バケットから .CSV ファイルをダウンロードして、スプレッドシートでデータを表示できるようにします。
+ ETL (抽出、変換、ロード)、SQLクエリ、ビジネス分析ツールを使用して、データを収集して分析します。

   AWS サービスを使用してデータを収集および分析したり、.CSV ベースのデータセットの分析を実行できるサードパーティーのツールを使用したりできます。

データを収集および分析するためのデータフィードの詳細については、次の例を参照してください。

## 例: AWS サービスを使用してデータを収集および分析する
<a name="data-feed-using-example"></a>

次の手順では、データフィードの送信先を Amazon S3 バケットとするように環境を設定済みであり、バケットにデータフィードが含まれていることを前提としています。

**データフィードからデータを収集して分析するには**

1. [AWS Glue コンソール](https://console.aws.amazon.com/glue)から、データフィードを格納する Amazon S3 バケットに接続する[クローラーを作成](https://docs.aws.amazon.com/glue/latest/dg/add-crawler.html)し、必要なデータを抽出して、 AWS Glue Data Catalogにメタデータテーブルを作成します。

   詳細については AWS Glue、「 [https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html)」を参照してください。

1. [Athena コンソール](https://console.aws.amazon.com/athena)から、[AWS Glue Data Catalogのデータに対して SQL クエリを実行](https://docs.aws.amazon.com/athena/latest/ug/querying-athena-tables.html)します。

   Athena の詳細については、「[https://docs.aws.amazon.com/athena/latest/ug/what-is.html](https://docs.aws.amazon.com/athena/latest/ug/what-is.html)」を参照してください。

1. [クイックコンソール](http://quicksight.aws.amazon.com)から分析[を作成し](https://docs.aws.amazon.com/quick/latest/userguide/creating-an-analysis.html)、データの[ビジュアルを作成します](https://docs.aws.amazon.com/quick/latest/userguide/creating-a-visual.html)。

   Quick の詳細については、[https://docs.aws.amazon.com/quick/latest/userguide/welcome.html](https://docs.aws.amazon.com/quick/latest/userguide/welcome.html)」を参照してください。

 AWS サービスを使用してデータフィード内のデータを収集および分析する方法の詳細な例については、 AWS Marketplace ブログの[「Using Seller Data Feed Delivery Service, Amazon Athena, and Quick to create seller reports](https://aws.amazon.com/blogs/awsmarketplace/using-seller-data-feed-delivery-service-amazon-athena-and-amazon-quicksight-to-create-seller-reports/)」を参照してください。

# データフィードテーブルの概要
<a name="data-feed-joining"></a>

AWS Marketplace 提供のデータフィードは、複数のテーブルを結合することによりクエリのコンテキストを広げることができます。

AWS Marketplace 提供のデータフィードには、次の一般的なドメイン、つまり関心のあるカテゴリがあります。
+ **カタログ** - アカウント内の製品やオファーに関する情報が含まれます。
+ **アカウント** - AWS Marketplace で製品を提供または購入するアカウント (自分のアカウント、またはチャネルパートナーや購入者などの協力関係者のアカウント) に関する情報が含まれます。
+ **収益** - 請求、支払い、税金に関する情報が含まれます。
+ **調達** – 登録販売者として作成した製品オファーの契約に関する情報が含まれます。

この図は、カタログ、アカウント、収益の各ドメインの中のテーブルを示しています。

![\[Entity relationship diagram showing how data feeds relate to each other.\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-overview.png) 

## カタログ関連テーブル
<a name="data-feed-catalog-domain"></a>

次の図は、カタログドメイン内のテーブルとテーブル内のフィールド間の関係を示しています。

![\[カタログドメイン内の製品、オファー_製品、オファー、オファー_ターゲット、レガシー_ID_マッピングの各テーブル間の関係。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-catalog-details.png)


`Product`、`Offer_Product`、`Offer`、`Offer_Target`、`Legacy_id_mapping`\$1テーブルはカタログドメインにあります。

`Offer_Target` テーブルにはターゲットの `account_id` の値フィールドが含まれますが、`target_type` 値が `account` である場合に限ります。

`Legacy_id_mapping` テーブルは現在のデータには使用されません。

**注記**  
テーブル内の各フィールドの説明や作成できる結合など、これらのテーブルの詳細については、以下のトピックを参照してください。  
[製品データフィード](data-feed-product.md)
[オファー製品データフィード](data-feed-offer-product.md)
[オファーデータフィード](data-feed-offer.md)
[オファーターゲットデータフィード](data-feed-offer-target.md)
[レガシーマッピングデータフィード](data-feed-legacy-mapping.md)

## 勘定科目関連テーブル
<a name="data-feed-accounts-domain"></a>

次の図は、アカウントドメイン内のとのテーブル間の関係、`Account` および `Address` テーブル内のフィールドを示しています。

![\[アカウントドメインのアカウントテーブルとアドレステーブル、および各テーブル内のフィールド間の関係。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-accounts-details.png)


**注記**  
テーブル内の各フィールド説明や作成できる結合を含むこれらのテーブルの詳細については、次のトピックを参照してください。  
[アカウントデータフィード](data-feed-account.md)
[住所データフィード](data-feed-address.md)

## 収益関連テーブル
<a name="data-feed-revenue-domain"></a>

次の図は、収益ドメイン内のとのテーブル間の関係、`Billing_Event` および `Tax_Item` テーブル内のフィールドを示しています。`Billing_Event` テーブルには、支払いと請求イベントに関する情報が含まれています。

![\[収益ドメインの Billing_Event テーブルと Tax_Item テーブル、および各テーブル内のフィールド間の関係。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-revenue-details.png)


**注記**  
テーブル内の各フィールド説明や作成できる結合を含むこれらのテーブルの詳細については、次のトピックを参照してください。  
[請求イベントデータフィード](data-feed-billing-event.md)
[税品目データフィード](data-feed-tax-item.md)

### 調達関連テーブル
<a name="procurement-tables"></a>

次の図は、調達ドメインの契約テーブル内のフィールドを示しています。

**注記**  
テーブル内の各フィールドの説明や作成できる結合など、これらのテーブルの詳細については、このガイドの「[契約データフィード](data-feed-agreements.md)」を参照してください。

以下のセクションでは、各ドメインの*エンティティ関係* (ER) 図を示します。各 ER 図には、テーブルと各テーブル内のフィールド、およびテーブルの結合に使用できるフィールドが示されています。

**注記**  
このセクションの ER 図には、すべてのデータフィードに共通するフィールドは含まれていません。共通フィールドの詳細については、「[AWS Marketplace データフィードのストレージと構造](data-feed-details.md)」を参照してください。

次の表では、ER 図に示されている記号について説明します。


| 記号 | 説明 | 
| --- | --- | 
|  ![\[「PK」という文字を記号にしたイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-primary-key.png)  |  **プライマリキー** - テーブルのプライマリキー。`valid_from` および `update_date` フィールドと一緒に使用すると、一意になります。これらのフィールドを一緒に使用する方法の詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。複数のフィールドがプライマリキーとしてマークされている場合、それらのフィールドが一緒になってプライマリキーになります。  | 
|  ![\[「FK」という文字を記号にしたイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-foreign-key.png)  |   **外部キー** - 別のテーブルのプライマリキーを表すフィールド。テーブル内で必ずしも一意である必要はありません。   現在のテーブルのレコードに対応するレコードが外部テーブルにない場合、外部キーが空白になることがあります。   | 
|  ![\[「AK」という文字を記号にしたイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-alternate-key.png)  |   **代替キー** - テーブル内のキーとして使用できるキー。プライマリキーと同じ一意性のルールに従います。  | 
|  ![\[一方の端に十字があり、もう一方の端に円と分岐がある線のイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-one-to-many.png)  |   **コネクタ** - フィールド間の線は接続を表し、テーブルを結合するために使用できる 2 つのフィールドです。線の端は接続の種類を表します。この例は 1 対多の接続を表しています。  | 

**コネクタタイプ**

次のテーブルは、各コネクタが持つことができる端部のタイプを示しています。


| コネクタタイプ | 説明 | 
| --- | --- | 
|  ![\[片方の端に十字の付いた線のイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-one-to-n.png)  |   **1 対 n** - この端があるコネクタは、結合のこちら側に値が 1 つだけある結合を表します。  | 
|  ![\[片方の端に十字と円の付いた線のイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-zero-or-one-to-n.png)  |   **0 または 1 対 n** - この端のコネクタは、結合のこちら側に値が 0 または 1 つある結合を表します。  | 
|  ![\[片方の端に円と分岐がある線のイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-optional-many-to-n.png)  |   **0 以上対 n** - この端のコネクタは、結合のこちら側に 0 個、1 個、または多数の値を持つ結合を表します。  | 
|  ![\[片方の端に十字と分岐がある線のイメージ。\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/images/datafeeds-one-or-more-to-n.png)  |   **1 以上対 n** - この端があるコネクタは、結合のこちら側に 1 つまたは複数の値がある結合を表します。  | 

# データフィードクエリの例
<a name="data-feed-full-examples"></a>

このセクションでは、 が提供するデータフィードを使用した複雑なクエリの例を示します AWS Marketplace。これらの例は、 AWS Marketplace 管理ポータルから得られる [販売者ダッシュボード](dashboards.md) と似ています。これらのクエリをカスタマイズして、必要な他のレポートを作成できます。

**Topics**
+ [契約と更新](#data-feed-example-agreements)
+ [請求済み収益](#data-feed-example-billed-revenue)
+ [未払い請求書または支払い済み請求書](#data-feed-example-collections)
+ [課税請求書](#data-feed-example-tax)
+ [製品別の支払い](#data-feed-example-disbursement-by-product)
+ [販売補償レポート](#data-feed-example-sales-compensation)

## 契約と更新
<a name="data-feed-example-agreements"></a>

契約および更新データを検索するには、次の例のような一連のクエリを実行できます。クエリは相互に構築され、**[契約と更新]** ダッシュボード、粒度の細かいデータセクションを作成します。図のように例を使用するか、データやユースケースに合わせてカスタマイズできます。

クエリのコメントは、クエリの動作と変更方法について説明しています。

```
      Query currently under development.
```

## 請求済み収益
<a name="data-feed-example-billed-revenue"></a>

請求書データを検索するには、次の例のような一連のクエリを実行できます。クエリは相互に構築され、**請求収益**レポートを作成します。図のように例を使用するか、データやユースケースに合わせてカスタマイズできます。

クエリのコメントは、クエリの動作と変更方法について説明しています。

```
-- Billed revenue report

-- General note: When executing this query we are assuming that the data ingested in the database uses 
-- two time axes (the valid_from column and the update_date column).
-- See documentation for more details: https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed.html#data-feed-details

-- An account_id has several valid_from dates (each representing a separate revision of the data)
-- but because of bi-temporality, an account_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
with accounts_with_uni_temporal_data as (
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    from_iso8601_timestamp(valid_from) as valid_from,
    tax_registration_number
  from
    (
      select
        account_id,
        aws_account_id,
        encrypted_account_id,
        mailing_address_id,
        tax_address_id,
        tax_legal_name,
        valid_from,
        delete_date,
        tax_registration_number,
        row_number() over (partition by account_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
      from
        accountfeed_v1
    )
    where
      -- keep latest ...
      row_num = 1
      -- ... and remove the soft-deleted one.
      and (delete_date is null or delete_date = '')
  ),

accounts_with_history as (
  with accounts_with_history_with_extended_valid_from as (
    select
      account_id,
      -- sometimes, this columns gets imported as a "bigint" and loses heading 0s -> casting to a char and re-adding heading 0s (if need be)
      substring('000000000000'||cast(aws_account_id as varchar),-12) as aws_account_id,
      encrypted_account_id,
      mailing_address_id,
      tax_address_id,
      tax_legal_name,
      -- The start time of account valid_from is extended to '1970-01-01 00:00:00', because:
      -- ... in tax report transformations, some tax line items with invoice_date cannot
      -- ... fall into the default valid time range of the associated account
      case
        when lag(valid_from) over (partition by account_id order by valid_from asc) is null
          then cast('1970-01-01 00:00:00' as timestamp)
        else valid_from
      end as valid_from
    from accounts_with_uni_temporal_data
    )
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    valid_from,
    coalesce(
      lead(valid_from) over (partition by account_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to
  from
    accounts_with_history_with_extended_valid_from
),

-- An address_id has several valid_from dates (each representing a separate revision of the data)
-- but because of bi-temporality, an account_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
address_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    address_id,
    company_name,
    email_domain,
    country_code,
    state_or_region,
    city,
    postal_code,
    row_num
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      address_id,
      company_name,
      email_domain,
      country_code,
      state_or_region,
      city,
      postal_code,
      row_number() over (partition by address_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      addressfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- We are only interested in the most recent tuple (BTW: a given address is not supposed to change over time but when bugs ;-) so this query mainly does nothing)
address_with_latest_revision as (
  select
    valid_from,
    address_id,
    company_name,
    email_domain,
    country_code,
    state_or_region,
    city,
    postal_code,
    row_num_latest_revision
  from
  (
    select
      valid_from,
      address_id,
      company_name,
      email_domain,
      country_code,
      state_or_region,
      city,
      postal_code,
      row_number() over (partition by address_id order by valid_from desc) as row_num_latest_revision
    from
      address_with_uni_temporal_data
  )
  where
    row_num_latest_revision = 1
),

accounts_with_history_with_company_name as (
  select
    awh.account_id,
    awh.aws_account_id,
    awh.encrypted_account_id,
    awh.mailing_address_id,
    awh.tax_address_id,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when address.company_name = '' then null else address.company_name end,
      awh.tax_legal_name) as mailing_company_name,
    address.email_domain,
    awh.valid_from,
    -- For BYOL, the agreement might be accepted (using some external non-AWS system or manual process) days before
    -- that BYOL agreement is entered into AWS Marketplace by the buyer. Therefore, the buyer is permitted to manually
    -- enter a backdated acceptance date, which might predate the point in time when the account was created.
    -- To work around this, we need to adjust the valid_from of the account to be
    -- earlier than the earliest possible backdated BYOL agreement acceptance date.
    case
      when lag(awh.valid_from) over (partition by aws_account_id order by awh.valid_from asc) is null
      then date_add('Day', -212, awh.valid_from)
      -- 212 is the longest delay between acceptance_date of the agreement and the account start_Date
      else awh.valid_from
    end as valid_from_adjusted,
    awh.valid_to
  from accounts_with_history as awh
  left join address_with_latest_revision as address on
    awh.mailing_address_id = address.address_id and awh.mailing_address_id is not null
),

-- An agreement_id has several valid_from dates (each representing an agreement revision)
-- but because of bi-temporality, an agreement_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
agreements_with_uni_temporal_data as (
  select
    agreement_id,
    origin_offer_id,
    proposer_account_id,
    acceptor_account_id,
    agreement_revision,
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(start_date) as start_date,
    from_iso8601_timestamp(end_date) as end_date,
    from_iso8601_timestamp(acceptance_date) as acceptance_date,
    agreement_type,
    previous_agreement_id,
    agreement_intent
  from
  (
    select
      --empty value in Athena shows as '', change all '' value to null
      case when agreement_id = '' then null else agreement_id end as agreement_id,
      origin_offer_id,
      proposer_account_id,
      acceptor_account_id,
      agreement_revision,
      valid_from,
      delete_date,
      start_date,
      end_date,
      acceptance_date,
      agreement_type,
      previous_agreement_id,
      agreement_intent,
      row_number() over (partition by agreement_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      -- TODO change to agreementfeed_v1 when Agreement Feed is GA'ed
      agreementfeed
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

agreements_with_history as (
  with agreements_with_window_functions as (
    select
      agreement_id,
      origin_offer_id as offer_id,
      proposer_account_id,
      acceptor_account_id,
      agreement_revision,
      start_date,
      end_date,
      acceptance_date,
      -- The start time of agreement valid_from is extended to '1970-01-01 00:00:00', because:
      -- ... in usage report transformations, some usage line items with usage_date cannot
      -- ... fall into the default valid time range of the associated agreement
      case
          when lag(valid_from) over (PARTITION BY agreement_id order by valid_from asc) is null
          then timestamp '1970-01-01 00:00:00'
          else valid_from
      end as valid_from,
      coalesce(
          lead(valid_from) over (partition by agreement_id order by valid_from asc),
          timestamp '2999-01-01 00:00:00'
      ) as valid_to,
      rank() over (partition by agreement_id order by valid_from asc) version,
      agreement_type,
      previous_agreement_id,
      agreement_intent
    from
      agreements_with_uni_temporal_data
  )
  select
    agreement_id,
    offer_id,
    proposer_account_id,
    acceptor_account_id,
    agreement_revision,
    start_date,
    end_date,
    acceptance_date,
    valid_from,
    case
        when version=1 and valid_from<timestamp '2023-03-03 06:16:08.743' then timestamp '1970-01-01'
        -- The following 60 minute adjustment is to handle special case where When Renewal happens for a contract
        when version=1 then date_add('minute',-60,valid_from)
        else valid_from
    end as valid_from_adjusted,
    valid_to,
    agreement_type,
    previous_agreement_id,
    agreement_intent
  from
    agreements_with_window_functions
),

-- An offer_id has several valid_from dates (each representing an offer revision)
-- but because of bi-temporality, an offer_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
offers_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    offer_id,
    offer_revision,
    name,
    expiration_date,
    opportunity_id,
    opportunity_name,
    opportunity_description,
    seller_account_id
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      offer_id,
      offer_revision,
      name,
      expiration_date,
      opportunity_id,
      opportunity_name,
      opportunity_description,
      seller_account_id,
      row_number() over (partition by offer_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      offerfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- Here, we build the validity time range (adding valid_to on top of valid_from) of each offer revision.
-- We will use it to get Offer name at invoice time.
-- NB: If you'd rather get "current" offer name, un-comment "offers_with_latest_revision"
offers_with_history as (
  select
    offer_id,
    offer_revision,
    name,
    opportunity_id,
    opportunity_name,
    opportunity_description,
    valid_from,
    -- When we try to look up an offer revision as at the acceptance date of a BYOL agreement, we run into a problem.
    -- For BYOL, the agreement might be accepted (using some external non-AWS system or manual process) days before
    -- that BYOL agreement is entered into AWS Marketplace by the buyer. Therefore, the buyer is permitted to manually
    -- enter a backdated acceptance date, which might predate the point in time when the first revision of the offer
    -- was created. To work around this, we need to adjust the valid_from on the first revision of the offer to be
    -- earlier than the earliest possible backdated BYOL agreement acceptance date.
    case
      when lag(valid_from) over (partition by offer_id order by valid_from asc) is null and valid_from<cast('2021-04-01' as timestamp)
      then date_add('Day', -3857, valid_from)
      -- 3857 is the longest delay between acceptance_date of an agreement and the first revision of the offer
      when lag(valid_from) over (partition by offer_id order by valid_from asc) is null and valid_from >= cast('2021-04-01' as timestamp)
      then date_add('Day', -1460, valid_from)
      --after 2021 for the two offers we need to adjust for 2 more years
      else valid_from
    end as valid_from_adjusted,
    coalesce(
      lead(valid_from) over (partition by offer_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp))
    as valid_to
  from offers_with_uni_temporal_data
),
-- provided for reference only if you are interested into get "current" offer name
-- (ie. not used afterwards)
offers_with_latest_revision as (
  select
    offer_id,
    offer_revision,
    name,
    opportunity_name,
    opportunity_description,
    valid_from,
    null valid_to
  from
  (
    select
      offer_id,
      offer_revision,
      name,
      opportunity_name,
      opportunity_description,
      valid_from,
      null valid_to,
      row_number() over (partition by offer_id order by valid_from desc) as row_num_latest_revision
    from
      offers_with_uni_temporal_data
  )
  where
    row_num_latest_revision = 1
),

-- An offer_target_id has several valid_from dates (each representing an offer revision)
-- but because of bi-temporality, an offer_target_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
offer_targets_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    offer_target_id,
    offer_id,
    offer_revision,
    target_type,
    polarity,
    value
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      offer_target_id,
      offer_id,
      offer_revision,
      target_type,
      polarity,
      value,
      row_number() over (partition by offer_target_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      offertargetfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

offer_target_type as (
  select
    offer_id,
    offer_revision,
    substring(
      -- The first character indicates the priority (lower value means higher precedence):
      min(
        case
          when offer_target.target_type='BuyerAccounts' then '1Private'
          when offer_target.target_type='ParticipatingPrograms' then '2Program:'||cast(offer_target.value as varchar)
          when offer_target.target_type='CountryCodes' then '3GeoTargeted'
          -- well, there is no other case today, but rather be safe...
          else '4Other Targeting'
        end
      ),
      -- Remove the first character that was only used for th priority in the "min" aggregate function:
      2
    ) as offer_target
  from
    offer_targets_with_uni_temporal_data as offer_target
  group by
    offer_id,
    offer_revision
),

offers_with_history_with_target_type as (
  select
    offer.offer_id,
    offer.offer_revision,
    -- even though today it is not possible to combine several types of targeting in a single offer, let's ensure the query is still predictable if this gets possible in the future
    max(
      case
        when off_tgt.offer_target is null then 'Public'
        else off_tgt.offer_target
      end
    ) as offer_target,
    min(offer.name) as name,
    min(offer.opportunity_name) as opportunity_name,
    min(offer.opportunity_description) as opportunity_description,
    offer.valid_from,
    offer.valid_from_adjusted,
    offer.valid_to,
    offer.opportunity_id
  from
    offers_with_history as offer
  left join offer_target_type as off_tgt on
    offer.offer_id = off_tgt.offer_id
    and offer.offer_revision = off_tgt.offer_revision
  group by
    offer.offer_id,
    offer.offer_revision,
    offer.valid_from,
    offer.valid_from_adjusted,
    offer.valid_to,
    offer.opportunity_id
),

-- provided for reference only if you are interested into get "current" offer targets
-- (ie. not used afterwards)
offers_with_latest_revision_with_target_type as (
  select
    offer.offer_id,
    offer.offer_revision,
    -- even though today it is not possible to combine several types of targeting in a single offer, let's ensure the query is still predictable if this gets possible in the future
    max(
      distinct
      case
        when off_tgt.target_type is null then 'Public'
        when off_tgt.target_type='BuyerAccounts' then 'Private'
        when off_tgt.target_type='ParticipatingPrograms' then 'Program:'||cast(off_tgt.value as varchar)
        when off_tgt.target_type='CountryCodes' then 'GeoTargeted'
        -- well, there is no other case today, but rather be safe...
        else 'Other Targeting'
      end
    ) as offer_target,
    min(offer.name) as name,
    min(offer.opportunity_name) as opportunity_name,
    min(offer.opportunity_description) as opportunity_description,
    offer.valid_from,
    offer.valid_to
  from
    offers_with_latest_revision offer
    -- left joining because public offers don't have targets
    left join offer_targets_with_uni_temporal_data off_tgt on
      offer.offer_id=off_tgt.offer_id and offer.offer_revision=off_tgt.offer_revision
  group by
    offer.offer_id,
    offer.offer_revision,
    -- redundant with offer_revision, as each revision has a dedicated valid_from (but cleaner in the group by)
    offer.valid_from,
    offer.valid_to
),

-- A product_id has several valid_from dates (each representing a product revision),
-- but because of bi-temporality, each product_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
products_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    product_id,
    manufacturer_account_id,
    product_code,
    title
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      product_id,
      manufacturer_account_id,
      product_code,
      title,
      row_number() over (partition by product_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      productfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

products_with_history as (
  select
    product_id,
    title,
    valid_from,
    -- Offerv2 can have upto 50 years and Offerv3 is upto 5 years of past date
    case
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from<cast('2021-04-01' as timestamp)
        then date_add('Day', -3857, valid_from)
      -- 3827 is the longest delay between acceptance_date of an agreement and the product
      -- we are keeping 3857 as a consistency between the offers and products
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from >= cast('2021-04-01' as timestamp)
        then date_add('Day', -2190, valid_from)
      --after 2021 for the two offers we need to adjust for 2 more years
      else valid_from 
    end as valid_from_adjusted,
    coalesce(
      lead(valid_from) over (partition by product_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to,
    product_code,
    manufacturer_account_id
  from
    products_with_uni_temporal_data
),

legacy_products as (
  select
    legacy_id,
    new_id
  from
    legacyidmappingfeed_v1
  where
    mapping_type='PRODUCT'
  group by
    legacy_id,
    new_id
),

-- A given billing_event_id represents an accounting event and thus has only one valid_from date,
-- but because of bi-temporality, a billing_event_id (+ its valid_from) can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
billing_events_with_uni_temporal_data as (
  select
    billing_event_id,
    valid_from,
    update_date,
    delete_date,
    invoice_date,
    transaction_type,
    transaction_reference_id,
    parent_billing_event_id,
    bank_trace_id,
    broker_id,
    product_id,
    disbursement_billing_event_id,
    action,
    from_account_id,
    to_account_id,
    end_user_account_id,
    billing_address_id,
    amount,
    currency,
    balance_impacting,
    --empty value in Athena shows as '', change all '' value to null
    case when agreement_id = '' then null else agreement_id end as agreement_id,
    invoice_id,
    payment_due_date,
    usage_period_start_date,
    usage_period_end_date,
    buyer_transaction_reference_id,
    row_num
  from
  (
    select
      billing_event_id,
      from_iso8601_timestamp(valid_from) as valid_from,
      from_iso8601_timestamp(update_date) as update_date,
      delete_date,
      from_iso8601_timestamp(invoice_date) as invoice_date,
      transaction_type,
      transaction_reference_id,
      parent_billing_event_id,
      -- casting in case data was imported as number
      cast(bank_trace_id as varchar) as bank_trace_id,
      broker_id,
      product_id,
      disbursement_billing_event_id,
      action,
      from_account_id,
      to_account_id,
      end_user_account_id,
      billing_address_id,
      -- casting in case data was imported as varchar
      cast(amount as decimal(38,6)) as amount,
      currency,
      balance_impacting,
      agreement_id,
      invoice_id,
      case when payment_due_date is null or payment_due_date = '' then null else from_iso8601_timestamp(payment_due_date) end as payment_due_date,
      from_iso8601_timestamp(usage_period_start_date) as usage_period_start_date,
      from_iso8601_timestamp(usage_period_end_date) as usage_period_end_date,
      buyer_transaction_reference_id,
      row_number() over (partition by billing_event_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      billingeventfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- Here we select the account_id of the current seller (We identify this by looking for the to_account_id related to revenue transactions).
-- We will use it later to distinguish own agreements from agreements generated by channel partners.
seller_account as (
  select
    from_account_id as seller_account_id
  from
    billing_events_with_uni_temporal_data bill
  where
    -- Assumption here is only seller will pay listing fee. As of 12/21/2021, there are cases that Channel partner have 0 listing fee for CPPO, so the amount could be 0.
    bill.transaction_type like 'AWS_REV_SHARE' and amount <= 0 and action = 'INVOICED'
  group by
    -- from_account_id is always the same for all those "listing fee" transactions == the seller of record himself.
    -- If this view returns more than 1 record, the overall query will fail (on purpose). Please contact AWS Marketplace if this happens.
    from_account_id
),

billing_event_with_business_flags as (
  select
    bl.billing_event_id,
    bl.end_user_account_id,
    bl.agreement_id,
    aggrement.proposer_account_id,
    aggrement.offer_id,
    aggrement.acceptor_account_id,
    case
      -- For AWS and BALANCE_ADJUSTMENT, the billing event feed will show the "AWS Marketplace" account as the
      -- receiver of the funds and the seller as the payer. We are not interested in this information here.
      -- Null values will be ignored by the `max` aggregation function.
      when bl.transaction_type like 'AWS%' then null
      -- For BALANCE_ADJUSTMENT, payer is seller themselves
      when bl.invoice_id is null then bl.to_account_id
      -- We get the payer of the invoice from *any* transaction type that is not AWS and not BALANCE_ADJUSTMENT (because they are the same for a given end user + agreement + product).
      else bl.from_account_id
    end as payer_account_id,
    bl.product_id,
    bl.action,
    bl.transaction_type,
    bl.parent_billing_event_id,
    bl.disbursement_billing_event_id,
    bl.amount,
    bl.currency,
    bl.balance_impacting,
    bl.invoice_date,
    bl.payment_due_date,
    bl.usage_period_start_date,
    bl.usage_period_end_date,
    bl.invoice_id,
    bl.billing_address_id,
    bl.transaction_reference_id,
    bl.buyer_transaction_reference_id,
    case when disbursement.bank_trace_id = 'EMEA_MP_TEST_TRACE_ID' then null else disbursement.bank_trace_id end as bank_trace_id,
    case when disbursement.bank_trace_id = 'EMEA_MP_TEST_TRACE_ID' then null else disbursement.invoice_date end as disbursement_date,
    disbursement.billing_event_id as disbursement_id,
    -- We will use disbursement_id_or_invoiced as part of the PK, so it cannot be null:
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when disbursement.billing_event_id = '' then null else disbursement.billing_event_id end,
      '<invoiced>') as disbursement_id_or_invoiced,
    bl.broker_id,
    case
      when bl.invoice_id is null /* transaction_type = 'BALANCE_ADJUSTMENT' */
        then (select seller_account_id from seller_account) ||':'|| cast(bl.invoice_date as varchar)
      else bl.buyer_transaction_reference_id
        ||'-'|| case when bl.agreement_id is null or bl.agreement_id = '' then ' ' else bl.agreement_id end
        ||'-'|| case when bl.end_user_account_id is null or bl.end_user_account_id = '' then ' ' else bl.end_user_account_id end
        ||'-'|| coalesce(cast(bl.usage_period_start_date as varchar),' ')
        ||'-'|| coalesce(cast(bl.usage_period_end_date as varchar),' ')
    end as internal_buyer_line_item_id,
    bl.buyer_transaction_reference_id <> bl.transaction_reference_id as is_seller_invoice,
    case when bl.transaction_type = 'SELLER_REV_SHARE' and (select seller_account_id from seller_account) <> bl.to_account_id then true else false end as is_cog,
    case when bl.transaction_type in('SELLER_REV_SHARE_CREDIT', 'SELLER_REV_SHARE_REFUND') and (select seller_account_id from seller_account) <> bl.to_account_id then true else false end as is_cog_refund,
    --TODO: replace below logic once we can create a logic the identify reseller/manufacturer without depending on agreement feed
    case when aggrement.proposer_account_id <> (select seller_account_id from seller_account) then true else false end as is_manufacturer_view_of_reseller
  from
    billing_events_with_uni_temporal_data as bl
    left join billing_events_with_uni_temporal_data as disbursement on
      disbursement.transaction_type like 'DISBURSEMENT%'
        and disbursement.action = 'DISBURSED'
        and disbursement.transaction_type IN ('DISBURSEMENT', 'DISBURSEMENT_FAILURE')
        and bl.disbursement_billing_event_id = disbursement.billing_event_id
    left join agreements_with_history as aggrement on
      bl.agreement_id = aggrement.agreement_id
        and bl.invoice_date >= aggrement.valid_from_adjusted
        and bl.invoice_date<aggrement.valid_to
    left join accounts_with_history awh on
      bl.to_account_id = awh.account_id
        and bl.invoice_date >= awh.valid_from
        and bl.invoice_date<awh.valid_to
  where
    bl.transaction_type not like 'DISBURSEMENT%' and
      (bl.agreement_id is null or bl.agreement_id = ''
      or aggrement.agreement_id is not null)
),

-- listagg function in athena does not support partitioning, grouping here and then joining to the main query
seller_invoice_list as (
  select
    internal_buyer_line_item_id,
    listagg(case when not is_seller_invoice then null else invoice_id end,',') within group (order by case when not is_seller_invoice then null else cast(invoice_date as varchar) end) as seller_invoice_id_or_null,
    listagg(case when not is_seller_invoice then null else cast(invoice_date as varchar) end,',') within group (order by case when not is_seller_invoice then null else cast(invoice_date as varchar) end) as seller_invoice_date_or_null
  from
    (
    -- listagg function in athena does not support ordering by another field when distinct is used,
    -- here we first select distinct invoices and then do the listagg order by invoice_date
    select distinct internal_buyer_line_item_id, is_seller_invoice, invoice_id, invoice_date
    from billing_event_with_business_flags) distinct_invoices
  group by internal_buyer_line_item_id
  order by internal_buyer_line_item_id
),

billing_event_with_categorized_transaction as (
-- Use the flags that were created in the previous transformation in more calculated columns:
-- NOTE: This transformation has no joins and no window functions
  select
    billing_event_id,
    end_user_account_id,
    agreement_id,
    proposer_account_id,
    offer_id,
    acceptor_account_id,
    case when is_cog or is_cog_refund then null else payer_account_id end as payer_account_id,
    product_id,
    action,
    transaction_type,
    parent_billing_event_id,
    disbursement_billing_event_id,
    amount,
    currency,
    balance_impacting,
    invoice_date,
    payment_due_date,
    usage_period_start_date,
    usage_period_end_date,
    invoice_id,
    billing_address_id,
    transaction_reference_id,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date,
    disbursement_id,
    disbursement_id_or_invoiced,
    broker_id,
    bl.internal_buyer_line_item_id,
    is_seller_invoice,
    is_cog,
    is_cog_refund,
    is_manufacturer_view_of_reseller,

    -- Buyer/seller columns:
    case when is_seller_invoice then null else invoice_id end as buyer_invoice_id_or_null,
    seller_invoices.seller_invoice_id_or_null,
    case when is_seller_invoice then null else invoice_date end as buyer_invoice_date_or_null,
    seller_invoices.seller_invoice_date_or_null,

    -- Categorized amounts by transaction type:
    case when transaction_type =   'SELLER_REV_SHARE' and not is_cog then amount else 0 end as gross_revenue,
    case when transaction_type in ('SELLER_REV_SHARE_REFUND','SELLER_REV_SHARE_CREDIT') and not is_cog_refund then amount else 0 end as gross_refund,
    case when transaction_type =   'SELLER_REV_SHARE' and     is_cog then amount else 0 end as cogs,
    case when transaction_type in ('SELLER_REV_SHARE_REFUND','SELLER_REV_SHARE_CREDIT') and     is_cog_refund then amount else 0 end as cogs_refund,
    case when transaction_type =   'AWS_REV_SHARE' then amount else 0 end as aws_rev_share,
    case when transaction_type in ('AWS_REV_SHARE_REFUND','AWS_REV_SHARE_CREDIT') then amount else 0 end as aws_refund_share,
    case when transaction_type =   'AWS_TAX_SHARE' and not is_seller_invoice then amount else 0 end as aws_tax_share,             -- AWS tax share from _buyer_  invoice
    case when transaction_type =   'AWS_TAX_SHARE' and     is_seller_invoice then amount else 0 end as aws_tax_share_listing_fee, -- AWS tax share from _seller_ invoice
    case when transaction_type =   'AWS_TAX_SHARE_REFUND' and not is_seller_invoice then amount else 0 end as aws_tax_share_refund,
    case when transaction_type =   'AWS_TAX_SHARE_REFUND' and     is_seller_invoice then amount else 0 end as aws_tax_share_refund_listing_fee,
    case when transaction_type =   'SELLER_TAX_SHARE' then amount else 0 end as seller_tax_share,
    case when transaction_type =   'SELLER_TAX_SHARE_REFUND' then amount else 0 end as seller_tax_share_refund,
    case when transaction_type =   'BALANCE_ADJUSTMENT' then amount else 0 end as balance_adjustment,
    case when transaction_type =   'SELLER_REV_SHARE_CREDIT' then amount else 0 end as seller_rev_credit,
    case when transaction_type =   'AWS_REV_SHARE_CREDIT' then amount else 0 end as aws_ref_fee_credit
  from
    billing_event_with_business_flags as bl
    left join seller_invoice_list as seller_invoices
      on bl.internal_buyer_line_item_id = seller_invoices.internal_buyer_line_item_id
    ),

line_items_aggregated as (
-- This transformation has the only "group by" in all of these transformations.
-- NOTE: This transformation has no joins and no window functions
  select
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    broker_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    max(payer_account_id) as payer_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    max(payment_due_date) payment_due_date,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date,
    max(billing_address_id) as billing_address_id,

    -- Buyer/seller columns:
    max(buyer_invoice_id_or_null) as buyer_invoice_id,
    max(seller_invoice_id_or_null) as seller_invoice_id,
    max(buyer_invoice_date_or_null) as buyer_invoice_date,
    max(seller_invoice_date_or_null) as seller_invoice_date,
  
    -- Categorized amounts by transaction type:
    -- When disbursement_id_or_invoiced = '<invoiced>',    these are invoiced amounts
    -- When disbursement_id_or_invoiced <> '<invoiced>' these are disbursed amounts for _this_ specific disbursement_id
    sum(gross_revenue) as gross_revenue_this_disbursement_id_or_invoiced,
    sum(gross_refund) as gross_refund_this_disbursement_id_or_invoiced,
    sum(cogs) as cogs_this_disbursement_id_or_invoiced,
    sum(cogs_refund) as cogs_refund_this_disbursement_id_or_invoiced,
    sum(aws_rev_share) as aws_rev_share_this_disbursement_id_or_invoiced,
    sum(aws_refund_share) as aws_refund_share_this_disbursement_id_or_invoiced,
    sum(aws_tax_share) as aws_tax_share_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_listing_fee) as aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_refund) as aws_tax_share_refund_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_refund_listing_fee) as aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    sum(seller_tax_share) as seller_tax_share_this_disbursement_id_or_invoiced,
    sum(seller_tax_share_refund) as seller_tax_share_refund_this_disbursement_id_or_invoiced,
    sum(balance_adjustment) as balance_adjustment_this_disbursement_id_or_invoiced,
    sum(seller_rev_credit) as seller_rev_credit_this_disbursement_id_or_invoiced,
    sum(aws_ref_fee_credit) as aws_ref_fee_credit_this_disbursement_id_or_invoiced
  from
    billing_event_with_categorized_transaction as billing_categorized
  group by
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    broker_id,
    -- The following columns are included the in group by but they are intentionally omitted from the PK.
    -- These columns should have the _same_ values for each record in the PK.
    product_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date
),

-- listagg function in athena does not support partitioning, grouping here and then joining to the main query
disbursement_list as (
  select
    internal_buyer_line_item_id,
    listagg(cast(disbursement_date as varchar),',') within group (order by cast(disbursement_date as varchar)) as disbursement_date_list,
    listagg(bank_trace_id,',') within group (order by cast(disbursement_date as varchar)) as disburse_bank_trace_id_list
    from (
    -- listagg function in athena does not support ordering by another field when distinct is used,
    -- here we first select distinct bank_trace_ids and then do the listagg order by disbursement_date
    select distinct internal_buyer_line_item_id, disbursement_date, bank_trace_id
  from billing_event_with_business_flags) distinct_disbursements
  group by internal_buyer_line_item_id
  order by internal_buyer_line_item_id
),

line_items_with_window_functions as (
--add flag next step compare gross_revenue and gross_revenue_disbursed or gross_refund and gross_refund_disbursed
  select
    line_item.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    broker_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    -- when there's aws_rev_Share adjustment/refund to a seller_rev_share invoice, it can happen that for the same aws_rev_share invoice_id, there are multiple disbursement events,
    -- using windows function to map payer_account_id of seller_rev_share to all corresponding aws_rev_Share
    max(payer_account_id) over (partition by line_item.internal_buyer_line_item_id) as payer_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,

    -- Buyer/seller columns:
    max(buyer_invoice_id) over (partition by line_item.internal_buyer_line_item_id) as buyer_invoice_id,
    seller_invoice_id,
    max(buyer_invoice_date) over (partition by line_item.internal_buyer_line_item_id) as buyer_invoice_date,
    seller_invoice_date,

    -- When disbursement_id_or_invoiced = '<invoiced>', these are actually invoiced amounts
    -- When disbursement_id_or_invoiced <> '<invoiced>' these are disbursed amounts for _this_ specific disbursement_id
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    -- IMPORTANT: All window functions partitioned by internal_buyer_line_item_id:

    -- Invoiced amounts, categorized by transaction type:
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then gross_revenue_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end)over (partition by line_item.internal_buyer_line_item_id) as gross_revenue_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then gross_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then cogs_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then cogs_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_rev_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_rev_share_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_refund_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_refund_share_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_tax_share_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_listing_fee_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_listing_fee_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then seller_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then seller_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then balance_adjustment_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as balance_adjustment_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then seller_rev_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_rev_credit_invoiced,
    sum(case when disbursement_id_or_invoiced = '<invoiced>' then aws_ref_fee_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_ref_fee_credit_invoiced,

    -- Total disbursed amounts (for all disbursement_id values), categorized by transaction type:
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then gross_revenue_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_revenue_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then gross_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_refund_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then cogs_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then cogs_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_refund_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_rev_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_rev_share_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_refund_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_refund_share_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_tax_share_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_listing_fee_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_listing_fee_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then seller_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then seller_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_refund_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then balance_adjustment_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as balance_adjustment_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then seller_rev_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_rev_credit_disbursed,
    sum(case when disbursement_id_or_invoiced <> '<invoiced>' then aws_ref_fee_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_ref_fee_credit_disbursed,

    -- aggregate multiple disbursement
    max(disbursement_date) over (partition by line_item.internal_buyer_line_item_id) as last_disbursement_date,
    first_value(case when disbursement_id_or_invoiced = '<invoiced>' then null else disbursement_id_or_invoiced end) over(partition by line_item.internal_buyer_line_item_id order by coalesce(disbursement_date,cast('1900-01-01' as timestamp)) desc rows between unbounded preceding and unbounded following) as last_disbursement_id,
    first_value(bank_trace_id) over (partition by line_item.internal_buyer_line_item_id order by coalesce(disbursement_date,cast('1900-01-01' as timestamp)) desc rows between unbounded preceding and unbounded following) as last_disburse_bank_trace_id,
    disb_list.disbursement_date_list,
    disb_list.disburse_bank_trace_id_list
  from
    line_items_aggregated as line_item
    left join disbursement_list disb_list
      on line_item.internal_buyer_line_item_id = disb_list.internal_buyer_line_item_id
),

cppo_offer_id as (
  select
    -- Channel partner offers do not exist in offertargetfeed_v1 table (as per legal requirement), causing cppo offer be defined as 'Public' in previous step, we will convert them back to 'Private' in next step
    offer_id
  from
    offers_with_uni_temporal_data
  where
    -- seller_account_id is null means the ISV owns the offer
    seller_account_id is not null
    and seller_account_id <>  (select seller_account_id from seller_account)
  group by
    offer_id
),

line_items_with_window_functions_enrich_offer_product_address as (
  select
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    line.product_id,
    legacy_product.legacy_id as legacy_product_id,
    products.title as product_title,
    line.broker_id,
    line.currency,
    line.end_user_account_id,
    acc_enduser.encrypted_account_id as end_user_encrypted_account_id,
    acc_enduser.aws_account_id as end_user_aws_account_id,
    acc_payer.aws_account_id as payer_aws_account_id,
    acc_payer.encrypted_account_id payer_encrypted_account_id,
    line.agreement_id,
    agreement.agreement_revision,
    line.proposer_account_id,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.start_date end as Agreement_Start_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.end_date end as Agreement_End_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.acceptance_date end as Agreement_Acceptance_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.valid_from end as agreement_updated_date,
    case when offer.offer_id like 'aiqoffer-%' then null else line.usage_period_start_date end as Usage_Period_Start_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else line.usage_period_end_date end as Usage_Period_End_Date,

    line.acceptor_account_id,
    acc_subscriber.aws_account_id as subscriber_aws_account_id,
    acc_subscriber.encrypted_account_id as subscriber_encrypted_account_id,
    offer.offer_id,
    case
      when offer.offer_id in (
        select distinct offer_id
        from cppo_offer_id)
        then 'Private'
      else offer.offer_target
    end as offer_target,
    offer.name offer_name,
    offer.opportunity_name offer_opportunity_name,
    offer.opportunity_description offer_opportunity_description,
    offer.opportunity_id,
    payment_due_date,
    line.bank_trace_id,
    disbursement_date,
    billing_address_id,
    buyer_invoice_id,
    seller_invoice_id,
    buyer_invoice_date,
    seller_invoice_date,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    products.product_code,
    acc_products.aws_account_id as manufacturer_aws_account_id,
    products.manufacturer_account_id,
    --add subscriber and payer addressID, payer address preference order: tax address > billing address > mailing address,  subscriber address preference order: tax address >  mailing address
    coalesce (
      --empty value in Athena shows as '', change all '' value to null in order to follow the preference order logic above
      case when acc_subscriber.tax_address_id ='' then null else acc_subscriber.tax_address_id end,
      case when acc_subscriber.mailing_address_id = '' then null else acc_subscriber.mailing_address_id end) as subscriber_address_id,
    coalesce (
      case when acc_payer.tax_address_id = '' then null else acc_payer.tax_address_id end,
      case when line.billing_address_id = '' then null else line.billing_address_id end,
      case when acc_payer.mailing_address_id = '' then null else acc_payer.mailing_address_id end) as payer_address_id,
    coalesce (
      case when acc_enduser.tax_address_id = '' then null else acc_enduser.tax_address_id end,
      case when line.billing_address_id = '' then null else line.billing_address_id end,
      case when acc_enduser.mailing_address_id = '' then null else acc_enduser.mailing_address_id end) as end_user_address_id
  from
    line_items_with_window_functions as line
  left join agreements_with_history as agreement on
      line.agreement_id = agreement.agreement_id and line.buyer_invoice_date >= agreement.valid_from_adjusted and line.buyer_invoice_date<agreement.valid_to
  left join offers_with_history_with_target_type as offer on
        line.offer_id = offer.offer_id and line.buyer_invoice_date >= offer.valid_from and line.buyer_invoice_date<offer.valid_to
  left join products_with_history as products on
        line.product_id = products.product_id and line.buyer_invoice_date >= products.valid_from_adjusted and line.buyer_invoice_date<products.valid_to
  left join legacy_products as legacy_product on
        line.product_id = legacy_product.new_id
  left join accounts_with_history_with_company_name as acc_payer on
        line.payer_account_id = acc_payer.account_id and line.buyer_invoice_date >= acc_payer.valid_from and line.buyer_invoice_date<acc_payer.valid_to
  left join accounts_with_history_with_company_name as acc_enduser on
        line.end_user_account_id = acc_enduser.account_id and line.buyer_invoice_date >= acc_enduser.valid_from and line.buyer_invoice_date<acc_enduser.valid_to
  left join accounts_with_history_with_company_name as acc_subscriber on
        line.acceptor_account_id = acc_subscriber.account_id and line.buyer_invoice_date >= acc_subscriber.valid_from and line.buyer_invoice_date<acc_subscriber.valid_to
  left join accounts_with_history_with_company_name as acc_products on
        products.manufacturer_account_id = acc_products.account_id and line.buyer_invoice_date >= acc_products.valid_from and line.buyer_invoice_date<acc_products.valid_to

),

line_items_with_window_functions_enrich_offer_product_address_name as (
  select
    line.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    legacy_product_id,
    product_title,
    broker_id,
    currency,
    end_user_address_id,
    end_user_account_id,
    end_user_encrypted_account_id,
    end_user_aws_account_id,
    add_enduser.company_name end_user_company_name,
    add_enduser.email_domain end_user_email_domain,
    add_enduser.city end_user_city,
    add_enduser.state_or_region end_user_state,
    add_enduser.country_code end_user_country,
    add_enduser.postal_code end_user_postal_code,
    payer_aws_account_id,
    payer_encrypted_account_id,
    payer_address_id,
    add_payer.company_name payer_company_name,
    add_payer.email_domain payer_email_domain,
    add_payer.city payer_city,
    add_payer.state_or_region payer_state,
    add_payer.country_code payer_country,
    add_payer.postal_code payer_postal_code,
    agreement_id,
    agreement_revision,
    agreement_start_date,
    agreement_end_date,
    agreement_acceptance_date,
    agreement_updated_date,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.aws_account_id end as reseller_aws_account_id,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.mailing_company_name end as reseller_company_name,
    usage_period_start_date,
    usage_period_end_date,
    proposer_account_id,
    acc_proposer.aws_account_id as proposer_aws_account_id,
    acceptor_account_id,
    subscriber_aws_account_id,
    subscriber_encrypted_account_id,
    subscriber_address_id,
    add_subscriber.company_name subscriber_company_name,
    add_subscriber.email_domain subscriber_email_domain,
    add_subscriber.city subscriber_city,
    add_subscriber.state_or_region subscriber_state,
    add_subscriber.country_code subscriber_country,
    add_subscriber.postal_code subscriber_postal_code,
    offer_id,
    offer_target,
    offer_name,
    offer_opportunity_name,
    offer_opportunity_description,
    opportunity_id,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,
    max(buyer_invoice_id)as buyer_invoice_id,
    max(seller_invoice_id)as seller_invoice_id,
    max(buyer_invoice_date)as buyer_invoice_date,
    max(seller_invoice_date)as seller_invoice_date,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    (gross_revenue_this_disbursement_id_or_invoiced + gross_refund_this_disbursement_id_or_invoiced + aws_rev_share_this_disbursement_id_or_invoiced + aws_refund_share_this_disbursement_id_or_invoiced + seller_tax_share_this_disbursement_id_or_invoiced + seller_tax_share_refund_this_disbursement_id_or_invoiced
      + cogs_this_disbursement_id_or_invoiced + cogs_refund_this_disbursement_id_or_invoiced + aws_tax_share_listing_fee_this_disbursement_id_or_invoiced + aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced) as seller_net_revenue_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    (gross_revenue_invoiced + gross_revenue_disbursed) as uncollected_gross_revenue,
    -- net revenue = gross revenue - listing fee - tax - cogs
    (gross_revenue_invoiced + gross_refund_invoiced + aws_rev_share_invoiced + aws_refund_share_invoiced + seller_tax_share_invoiced + seller_tax_share_refund_invoiced + cogs_invoiced + cogs_refund_invoiced + aws_tax_share_listing_fee_invoiced + aws_tax_share_refund_listing_fee_invoiced) as seller_net_revenue,
    (gross_revenue_invoiced + gross_refund_invoiced + aws_rev_share_invoiced + aws_refund_share_invoiced + seller_tax_share_invoiced + seller_tax_share_refund_invoiced + cogs_invoiced + cogs_refund_invoiced + aws_tax_share_listing_fee_invoiced + aws_tax_share_refund_listing_fee_invoiced
      + gross_revenue_disbursed + gross_refund_disbursed + aws_rev_share_disbursed + aws_refund_share_disbursed + seller_tax_share_disbursed + seller_tax_share_refund_disbursed + cogs_disbursed + cogs_refund_disbursed + aws_tax_share_listing_fee_disbursed + aws_tax_share_refund_listing_fee_disbursed) as uncollected_seller_net_revenue,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    product_code,
    manufacturer_aws_account_id,
    manufacturer_account_id,
    acc_manu.mailing_company_name as manufacturer_company_name,
    cast(null as varchar) as AR_Period,
    case
      when (
        (gross_revenue_invoiced <>0 and gross_revenue_invoiced = -1 * gross_revenue_disbursed)
        or (gross_refund_invoiced <> 0 and gross_refund_invoiced = -1 * gross_refund_disbursed)
        or (balance_adjustment_invoiced <> 0 and balance_adjustment_invoiced = -1 * balance_adjustment_disbursed)
        or (seller_tax_share_refund_invoiced <> 0 and seller_tax_share_refund_invoiced = -1 * seller_tax_share_refund_disbursed)
        or (gross_revenue_invoiced = 0 and gross_refund_invoiced = 0 and balance_adjustment_invoiced = 0 and seller_tax_share_refund_invoiced = 0 and last_disbursement_id is not null)) then 'Yes'
      when gross_revenue_disbursed = 0 and gross_refund_disbursed = 0 and balance_adjustment_disbursed = 0 and seller_tax_share_disbursed = 0 and seller_tax_share_refund_disbursed = 0 then 'No'
      else 'Partial'
    end as Disbursement_Flag
  from line_items_with_window_functions_enrich_offer_product_address as line
  left join accounts_with_history_with_company_name as acc_manu on
    line.manufacturer_account_id = acc_manu.account_id and line.buyer_invoice_date >= acc_manu.valid_from_adjusted and line.buyer_invoice_date <= acc_manu.valid_to
  left join accounts_with_history_with_company_name as acc_proposer on
    line.proposer_account_id = acc_proposer.account_id and line.buyer_invoice_date >= acc_proposer.valid_from and line.buyer_invoice_date<acc_proposer.valid_to
  left join address_with_latest_revision as add_payer on
    line.payer_address_id = add_payer.address_id
  left join address_with_latest_revision as add_subscriber on
    line.subscriber_address_id = add_subscriber.address_id
  left join address_with_latest_revision as add_enduser on
    line.end_user_address_id = add_enduser.address_id
  group by
    line.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    legacy_product_id,
    product_title,
    broker_id,
    currency,
    end_user_address_id,
    end_user_account_id,
    end_user_encrypted_account_id,
    end_user_aws_account_id,
    add_enduser.company_name,
    add_enduser.email_domain,
    add_enduser.city,
    add_enduser.state_or_region,
    add_enduser.country_code,
    add_enduser.postal_code,
    payer_aws_account_id,
    payer_encrypted_account_id,
    payer_address_id,
    add_payer.company_name,
    add_payer.email_domain,
    add_payer.city,
    add_payer.state_or_region,
    add_payer.country_code,
    add_payer.postal_code,
    agreement_id,
    agreement_revision,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.aws_account_id end,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.mailing_company_name end,
    agreement_start_date,
    agreement_end_date,
    agreement_acceptance_date,
    agreement_updated_date,
    usage_period_start_date,
    usage_period_end_date,
    acceptor_account_id,
    subscriber_aws_account_id,
    subscriber_encrypted_account_id,
    subscriber_address_id,
    add_subscriber.company_name,
    add_subscriber.email_domain,
    add_subscriber.city,
    add_subscriber.state_or_region,
    add_subscriber.country_code,
    add_subscriber.postal_code,
    offer_id,
    offer_target,
    offer_name,
    offer_opportunity_name,
    offer_opportunity_description,
    opportunity_id,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    product_code,
    manufacturer_aws_account_id,
    manufacturer_account_id,
    acc_manu.mailing_company_name,
    proposer_account_id,
    acc_proposer.aws_account_id
),

billed_revenue as (
  select
    ------------------
    -- Invoice Info --
    ------------------
    buyer_invoice_date as Invoice_Date,
    Payment_Due_Date as Payment_Due_Date,
    concat(
      'Net ',
      case
        when abs(date_diff('Day', Payment_due_date, buyer_invoice_date))>180 then '180+'
        else cast(abs(date_diff('Day', Payment_due_date, buyer_invoice_date)) as varchar)
        end,
      ' days'
    ) as payment_terms,
    buyer_invoice_id as Invoice_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when seller_invoice_id = '' then null else seller_invoice_id end,
      'Not applicable') as Listing_Fee_Invoice_ID,

    ---------------------------
    --End user Information --
    ---------------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when End_User_Company_Name = '' then null else End_User_Company_Name end,
      'Not available') as End_User_Company_Name,
    End_User_AWS_Account_ID,
    End_User_Encrypted_Account_ID,
    End_User_Email_Domain,
    End_User_City,
    End_User_State as End_User_State_or_Region,
    End_User_Country,
    End_User_Postal_Code,
    End_User_Address_ID,

    ---------------------------
    --Subscriber Information --
    ---------------------------
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Company_Name is null or Subscriber_Company_Name = '' then 'Not provided'
      else Subscriber_Company_Name
      end as Subscriber_Company_Name,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_AWS_Account_ID
      end as Subscriber_AWS_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_Encrypted_Account_ID
      end as Subscriber_Encrypted_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Email_Domain is null or Subscriber_Email_Domain = '' then 'Not provided'
      else Subscriber_Email_Domain
      end as Subscriber_Email_Domain,
    case
      when Agreement_id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_City is null or Subscriber_City = '' then 'Not provided'
      else Subscriber_City
      end as Subscriber_City,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_State is null or Subscriber_State = '' then 'Not provided'
      else Subscriber_State
      end as Subscriber_State_or_Region,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Country is null or Subscriber_Country = '' then 'Not provided'
      else Subscriber_Country
      end as Subscriber_Country,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Postal_Code is null or Subscriber_Postal_Code = '' then 'Not provided'
      else Subscriber_Postal_Code
      end as Subscriber_Postal_Code,
    case
      when Agreement_ID is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Address_ID is null or Subscriber_Address_ID = '' then 'Not provided'
      else Subscriber_Address_ID
      end as Subscriber_Address_ID,

    ----------------------
    -- Procurement Info --
    ----------------------
     -- product title at time of invoice. It is possible that the title changes over time and therefore there may be multiple product titles mapped to a single product id.
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_Title = '' then null else Product_Title end,
      'Not provided') as Product_Title,
    -- offer name at time of invoice. It is possible that the name changes over time therefore there may be multiple offer names mapped to a single offer id.
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when (Offer_Name is null or Offer_Name = '') and Offer_Target = 'Public' then 'Not applicable'
      else Offer_Name
      end as Offer_Name,
    case
      when Agreement_Id is null or Agreement_ID = ''
      then 'Not available'
      else Offer_ID
      end as Offer_ID,
    -- offer target at time of invoice.,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Offer_Target
      end as Offer_Visibility,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Agreement_ID = '' then null else Agreement_ID end,
      'Not available') as Agreement_ID,
    Agreement_Start_Date,
    Agreement_Acceptance_Date,
    Agreement_End_Date,
    Usage_Period_Start_Date,
    Usage_Period_End_Date,

    -----------------------
    -- Disbursement Info --
    -----------------------
    case
      when Disbursement_Flag = 'Yes' then 'Disbursed'
      when Disbursement_Flag = 'No' then 'Not Disbursed'
      else 'Other'
      end as Disbursement_Status,
    last_disbursement_date as disbursement_date,
    case
      when Disbursement_Flag = 'No' then 'Not applicable'
      when disburse_bank_trace_id_list is null or disburse_bank_trace_id_list = '' then 'Not available'
      else disburse_bank_trace_id_list
    end as disburse_bank_trace_id,

    --------------
    -- Revenues --
    --------------
    -- We are rounding the sums using 2 decimal precision
    -- Note that the rounding method might differ between SQL implementations.
    -- The monthly revenue report is using RoundingMode.HALF_UP. This might create tiny discrepancies between this SQL output
    -- and the legacy report
    round(gross_revenue_invoiced,2) as Gross_Revenue,
    round(gross_refund_invoiced,2) as Gross_Refund,
    round(aws_rev_share_invoiced,2) as Listing_Fee,
    round(aws_refund_share_invoiced,2) as Listing_Fee_Refund,
    truncate(
      case
        when gross_revenue_invoiced != 0 then abs(aws_rev_share_invoiced/gross_revenue_invoiced)
        when gross_refund_invoiced != 0 then abs(aws_refund_share_invoiced/gross_refund_invoiced)
        else 0
      end
      ,4) as Listing_Fee_Percentage,
    round(seller_tax_share_invoiced,2) as Seller_Tax_Share,
    round(seller_tax_share_refund_invoiced,2) as Seller_Tax_Share_Refund,
    round(aws_tax_share_invoiced,2) as AWS_Tax_Share,
    round(aws_tax_share_refund_invoiced,2) as AWS_Tax_Share_Refund,
    round(aws_tax_share_listing_fee_invoiced,2) as AWS_Tax_Share_Listing_Fee,
    round(aws_tax_share_refund_listing_fee_invoiced,2) as AWS_Tax_Share_Refund_Listing_Fee,
    round(cogs_invoiced,2) as Wholesale_cost,
    round(cogs_refund_invoiced,2) as Wholesale_cost_Refund,
    round(seller_net_revenue,2) as Seller_Net_Revenue,
    currency as Currency,

    substring(internal_buyer_line_item_id,1,strpos(internal_buyer_line_item_id,'-')-1) as Transaction_Reference_ID,
    broker_id as AWS_seller_of_record,

    -----------------
    -- Resale info --
    -----------------
    case
      when Opportunity_Id is null or Opportunity_Id = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Opportunity_Id
    end as Resale_authorization_ID,
    case
      when Offer_Opportunity_Name is null or Offer_Opportunity_Name = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Offer_Opportunity_Name
    end as Resale_authorization_name,
    case
      when Offer_Opportunity_Description is null or Offer_Opportunity_Description = '' then
        case
         when Offer_Target = 'Public' then 'Not applicable'
         when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
         else null
        end
      else Offer_Opportunity_Name
    end as Resale_authorization_description,
    case
      when (Reseller_AWS_Account_ID is not null and Reseller_AWS_Account_ID != '')
        and (Reseller_Company_Name is null or Reseller_Company_Name = '') then 'Not available'
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (opportunity_id is null or opportunity_id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) <> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_Company_Name
    end as Reseller_Company_Name,
    case
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (Opportunity_Id is null or Opportunity_Id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) <> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_AWS_Account_ID
    end as Reseller_AWS_Account_ID,

    -----------------------
    -- Payer Information --
    -----------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Payer_Company_Name = '' then null else Payer_Company_Name end,
      'Not available') as Payer_Company_Name,
    Payer_AWS_Account_ID,
    Payer_Encrypted_Account_ID,
    Payer_Email_Domain,
    Payer_City,
    Payer_State as Payer_State_or_Region,
    Payer_Country,
    Payer_Postal_Code,
    Payer_Address_ID,

    ---------------------
    -- ISV Information --
    ---------------------
    manufacturer_aws_account_id as ISV_Account_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Manufacturer_Company_Name = '' then null else Manufacturer_Company_Name end,
      'Not available') as ISV_Company_Name,

    ---------------------
    -- Products info --
    ---------------------
    Legacy_Product_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_ID = '' then null else Product_ID end,
      'Not provided') as Product_ID,
    Product_Code
  from
    line_items_with_window_functions_enrich_offer_product_address_name as line
  where disbursement_id_or_invoiced = '<invoiced>'

)

select *
from billed_revenue
where invoice_date >= date_add('DAY', -90, current_date)
--where invoice_date between cast('2023-01-01' as timestamp) and cast('2024-03-01' as timestamp)
```

## 未払い請求書または支払い済み請求書
<a name="data-feed-example-collections"></a>

未払い請求書または支払い済み請求書を検索するには、次の例のような一連のクエリを実行できます。クエリは相互に構築され、**集金と支払い**レポートを作成します。図のように例を使用するか、データやユースケースに合わせてカスタマイズできます。

クエリのコメントは、クエリの動作と変更方法について説明しています。

```
-- Collections and disbursements report

-- General note: When running this query, we assume that the data ingested in the database uses
-- two time axes (the valid_from column and the update_date column).
-- See documentation for more details: https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed.html#data-feed-details

-- An account_id has several valid_from dates (each representing a separate revision of the data)
-- but because of bi-temporality, an account_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
with accounts_with_uni_temporal_data as (
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    from_iso8601_timestamp(valid_from) as valid_from,
    tax_registration_number
  from
    (
      select
        account_id,
        aws_account_id,
        encrypted_account_id,
        mailing_address_id,
        tax_address_id,
        tax_legal_name,
        valid_from,
        delete_date,
        tax_registration_number,
        row_number() over (partition by account_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
      from
        accountfeed_v1
    )
    where
      -- keep latest ...
      row_num = 1
      -- ... and remove the soft-deleted one.
      and (delete_date is null or delete_date = '')
  ),

accounts_with_history as (
  with accounts_with_history_with_extended_valid_from as (
    select
      account_id,
      -- sometimes, this columns gets imported as a "bigint" and loses heading 0s -> casting to a char and re-adding heading 0s (if need be)
      substring('000000000000'||cast(aws_account_id as varchar),-12) as aws_account_id,
      encrypted_account_id,
      mailing_address_id,
      tax_address_id,
      tax_legal_name,
      -- The start time of account valid_from is extended to '1970-01-01 00:00:00', because:
      -- ... in tax report transformations, some tax line items with invoice_date cannot
      -- ... fall into the default valid time range of the associated account
      case
        when lag(valid_from) over (partition by account_id order by valid_from asc) is null
          then cast('1970-01-01 00:00:00' as timestamp)
        else valid_from
      end as valid_from
    from accounts_with_uni_temporal_data
    )
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    valid_from,
    coalesce(
      lead(valid_from) over (partition by account_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to
  from
    accounts_with_history_with_extended_valid_from
),

-- An address_id has several valid_from dates (each representing a separate revision of the data)
-- but because of bi-temporality, an account_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
address_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    address_id,
    company_name,
    email_domain,
    country_code,
    state_or_region,
    city,
    postal_code,
    row_num
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      address_id,
      company_name,
      email_domain,
      country_code,
      state_or_region,
      city,
      postal_code,
      row_number() over (partition by address_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      addressfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- We are only interested in the most recent tuple (BTW: a given address is not supposed to change over time but when bugs ;-) so this query mainly does nothing)
address_with_latest_revision as (
  select
    valid_from,
    address_id,
    company_name,
    email_domain,
    country_code,
    state_or_region,
    city,
    postal_code,
    row_num_latest_revision
  from
  (
    select
      valid_from,
      address_id,
      company_name,
      email_domain,
      country_code,
      state_or_region,
      city,
      postal_code,
      row_number() over (partition by address_id order by valid_from desc) as row_num_latest_revision
    from
      address_with_uni_temporal_data
  )
  where
    row_num_latest_revision = 1
),

accounts_with_history_with_company_name as (
  select
    awh.account_id,
    awh.aws_account_id,
    awh.encrypted_account_id,
    awh.mailing_address_id,
    awh.tax_address_id,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when address.company_name = '' then null else address.company_name end,
      awh.tax_legal_name) as mailing_company_name,
    address.email_domain,
    awh.valid_from,
    -- For BYOL, the agreement might be accepted (using some external non-AWS system or manual process) days before
    -- that BYOL agreement is entered into AWS Marketplace by the buyer. Therefore, the buyer is permitted to manually
    -- enter a backdated acceptance date, which might predate the point in time when the account was created.
    -- To work around this, we need to adjust the valid_from of the account to be
    -- earlier than the earliest possible backdated BYOL agreement acceptance date.
    case
      when lag(awh.valid_from) over (partition by aws_account_id order by awh.valid_from asc) is null
      then date_add('Day', -212, awh.valid_from)
      -- 212 is the longest delay between acceptance_date of the agreement and the account start_Date
      else awh.valid_from
    end as valid_from_adjusted,
    awh.valid_to
  from accounts_with_history as awh
  left join address_with_latest_revision as address on
    awh.mailing_address_id = address.address_id and awh.mailing_address_id is not null
),

-- An agreement_id has several valid_from dates (each representing an agreement revision)
-- but because of bi-temporality, an agreement_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
agreements_with_uni_temporal_data as (
  select
    agreement_id,
    origin_offer_id,
    proposer_account_id,
    acceptor_account_id,
    agreement_revision,
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(start_date) as start_date,
    from_iso8601_timestamp(end_date) as end_date,
    from_iso8601_timestamp(acceptance_date) as acceptance_date,
    agreement_type,
    previous_agreement_id,
    agreement_intent
  from
  (
    select
      --empty value in Athena shows as '', change all '' value to null
      case when agreement_id = '' then null else agreement_id end as agreement_id,
      origin_offer_id,
      proposer_account_id,
      acceptor_account_id,
      agreement_revision,
      valid_from,
      delete_date,
      start_date,
      end_date,
      acceptance_date,
      agreement_type,
      previous_agreement_id,
      agreement_intent,
      row_number() over (partition by agreement_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      -- TODO change to agreementfeed_v1 when Agreement Feed is GA'ed
      agreementfeed
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

agreements_with_history as (
  with agreements_with_window_functions as (
    select
      agreement_id,
      origin_offer_id as offer_id,
      proposer_account_id,
      acceptor_account_id,
      agreement_revision,
      start_date,
      end_date,
      acceptance_date,
      -- The start time of agreement valid_from is extended to '1970-01-01 00:00:00', because:
      -- ... in usage report transformations, some usage line items with usage_date cannot
      -- ... fall into the default valid time range of the associated agreement
      case
          when lag(valid_from) over (PARTITION BY agreement_id order by valid_from asc) is null
          then timestamp '1970-01-01 00:00:00'
          else valid_from
      end as valid_from,
      coalesce(
          lead(valid_from) over (partition by agreement_id order by valid_from asc),
          timestamp '2999-01-01 00:00:00'
      ) as valid_to,
      rank() over (partition by agreement_id order by valid_from asc) version,
      agreement_type,
      previous_agreement_id,
      agreement_intent
    from
      agreements_with_uni_temporal_data
  )
  select
    agreement_id,
    offer_id,
    proposer_account_id,
    acceptor_account_id,
    agreement_revision,
    start_date,
    end_date,
    acceptance_date,
    valid_from,
    case
        when version=1 and valid_from < timestamp '2023-03-03 06:16:08.743' then timestamp '1970-01-01'
        -- The following 60 minute adjustment is to handle special case where When Renewal happens for a contract
        when version=1 then date_add('minute',-60,valid_from)
        else valid_from
    end as valid_from_adjusted,
    valid_to,
    agreement_type,
    previous_agreement_id,
    agreement_intent
  from
    agreements_with_window_functions
),

-- An offer_id has several valid_from dates (each representing an offer revision)
-- but because of bi-temporality, an offer_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
offers_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    offer_id,
    offer_revision,
    name,
    expiration_date,
    opportunity_id,
    opportunity_name,
    opportunity_description,
    seller_account_id
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      offer_id,
      offer_revision,
      name,
      expiration_date,
      opportunity_id,
      opportunity_name,
      opportunity_description,
      seller_account_id,
      row_number() over (partition by offer_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      offerfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- Here, we build the validity time range (adding valid_to on top of valid_from) of each offer revision.
-- We will use it to get Offer name at invoice time.
-- NB: If you'd rather get "current" offer name, un-comment "offers_with_latest_revision"
offers_with_history as (
  select
    offer_id,
    offer_revision,
    name,
    opportunity_id,
    opportunity_name,
    opportunity_description,
    valid_from,
    -- When we try to look up an offer revision as at the acceptance date of a BYOL agreement, we run into a problem.
    -- For BYOL, the agreement might be accepted (using some external non-AWS system or manual process) days before
    -- that BYOL agreement is entered into AWS Marketplace by the buyer. Therefore, the buyer is permitted to manually
    -- enter a backdated acceptance date, which might predate the point in time when the first revision of the offer
    -- was created. To work around this, we need to adjust the valid_from on the first revision of the offer to be
    -- earlier than the earliest possible backdated BYOL agreement acceptance date.
    case
      when lag(valid_from) over (partition by offer_id order by valid_from asc) is null and valid_from < cast('2021-04-01' as timestamp)
      then date_add('Day', -3857, valid_from)
      -- 3857 is the longest delay between acceptance_date of an agreement and the first revision of the offer
      when lag(valid_from) over (partition by offer_id order by valid_from asc) is null and valid_from >= cast('2021-04-01' as timestamp)
      then date_add('Day', -1460, valid_from)
      --after 2021 for the two offers we need to adjust for 2 more years
      else valid_from
    end as valid_from_adjusted,
    coalesce(
      lead(valid_from) over (partition by offer_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp))
    as valid_to
  from offers_with_uni_temporal_data
),
-- provided for reference only if you are interested into get "current" offer name
-- (ie. not used afterwards)
offers_with_latest_revision as (
  select
    offer_id,
    offer_revision,
    name,
    opportunity_name,
    opportunity_description,
    valid_from,
    null valid_to
  from
  (
    select
      offer_id,
      offer_revision,
      name,
      opportunity_name,
      opportunity_description,
      valid_from,
      null valid_to,
      row_number() over (partition by offer_id order by valid_from desc) as row_num_latest_revision
    from
      offers_with_uni_temporal_data
  )
  where
    row_num_latest_revision = 1
),

-- An offer_target_id has several valid_from dates (each representing an offer revision)
-- but because of bi-temporality, an offer_target_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
offer_targets_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    offer_target_id,
    offer_id,
    offer_revision,
    target_type,
    polarity,
    value
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      offer_target_id,
      offer_id,
      offer_revision,
      target_type,
      polarity,
      value,
      row_number() over (partition by offer_target_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      offertargetfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

offer_target_type as (
  select
    offer_id,
    offer_revision,
    substring(
      -- The first character indicates the priority (lower value means higher precedence):
      min(
        case
          when offer_target.target_type='BuyerAccounts' then '1Private'
          when offer_target.target_type='ParticipatingPrograms' then '2Program:'||cast(offer_target.value as varchar)
          when offer_target.target_type='CountryCodes' then '3GeoTargeted'
          -- well, there is no other case today, but rather be safe...
          else '4Other Targeting'
        end
      ),
      -- Remove the first character that was only used for th priority in the "min" aggregate function:
      2
    ) as offer_target
  from
    offer_targets_with_uni_temporal_data as offer_target
  group by
    offer_id,
    offer_revision
),

offers_with_history_with_target_type as (
  select
    offer.offer_id,
    offer.offer_revision,
    -- even though today it is not possible to combine several types of targeting in a single offer, let's ensure the query is still predictable if this gets possible in the future
    max(
      case
        when off_tgt.offer_target is null then 'Public'
        else off_tgt.offer_target
      end
    ) as offer_target,
    min(offer.name) as name,
    min(offer.opportunity_name) as opportunity_name,
    min(offer.opportunity_description) as opportunity_description,
    offer.valid_from,
    offer.valid_from_adjusted,
    offer.valid_to,
    offer.opportunity_id
  from
    offers_with_history as offer
  left join offer_target_type as off_tgt on
    offer.offer_id = off_tgt.offer_id
    and offer.offer_revision = off_tgt.offer_revision
  group by
    offer.offer_id,
    offer.offer_revision,
    offer.valid_from,
    offer.valid_from_adjusted,
    offer.valid_to,
    offer.opportunity_id
),

-- provided for reference only if you are interested into get "current" offer targets
-- (ie. not used afterwards)
offers_with_latest_revision_with_target_type as (
  select
    offer.offer_id,
    offer.offer_revision,
    -- even though today it is not possible to combine several types of targeting in a single offer, let's ensure the query is still predictable if this gets possible in the future
    max(
      distinct
      case
        when off_tgt.target_type is null then 'Public'
        when off_tgt.target_type='BuyerAccounts' then 'Private'
        when off_tgt.target_type='ParticipatingPrograms' then 'Program:'||cast(off_tgt.value as varchar)
        when off_tgt.target_type='CountryCodes' then 'GeoTargeted'
        -- well, there is no other case today, but rather be safe...
        else 'Other Targeting'
      end
    ) as offer_target,
    min(offer.name) as name,
    min(offer.opportunity_name) as opportunity_name,
    min(offer.opportunity_description) as opportunity_description,
    offer.valid_from,
    offer.valid_to
  from
    offers_with_latest_revision offer
    -- left joining because public offers don't have targets
    left join offer_targets_with_uni_temporal_data off_tgt on
      offer.offer_id=off_tgt.offer_id and offer.offer_revision=off_tgt.offer_revision
  group by
    offer.offer_id,
    offer.offer_revision,
    -- redundant with offer_revision, as each revision has a dedicated valid_from (but cleaner in the group by)
    offer.valid_from,
    offer.valid_to
),

-- A product_id has several valid_from dates (each representing a product revision),
-- but because of bi-temporality, each product_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
products_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    product_id,
    manufacturer_account_id,
    product_code,
    title
  from
  (
    select
      valid_from,
      update_date,
      delete_date,
      product_id,
      manufacturer_account_id,
      product_code,
      title,
      row_number() over (partition by product_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      productfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

products_with_history as (
  select
    product_id,
    title,
    valid_from,
    -- Offerv2 can have upto 50 years and Offerv3 is upto 5 years of past date
    case
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from < cast('2021-04-01' as timestamp)
        then date_add('Day', -3857, valid_from)
      -- 3827 is the longest delay between acceptance_date of an agreement and the product
      -- we are keeping 3857 as a consistency between the offers and products
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from >= cast('2021-04-01' as timestamp)
        then date_add('Day', -2190, valid_from)
      --after 2021 for the two offers we need to adjust for 2 more years
      else valid_from 
    end as valid_from_adjusted,
    coalesce(
      lead(valid_from) over (partition by product_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to,
    product_code,
    manufacturer_account_id
  from
    products_with_uni_temporal_data
),

legacy_products as (
  select
    legacy_id,
    new_id
  from
    legacyidmappingfeed_v1
  where
    mapping_type='PRODUCT'
  group by
    legacy_id,
    new_id
),

-- A given billing_event_id represents an accounting event and thus has only one valid_from date,
-- but because of bi-temporality, a billing_event_id (+ its valid_from) can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
billing_events_with_uni_temporal_data as (
  select
    billing_event_id,
    valid_from,
    update_date,
    delete_date,
    invoice_date,
    transaction_type,
    transaction_reference_id,
    parent_billing_event_id,
    bank_trace_id,
    broker_id,
    product_id,
    disbursement_billing_event_id,
    action,
    from_account_id,
    to_account_id,
    end_user_account_id,
    billing_address_id,
    amount,
    currency,
    balance_impacting,
    --empty value in Athena shows as '', change all '' value to null
    case when agreement_id = '' then null else agreement_id end as agreement_id,
    invoice_id,
    payment_due_date,
    usage_period_start_date,
    usage_period_end_date,
    buyer_transaction_reference_id,
    row_num
  from
  (
    select
      billing_event_id,
      from_iso8601_timestamp(valid_from) as valid_from,
      from_iso8601_timestamp(update_date) as update_date,
      delete_date,
      from_iso8601_timestamp(invoice_date) as invoice_date,
      transaction_type,
      transaction_reference_id,
      parent_billing_event_id,
      -- casting in case data was imported as number
      cast(bank_trace_id as varchar) as bank_trace_id,
      broker_id,
      product_id,
      disbursement_billing_event_id,
      action,
      from_account_id,
      to_account_id,
      end_user_account_id,
      billing_address_id,
      -- casting in case data was imported as varchar
      cast(amount as decimal(38,6)) as amount,
      currency,
      balance_impacting,
      agreement_id,
      invoice_id,
      case when payment_due_date is null or payment_due_date = '' then null else from_iso8601_timestamp(payment_due_date) end as payment_due_date,
      from_iso8601_timestamp(usage_period_start_date) as usage_period_start_date,
      from_iso8601_timestamp(usage_period_end_date) as usage_period_end_date,
      buyer_transaction_reference_id,
      row_number() over (partition by billing_event_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
    from
      billingeventfeed_v1
  )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

-- Here we select the account_id of the current seller (We identify this by looking for the to_account_id related to revenue transactions).
-- We will use it later to distinguish own agreements from agreements generated by channel partners.
seller_account as (
  select
    from_account_id as seller_account_id
  from
    billing_events_with_uni_temporal_data bill
  where
    -- Assumption here is only seller will pay listing fee. As of 12/21/2021, there are cases that Channel partner have 0 listing fee for CPPO, so the amount could be 0.
    bill.transaction_type like 'AWS_REV_SHARE' and amount <= 0 and action = 'INVOICED'
  group by
    -- from_account_id is always the same for all those "listing fee" transactions == the seller of record himself.
    -- If this view returns more than 1 record, the overall query will fail (on purpose). Please contact AWS Marketplace if this happens.
    from_account_id
),

billing_event_with_business_flags as (
  select
    bl.billing_event_id,
    bl.end_user_account_id,
    bl.agreement_id,
    aggrement.proposer_account_id,
    aggrement.offer_id,
    aggrement.acceptor_account_id,
    case
      -- For AWS and BALANCE_ADJUSTMENT, the billing event feed will show the "AWS Marketplace" account as the
      -- receiver of the funds and the seller as the payer. We are not interested in this information here.
      -- Null values will be ignored by the `max` aggregation function.
      when bl.transaction_type like 'AWS%' then null
      -- For BALANCE_ADJUSTMENT, payer is seller themselves
      when bl.invoice_id is null then bl.to_account_id
      -- We get the payer of the invoice from *any* transaction type that is not AWS and not BALANCE_ADJUSTMENT (because they are the same for a given end user + agreement + product).
      else bl.from_account_id
    end as payer_account_id,
    bl.product_id,
    bl.action,
    bl.transaction_type,
    bl.parent_billing_event_id,
    bl.disbursement_billing_event_id,
    bl.amount,
    bl.currency,
    bl.balance_impacting,
    bl.invoice_date,
    bl.payment_due_date,
    bl.usage_period_start_date,
    bl.usage_period_end_date,
    bl.invoice_id,
    bl.billing_address_id,
    bl.transaction_reference_id,
    bl.buyer_transaction_reference_id,
    case when disbursement.bank_trace_id = 'EMEA_MP_TEST_TRACE_ID' then null else disbursement.bank_trace_id end as bank_trace_id,
    case when disbursement.bank_trace_id = 'EMEA_MP_TEST_TRACE_ID' then null else disbursement.invoice_date end as disbursement_date,
    disbursement.billing_event_id as disbursement_id,
    -- We will use disbursement_id_or_invoiced as part of the PK, so it cannot be null:
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when disbursement.billing_event_id = '' then null else disbursement.billing_event_id end,
      '<invoiced>') as disbursement_id_or_invoiced,
    bl.broker_id,
    case
      when bl.invoice_id is null /* transaction_type = 'BALANCE_ADJUSTMENT' */
        then (select seller_account_id from seller_account) ||':'|| cast(bl.invoice_date as varchar)
      else bl.buyer_transaction_reference_id
        ||'-'|| case when bl.agreement_id is null or bl.agreement_id = '' then ' ' else bl.agreement_id end
        ||'-'|| case when bl.end_user_account_id is null or bl.end_user_account_id = '' then ' ' else bl.end_user_account_id end
        ||'-'|| coalesce(cast(bl.usage_period_start_date as varchar),' ')
        ||'-'|| coalesce(cast(bl.usage_period_end_date as varchar),' ')
    end as internal_buyer_line_item_id,
    bl.buyer_transaction_reference_id <> bl.transaction_reference_id as is_seller_invoice,
    case when bl.transaction_type = 'SELLER_REV_SHARE' and (select seller_account_id from seller_account) <> bl.to_account_id then true else false end as is_cog,
    case when bl.transaction_type in('SELLER_REV_SHARE_CREDIT', 'SELLER_REV_SHARE_REFUND') and (select seller_account_id from seller_account) <> bl.to_account_id then true else false end as is_cog_refund,
    --TODO: replace below logic once we can create a logic the identify reseller/manufacturer without depending on agreement feed
    case when aggrement.proposer_account_id <> (select seller_account_id from seller_account) then true else false end as is_manufacturer_view_of_reseller
  from
    billing_events_with_uni_temporal_data as bl
    left join billing_events_with_uni_temporal_data as disbursement on
      disbursement.transaction_type like 'DISBURSEMENT%'
        and disbursement.action = 'DISBURSED'
        and disbursement.transaction_type IN ('DISBURSEMENT', 'DISBURSEMENT_FAILURE')
        and bl.disbursement_billing_event_id = disbursement.billing_event_id
    left join agreements_with_history as aggrement on
      bl.agreement_id = aggrement.agreement_id
        and bl.invoice_date >= aggrement.valid_from_adjusted
        and bl.invoice_date < aggrement.valid_to
    left join accounts_with_history awh on
      bl.to_account_id = awh.account_id
        and bl.invoice_date >= awh.valid_from
        and bl.invoice_date < awh.valid_to
  where
    bl.transaction_type not like 'DISBURSEMENT%' and
      (bl.agreement_id is null or bl.agreement_id = ''
      or aggrement.agreement_id is not null)
),

-- listagg function in athena does not support partitioning, grouping here and then joining to the main query
seller_invoice_list as (
  select
    internal_buyer_line_item_id,
    listagg(case when not is_seller_invoice then null else invoice_id end,',') within group (order by case when not is_seller_invoice then null else cast(invoice_date as varchar) end) as seller_invoice_id_or_null,
    listagg(case when not is_seller_invoice then null else cast(invoice_date as varchar) end,',') within group (order by case when not is_seller_invoice then null else cast(invoice_date as varchar) end) as seller_invoice_date_or_null
  from
    (
    -- listagg function in athena does not support ordering by another field when distinct is used,
    -- here we first select distinct invoices and then do the listagg order by invoice_date
    select distinct internal_buyer_line_item_id, is_seller_invoice, invoice_id, invoice_date
    from billing_event_with_business_flags) distinct_invoices
  group by internal_buyer_line_item_id
  order by internal_buyer_line_item_id
),

billing_event_with_categorized_transaction as (
-- Use the flags that were created in the previous transformation in more calculated columns:
-- NOTE: This transformation has no joins and no window functions
  select
    billing_event_id,
    end_user_account_id,
    agreement_id,
    proposer_account_id,
    offer_id,
    acceptor_account_id,
    case when is_cog or is_cog_refund then null else payer_account_id end as payer_account_id,
    product_id,
    action,
    transaction_type,
    parent_billing_event_id,
    disbursement_billing_event_id,
    amount,
    currency,
    balance_impacting,
    invoice_date,
    payment_due_date,
    usage_period_start_date,
    usage_period_end_date,
    invoice_id,
    billing_address_id,
    transaction_reference_id,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date,
    disbursement_id,
    disbursement_id_or_invoiced,
    broker_id,
    bl.internal_buyer_line_item_id,
    is_seller_invoice,
    is_cog,
    is_cog_refund,
    is_manufacturer_view_of_reseller,

    -- Buyer/seller columns:
    case when is_seller_invoice then null else invoice_id end as buyer_invoice_id_or_null,
    seller_invoices.seller_invoice_id_or_null,
    case when is_seller_invoice then null else invoice_date end as buyer_invoice_date_or_null,
    seller_invoices.seller_invoice_date_or_null,

    -- Categorized amounts by transaction type:
    case when transaction_type =   'SELLER_REV_SHARE' and not is_cog then amount else 0 end as gross_revenue,
    case when transaction_type in ('SELLER_REV_SHARE_REFUND','SELLER_REV_SHARE_CREDIT') and not is_cog_refund then amount else 0 end as gross_refund,
    case when transaction_type =   'SELLER_REV_SHARE' and     is_cog then amount else 0 end as cogs,
    case when transaction_type in ('SELLER_REV_SHARE_REFUND','SELLER_REV_SHARE_CREDIT') and     is_cog_refund then amount else 0 end as cogs_refund,
    case when transaction_type =   'AWS_REV_SHARE' then amount else 0 end as aws_rev_share,
    case when transaction_type in ('AWS_REV_SHARE_REFUND','AWS_REV_SHARE_CREDIT') then amount else 0 end as aws_refund_share,
    case when transaction_type =   'AWS_TAX_SHARE' and not is_seller_invoice then amount else 0 end as aws_tax_share,             -- AWS tax share from _buyer_  invoice
    case when transaction_type =   'AWS_TAX_SHARE' and     is_seller_invoice then amount else 0 end as aws_tax_share_listing_fee, -- AWS tax share from _seller_ invoice
    case when transaction_type =   'AWS_TAX_SHARE_REFUND' and not is_seller_invoice then amount else 0 end as aws_tax_share_refund,
    case when transaction_type =   'AWS_TAX_SHARE_REFUND' and     is_seller_invoice then amount else 0 end as aws_tax_share_refund_listing_fee,
    case when transaction_type =   'SELLER_TAX_SHARE' then amount else 0 end as seller_tax_share,
    case when transaction_type =   'SELLER_TAX_SHARE_REFUND' then amount else 0 end as seller_tax_share_refund,
    case when transaction_type =   'BALANCE_ADJUSTMENT' then amount else 0 end as balance_adjustment,
    case when transaction_type =   'SELLER_REV_SHARE_CREDIT' then amount else 0 end as seller_rev_credit,
    case when transaction_type =   'AWS_REV_SHARE_CREDIT' then amount else 0 end as aws_ref_fee_credit
  from
    billing_event_with_business_flags as bl
    left join seller_invoice_list as seller_invoices
      on bl.internal_buyer_line_item_id = seller_invoices.internal_buyer_line_item_id
    ),

line_items_aggregated as (
-- This transformation has the only "group by" in all of these transformations.
-- NOTE: This transformation has no joins and no window functions
  select
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    broker_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    max(payer_account_id) as payer_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    max(payment_due_date) payment_due_date,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date,
    max(billing_address_id) as billing_address_id,

    -- Buyer/seller columns:
    max(buyer_invoice_id_or_null) as buyer_invoice_id,
    max(seller_invoice_id_or_null) as seller_invoice_id,
    max(buyer_invoice_date_or_null) as buyer_invoice_date,
    max(seller_invoice_date_or_null) as seller_invoice_date,
  
    -- Categorized amounts by transaction type:
    -- When disbursement_id_or_invoiced = '<invoiced>',    these are invoiced amounts
    -- When disbursement_id_or_invoiced <> ''<invoiced>' these are disbursed amounts for _this_ specific disbursement_id
    sum(gross_revenue) as gross_revenue_this_disbursement_id_or_invoiced,
    sum(gross_refund) as gross_refund_this_disbursement_id_or_invoiced,
    sum(cogs) as cogs_this_disbursement_id_or_invoiced,
    sum(cogs_refund) as cogs_refund_this_disbursement_id_or_invoiced,
    sum(aws_rev_share) as aws_rev_share_this_disbursement_id_or_invoiced,
    sum(aws_refund_share) as aws_refund_share_this_disbursement_id_or_invoiced,
    sum(aws_tax_share) as aws_tax_share_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_listing_fee) as aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_refund) as aws_tax_share_refund_this_disbursement_id_or_invoiced,
    sum(aws_tax_share_refund_listing_fee) as aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    sum(seller_tax_share) as seller_tax_share_this_disbursement_id_or_invoiced,
    sum(seller_tax_share_refund) as seller_tax_share_refund_this_disbursement_id_or_invoiced,
    sum(balance_adjustment) as balance_adjustment_this_disbursement_id_or_invoiced,
    sum(seller_rev_credit) as seller_rev_credit_this_disbursement_id_or_invoiced,
    sum(aws_ref_fee_credit) as aws_ref_fee_credit_this_disbursement_id_or_invoiced
  from
    billing_event_with_categorized_transaction as billing_categorized
  group by
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    broker_id,
    -- The following columns are included the in group by but they are intentionally omitted from the PK.
    -- These columns should have the _same_ values for each record in the PK.
    product_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    buyer_transaction_reference_id,
    bank_trace_id,
    disbursement_date
),

-- listagg function in athena does not support partitioning, grouping here and then joining to the main query
disbursement_list as (
  select
    internal_buyer_line_item_id,
    listagg(cast(disbursement_date as varchar),',') within group (order by cast(disbursement_date as varchar)) as disbursement_date_list,
    listagg(bank_trace_id,',') within group (order by cast(disbursement_date as varchar)) as disburse_bank_trace_id_list
    from (
    -- listagg function in athena does not support ordering by another field when distinct is used,
    -- here we first select distinct bank_trace_ids and then do the listagg order by disbursement_date
    select distinct internal_buyer_line_item_id, disbursement_date, bank_trace_id
  from billing_event_with_business_flags) distinct_disbursements
  group by internal_buyer_line_item_id
  order by internal_buyer_line_item_id
),

line_items_with_window_functions as (
--add flag next step compare gross_revenue and gross_revenue_disbursed or gross_refund and gross_refund_disbursed
  select
    line_item.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    broker_id,
    currency,
    agreement_id,
    proposer_account_id,
    acceptor_account_id,
    -- when there's aws_rev_Share adjustment/refund to a seller_rev_share invoice, it can happen that for the same aws_rev_share invoice_id, there are multiple disbursement events,
    -- using windows function to map payer_account_id of seller_rev_share to all corresponding aws_rev_Share
    max(payer_account_id) over (partition by line_item.internal_buyer_line_item_id) as payer_account_id,
    offer_id,
    end_user_account_id,
    usage_period_start_date,
    usage_period_end_date,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,

    -- Buyer/seller columns:
    max(buyer_invoice_id) over (partition by line_item.internal_buyer_line_item_id) as buyer_invoice_id,
    seller_invoice_id,
    max(buyer_invoice_date) over (partition by line_item.internal_buyer_line_item_id) as buyer_invoice_date,
    seller_invoice_date,

    -- When disbursement_id_or_invoiced = ''<invoiced>', these are actually invoiced amounts
    -- When disbursement_id_or_invoiced <> ''<invoiced>' these are disbursed amounts for _this_ specific disbursement_id
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    -- IMPORTANT: All window functions partitioned by internal_buyer_line_item_id:

    -- Invoiced amounts, categorized by transaction type:
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then gross_revenue_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end)over (partition by line_item.internal_buyer_line_item_id) as gross_revenue_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then gross_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then cogs_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then cogs_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_rev_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_rev_share_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_refund_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_refund_share_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_tax_share_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_listing_fee_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_listing_fee_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then seller_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then seller_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_refund_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then balance_adjustment_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as balance_adjustment_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then seller_rev_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_rev_credit_invoiced,
    sum(case when disbursement_id_or_invoiced = ''<invoiced>' then aws_ref_fee_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_ref_fee_credit_invoiced,

    -- Total disbursed amounts (for all disbursement_id values), categorized by transaction type:
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then gross_revenue_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_revenue_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then gross_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as gross_refund_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then cogs_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then cogs_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as cogs_refund_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_rev_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_rev_share_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_refund_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_refund_share_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_tax_share_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_listing_fee_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_tax_share_refund_listing_fee_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then seller_tax_share_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then seller_tax_share_refund_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_tax_share_refund_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then balance_adjustment_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as balance_adjustment_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then seller_rev_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as seller_rev_credit_disbursed,
    sum(case when disbursement_id_or_invoiced '<> ''<invoiced>' then aws_ref_fee_credit_this_disbursement_id_or_invoiced else cast(0 as decimal(38,6)) end) over (partition by line_item.internal_buyer_line_item_id) as aws_ref_fee_credit_disbursed,

    -- aggregate multiple disbursement
    max(disbursement_date) over (partition by line_item.internal_buyer_line_item_id) as last_disbursement_date,
    first_value(case when disbursement_id_or_invoiced = ''<invoiced>' then null else disbursement_id_or_invoiced end) over(partition by line_item.internal_buyer_line_item_id order by coalesce(disbursement_date,cast('1900-01-01' as timestamp)) desc rows between unbounded preceding and unbounded following) as last_disbursement_id,
    first_value(bank_trace_id) over (partition by line_item.internal_buyer_line_item_id order by coalesce(disbursement_date,cast('1900-01-01' as timestamp)) desc rows between unbounded preceding and unbounded following) as last_disburse_bank_trace_id,
    disb_list.disbursement_date_list,
    disb_list.disburse_bank_trace_id_list
  from
    line_items_aggregated as line_item
    left join disbursement_list disb_list
      on line_item.internal_buyer_line_item_id = disb_list.internal_buyer_line_item_id
),

cppo_offer_id as (
  select
    -- Channel partner offers do not exist in offertargetfeed_v1 table (as per legal requirement), causing cppo offer be defined as 'Public' in previous step, we will convert them back to 'Private' in next step
    offer_id
  from
    offers_with_uni_temporal_data
  where
    -- seller_account_id is null means the ISV owns the offer
    seller_account_id is not null
    and seller_account_id '<>  (select seller_account_id from seller_account)
  group by
    offer_id
),

line_items_with_window_functions_enrich_offer_product_address as (
  select
    internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    line.product_id,
    legacy_product.legacy_id as legacy_product_id,
    products.title as product_title,
    line.broker_id,
    line.currency,
    line.end_user_account_id,
    acc_enduser.encrypted_account_id as end_user_encrypted_account_id,
    acc_enduser.aws_account_id as end_user_aws_account_id,
    acc_payer.aws_account_id as payer_aws_account_id,
    acc_payer.encrypted_account_id payer_encrypted_account_id,
    line.agreement_id,
    agreement.agreement_revision,
    line.proposer_account_id,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.start_date end as Agreement_Start_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.end_date end as Agreement_End_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.acceptance_date end as Agreement_Acceptance_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else agreement.valid_from end as agreement_updated_date,
    case when offer.offer_id like 'aiqoffer-%' then null else line.usage_period_start_date end as Usage_Period_Start_Date,
    case when offer.offer_id like 'aiqoffer-%' then null else line.usage_period_end_date end as Usage_Period_End_Date,

    line.acceptor_account_id,
    acc_subscriber.aws_account_id as subscriber_aws_account_id,
    acc_subscriber.encrypted_account_id as subscriber_encrypted_account_id,
    offer.offer_id,
    case
      when offer.offer_id in (
        select distinct offer_id
        from cppo_offer_id)
        then 'Private'
      else offer.offer_target
    end as offer_target,
    offer.name offer_name,
    offer.opportunity_name offer_opportunity_name,
    offer.opportunity_description offer_opportunity_description,
    offer.opportunity_id,
    payment_due_date,
    line.bank_trace_id,
    disbursement_date,
    billing_address_id,
    buyer_invoice_id,
    seller_invoice_id,
    buyer_invoice_date,
    seller_invoice_date,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    products.product_code,
    acc_products.aws_account_id as manufacturer_aws_account_id,
    products.manufacturer_account_id,
    --add subscriber and payer addressID, payer address preference order: tax address>billing address>mailing address,  subscriber address preference order: tax address> mailing address
    coalesce (
      --empty value in Athena shows as '', change all '' value to null in order to follow the preference order logic above
      case when acc_subscriber.tax_address_id ='' then null else acc_subscriber.tax_address_id end,
      case when acc_subscriber.mailing_address_id = '' then null else acc_subscriber.mailing_address_id end) as subscriber_address_id,
    coalesce (
      case when acc_payer.tax_address_id = '' then null else acc_payer.tax_address_id end,
      case when line.billing_address_id = '' then null else line.billing_address_id end,
      case when acc_payer.mailing_address_id = '' then null else acc_payer.mailing_address_id end) as payer_address_id,
    coalesce (
      case when acc_enduser.tax_address_id = '' then null else acc_enduser.tax_address_id end,
      case when line.billing_address_id = '' then null else line.billing_address_id end,
      case when acc_enduser.mailing_address_id = '' then null else acc_enduser.mailing_address_id end) as end_user_address_id
  from
    line_items_with_window_functions as line
  left join agreements_with_history as agreement on
      line.agreement_id = agreement.agreement_id and line.buyer_invoice_date >= agreement.valid_from_adjusted and line.buyer_invoice_date < agreement.valid_to
  left join offers_with_history_with_target_type as offer on
        line.offer_id = offer.offer_id and line.buyer_invoice_date >= offer.valid_from and line.buyer_invoice_date < offer.valid_to
  left join products_with_history as products on
        line.product_id = products.product_id and line.buyer_invoice_date >= products.valid_from_adjusted and line.buyer_invoice_date < products.valid_to
  left join legacy_products as legacy_product on
        line.product_id = legacy_product.new_id
  left join accounts_with_history_with_company_name as acc_payer on
        line.payer_account_id = acc_payer.account_id and line.buyer_invoice_date >= acc_payer.valid_from and line.buyer_invoice_date < acc_payer.valid_to
  left join accounts_with_history_with_company_name as acc_enduser on
        line.end_user_account_id = acc_enduser.account_id and line.buyer_invoice_date >= acc_enduser.valid_from and line.buyer_invoice_date < acc_enduser.valid_to
  left join accounts_with_history_with_company_name as acc_subscriber on
        line.acceptor_account_id = acc_subscriber.account_id and line.buyer_invoice_date >= acc_subscriber.valid_from and line.buyer_invoice_date < acc_subscriber.valid_to
  left join accounts_with_history_with_company_name as acc_products on
        products.manufacturer_account_id = acc_products.account_id and line.buyer_invoice_date >= acc_products.valid_from and line.buyer_invoice_date < acc_products.valid_to

),

line_items_with_window_functions_enrich_offer_product_address_name as (
  select
    line.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    legacy_product_id,
    product_title,
    broker_id,
    currency,
    end_user_address_id,
    end_user_account_id,
    end_user_encrypted_account_id,
    end_user_aws_account_id,
    add_enduser.company_name end_user_company_name,
    add_enduser.email_domain end_user_email_domain,
    add_enduser.city end_user_city,
    add_enduser.state_or_region end_user_state,
    add_enduser.country_code end_user_country,
    add_enduser.postal_code end_user_postal_code,
    payer_aws_account_id,
    payer_encrypted_account_id,
    payer_address_id,
    add_payer.company_name payer_company_name,
    add_payer.email_domain payer_email_domain,
    add_payer.city payer_city,
    add_payer.state_or_region payer_state,
    add_payer.country_code payer_country,
    add_payer.postal_code payer_postal_code,
    agreement_id,
    agreement_revision,
    agreement_start_date,
    agreement_end_date,
    agreement_acceptance_date,
    agreement_updated_date,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.aws_account_id end as reseller_aws_account_id,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.mailing_company_name end as reseller_company_name,
    usage_period_start_date,
    usage_period_end_date,
    proposer_account_id,
    acc_proposer.aws_account_id as proposer_aws_account_id,
    acceptor_account_id,
    subscriber_aws_account_id,
    subscriber_encrypted_account_id,
    subscriber_address_id,
    add_subscriber.company_name subscriber_company_name,
    add_subscriber.email_domain subscriber_email_domain,
    add_subscriber.city subscriber_city,
    add_subscriber.state_or_region subscriber_state,
    add_subscriber.country_code subscriber_country,
    add_subscriber.postal_code subscriber_postal_code,
    offer_id,
    offer_target,
    offer_name,
    offer_opportunity_name,
    offer_opportunity_description,
    opportunity_id,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,
    max(buyer_invoice_id)as buyer_invoice_id,
    max(seller_invoice_id)as seller_invoice_id,
    max(buyer_invoice_date)as buyer_invoice_date,
    max(seller_invoice_date)as seller_invoice_date,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    (gross_revenue_this_disbursement_id_or_invoiced + gross_refund_this_disbursement_id_or_invoiced + aws_rev_share_this_disbursement_id_or_invoiced + aws_refund_share_this_disbursement_id_or_invoiced + seller_tax_share_this_disbursement_id_or_invoiced + seller_tax_share_refund_this_disbursement_id_or_invoiced
      + cogs_this_disbursement_id_or_invoiced + cogs_refund_this_disbursement_id_or_invoiced + aws_tax_share_listing_fee_this_disbursement_id_or_invoiced + aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced) as seller_net_revenue_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    (gross_revenue_invoiced + gross_revenue_disbursed) as uncollected_gross_revenue,
    -- net revenue = gross revenue - listing fee - tax - cogs
    (gross_revenue_invoiced + gross_refund_invoiced + aws_rev_share_invoiced + aws_refund_share_invoiced + seller_tax_share_invoiced + seller_tax_share_refund_invoiced + cogs_invoiced + cogs_refund_invoiced + aws_tax_share_listing_fee_invoiced + aws_tax_share_refund_listing_fee_invoiced) as seller_net_revenue,
    (gross_revenue_invoiced + gross_refund_invoiced + aws_rev_share_invoiced + aws_refund_share_invoiced + seller_tax_share_invoiced + seller_tax_share_refund_invoiced + cogs_invoiced + cogs_refund_invoiced + aws_tax_share_listing_fee_invoiced + aws_tax_share_refund_listing_fee_invoiced
      + gross_revenue_disbursed + gross_refund_disbursed + aws_rev_share_disbursed + aws_refund_share_disbursed + seller_tax_share_disbursed + seller_tax_share_refund_disbursed + cogs_disbursed + cogs_refund_disbursed + aws_tax_share_listing_fee_disbursed + aws_tax_share_refund_listing_fee_disbursed) as uncollected_seller_net_revenue,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    product_code,
    manufacturer_aws_account_id,
    manufacturer_account_id,
    acc_manu.mailing_company_name as manufacturer_company_name,
    cast(null as varchar) as AR_Period,
    case
      when (
        (gross_revenue_invoiced '<>0 and gross_revenue_invoiced = -1 * gross_revenue_disbursed)
        or (gross_refund_invoiced '<> 0 and gross_refund_invoiced = -1 * gross_refund_disbursed)
        or (balance_adjustment_invoiced '<> 0 and balance_adjustment_invoiced = -1 * balance_adjustment_disbursed)
        or (seller_tax_share_refund_invoiced '<> 0 and seller_tax_share_refund_invoiced = -1 * seller_tax_share_refund_disbursed)
        or (gross_revenue_invoiced = 0 and gross_refund_invoiced = 0 and balance_adjustment_invoiced = 0 and seller_tax_share_refund_invoiced = 0 and last_disbursement_id is not null)) then 'Yes'
      when gross_revenue_disbursed = 0 and gross_refund_disbursed = 0 and balance_adjustment_disbursed = 0 and seller_tax_share_disbursed = 0 and seller_tax_share_refund_disbursed = 0 then 'No'
      else 'Partial'
    end as Disbursement_Flag
  from line_items_with_window_functions_enrich_offer_product_address as line
  left join accounts_with_history_with_company_name as acc_manu on
    line.manufacturer_account_id = acc_manu.account_id and line.buyer_invoice_date >= acc_manu.valid_from_adjusted and line.buyer_invoice_date <= acc_manu.valid_to
  left join accounts_with_history_with_company_name as acc_proposer on
    line.proposer_account_id = acc_proposer.account_id and line.buyer_invoice_date >= acc_proposer.valid_from and line.buyer_invoice_date < acc_proposer.valid_to
  left join address_with_latest_revision as add_payer on
    line.payer_address_id = add_payer.address_id
  left join address_with_latest_revision as add_subscriber on
    line.subscriber_address_id = add_subscriber.address_id
  left join address_with_latest_revision as add_enduser on
    line.end_user_address_id = add_enduser.address_id
  group by
    line.internal_buyer_line_item_id,
    disbursement_id,
    disbursement_id_or_invoiced,
    product_id,
    legacy_product_id,
    product_title,
    broker_id,
    currency,
    end_user_address_id,
    end_user_account_id,
    end_user_encrypted_account_id,
    end_user_aws_account_id,
    add_enduser.company_name,
    add_enduser.email_domain,
    add_enduser.city,
    add_enduser.state_or_region,
    add_enduser.country_code,
    add_enduser.postal_code,
    payer_aws_account_id,
    payer_encrypted_account_id,
    payer_address_id,
    add_payer.company_name,
    add_payer.email_domain,
    add_payer.city,
    add_payer.state_or_region,
    add_payer.country_code,
    add_payer.postal_code,
    agreement_id,
    agreement_revision,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.aws_account_id end,
    case when proposer_account_id = (select seller_account_id from seller_account) then null else acc_proposer.mailing_company_name end,
    agreement_start_date,
    agreement_end_date,
    agreement_acceptance_date,
    agreement_updated_date,
    usage_period_start_date,
    usage_period_end_date,
    acceptor_account_id,
    subscriber_aws_account_id,
    subscriber_encrypted_account_id,
    subscriber_address_id,
    add_subscriber.company_name,
    add_subscriber.email_domain,
    add_subscriber.city,
    add_subscriber.state_or_region,
    add_subscriber.country_code,
    add_subscriber.postal_code,
    offer_id,
    offer_target,
    offer_name,
    offer_opportunity_name,
    offer_opportunity_description,
    opportunity_id,
    payment_due_date,
    bank_trace_id,
    disbursement_date,
    billing_address_id,
    gross_revenue_this_disbursement_id_or_invoiced,
    gross_refund_this_disbursement_id_or_invoiced,
    cogs_this_disbursement_id_or_invoiced,
    cogs_refund_this_disbursement_id_or_invoiced,
    aws_rev_share_this_disbursement_id_or_invoiced,
    aws_refund_share_this_disbursement_id_or_invoiced,
    aws_tax_share_this_disbursement_id_or_invoiced,
    aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_this_disbursement_id_or_invoiced,
    aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,
    seller_tax_share_this_disbursement_id_or_invoiced,
    seller_tax_share_refund_this_disbursement_id_or_invoiced,
    balance_adjustment_this_disbursement_id_or_invoiced,
    seller_rev_credit_this_disbursement_id_or_invoiced,
    aws_ref_fee_credit_this_disbursement_id_or_invoiced,
    gross_revenue_invoiced,
    gross_refund_invoiced,
    cogs_invoiced,
    cogs_refund_invoiced,
    aws_rev_share_invoiced,
    aws_refund_share_invoiced,
    aws_tax_share_invoiced,
    aws_tax_share_listing_fee_invoiced,
    aws_tax_share_refund_invoiced,
    aws_tax_share_refund_listing_fee_invoiced,
    seller_tax_share_invoiced,
    seller_tax_share_refund_invoiced,
    balance_adjustment_invoiced,
    seller_rev_credit_invoiced,
    aws_ref_fee_credit_invoiced,
    gross_revenue_disbursed,
    gross_refund_disbursed,
    cogs_disbursed,
    cogs_refund_disbursed,
    aws_rev_share_disbursed,
    aws_refund_share_disbursed,
    aws_tax_share_disbursed,
    aws_tax_share_listing_fee_disbursed,
    aws_tax_share_refund_disbursed,
    aws_tax_share_refund_listing_fee_disbursed,
    seller_tax_share_disbursed,
    seller_tax_share_refund_disbursed,
    balance_adjustment_disbursed,
    seller_rev_credit_disbursed,
    aws_ref_fee_credit_disbursed,
    last_disbursement_date,
    last_disbursement_id,
    last_disburse_bank_trace_id,
    disbursement_date_list,
    disburse_bank_trace_id_list,
    product_code,
    manufacturer_aws_account_id,
    manufacturer_account_id,
    acc_manu.mailing_company_name,
    proposer_account_id,
    acc_proposer.aws_account_id
),
invoiced_not_disbursed as(
  select
    --we will filter on rownum =1 in next step,
    -- means internal_buyer_line_item_id, there's only '<invoiced> record, no disbursement_id linked
    *,
    max(case when disbursement_id_or_invoiced = ''<invoiced>' then 1 else 2 end)
      over (partition by internal_buyer_line_item_id) rownum
  from line_items_with_window_functions_enrich_offer_product_address_name as line_items

),
collections_and_disbursements as (
  select
    ------------------
    -- Invoice Info --
    ------------------
    buyer_invoice_date as Invoice_Date,
    Payment_Due_Date as Payment_Due_Date,
    concat(
      'Net ',
      case
        when abs(date_diff('Day', Payment_due_date, buyer_invoice_date))>180 then '180+'
        else cast(abs(date_diff('Day', Payment_due_date, buyer_invoice_date)) as varchar)
        end,
      ' days'
    ) as payment_terms,
    buyer_invoice_id as Invoice_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when seller_invoice_id = '' then null else seller_invoice_id end,
      'Not applicable') as Listing_Fee_Invoice_ID,

    ---------------------------
    --End user Information --
    ---------------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when End_User_Company_Name = '' then null else End_User_Company_Name end,
      'Not available') as End_User_Company_Name,
    End_User_AWS_Account_ID,
    End_User_Encrypted_Account_ID,
    End_User_Email_Domain,
    End_User_City,
    End_User_State as End_User_State_or_Region,
    End_User_Country,
    End_User_Postal_Code,
    End_User_Address_ID,

    ---------------------------
    --Subscriber Information --
    ---------------------------
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Company_Name is null or Subscriber_Company_Name = '' then 'Not provided'
      else Subscriber_Company_Name
    end as Subscriber_Company_Name,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_AWS_Account_ID
    end as Subscriber_AWS_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_Encrypted_Account_ID
    end as Subscriber_Encrypted_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Email_Domain is null or Subscriber_Email_Domain = '' then 'Not provided'
      else Subscriber_Email_Domain
    end as Subscriber_Email_Domain,
    case
      when Agreement_id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_City is null or Subscriber_City = '' then 'Not provided'
      else Subscriber_City
    end as Subscriber_City,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_State is null or Subscriber_State = '' then 'Not provided'
      else Subscriber_State
    end as Subscriber_State_or_Region,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Country is null or Subscriber_Country = '' then 'Not provided'
      else Subscriber_Country
    end as Subscriber_Country,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Postal_Code is null or Subscriber_Postal_Code = '' then 'Not provided'
      else Subscriber_Postal_Code
    end as Subscriber_Postal_Code,
    case
      when Agreement_ID is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Address_ID is null or Subscriber_Address_ID = '' then 'Not provided'
      else Subscriber_Address_ID
    end as Subscriber_Address_ID,

    ----------------------
    -- Procurement Info --
    ----------------------
    -- product title at time of invoice. It is possible that the title changes over time and therefore there may be multiple product titles mapped to a single product id.
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_Title = '' then null else Product_Title end,
      'Not provided') as Product_Title,
    -- offer name at time of invoice. It is possible that the name changes over time therefore there may be multiple offer names mapped to a single offer id.
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when (Offer_Name is null or Offer_Name = '') and Offer_Target = 'Public' then 'Not applicable'
      else Offer_Name
    end as Offer_Name,
    case
      when Agreement_Id is null or Agreement_ID = ''
      then 'Not available'
      else Offer_ID
    end as Offer_ID,
    -- offer visibility at time of invoice.,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Offer_Target
    end as Offer_Visibility,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Agreement_ID = '' then null else Agreement_ID end,
      'Not available') as Agreement_ID,
    Agreement_Start_Date,
    Agreement_Acceptance_Date,
    Agreement_End_Date,

    Usage_Period_Start_Date,
    Usage_Period_End_Date,

    -----------------------
    -- Disbursement Info --
    -----------------------
    case
      when Disbursement_Flag = 'Yes' then 'Disbursed'
      when Disbursement_Flag = 'No' then 'Not Disbursed'
      else 'Other'
    end as Disbursement_Status,
    last_disbursement_date as disbursement_date,
    case
      when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date))
      else null
    end as Disbursement_Time,
    case
      when Disbursement_Flag = 'No' then 'Not applicable'
      when bank_trace_id is null or bank_trace_id = '' then 'Not available'
      else bank_trace_id
    end as disburse_bank_trace_id,

    --------------
    -- Revenues --
    --------------
    -- We are rounding the sums using 2 decimal precision
    -- Note that the rounding method might differ between SQL implementations.
    -- The monthly revenue report is using RoundingMode.HALF_UP. This might create tiny discrepancies between this SQL output
    -- and the legacy report
    round(-1 * gross_revenue_this_disbursement_id_or_invoiced,2) as Gross_Revenue,
    round(-1 * gross_refund_this_disbursement_id_or_invoiced,2) as Gross_Refund,
    round(-1 * aws_rev_share_this_disbursement_id_or_invoiced,2) as Listing_Fee,
    round(-1 * aws_refund_share_this_disbursement_id_or_invoiced,2) as Listing_Fee_Refund,
    truncate(
      case
        when gross_revenue_this_disbursement_id_or_invoiced != 0 then abs(aws_rev_share_this_disbursement_id_or_invoiced/gross_revenue_this_disbursement_id_or_invoiced)
        when gross_refund_this_disbursement_id_or_invoiced != 0 then abs(aws_refund_share_this_disbursement_id_or_invoiced/gross_refund_this_disbursement_id_or_invoiced)
        else 0
      end
      ,4) as Listing_Fee_Percentage,
    round(-1 * seller_tax_share_this_disbursement_id_or_invoiced,2) as Seller_Tax_Share,
    round(-1 * seller_tax_share_refund_this_disbursement_id_or_invoiced,2) as Seller_Tax_Share_Refund,
    round(-1 * aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,2) as AWS_Tax_Share_Listing_Fee,
    round(-1 * aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,2) as AWS_Tax_Share_Refund_Listing_Fee,
    round(-1 * cogs_this_disbursement_id_or_invoiced,2) as Wholesale_cost,
    round(-1 * cogs_refund_this_disbursement_id_or_invoiced,2) as Wholesale_cost_Refund,
    round(-1 * seller_net_revenue_this_disbursement_id_or_invoiced,2) as Seller_Net_Revenue,
    currency as Currency,

    substring(internal_buyer_line_item_id,1,strpos(internal_buyer_line_item_id,'-')-1) as Transaction_Reference_ID,
    broker_id as AWS_seller_of_record,

    -----------------
    -- Resale info --
    -----------------
    case
      when Opportunity_Id is null or Opportunity_Id = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Opportunity_Id
    end as Resale_authorization_ID,
    case
      when Offer_Opportunity_Name is null or Offer_Opportunity_Name = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Offer_Opportunity_Name
    end as Resale_authorization_name,
    case
      when Offer_Opportunity_Description is null or Offer_Opportunity_Description = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Offer_Opportunity_Description
    end as Resale_authorization_description,
    case
      when (Reseller_AWS_Account_ID is not null and Reseller_AWS_Account_ID != '')
        and (Reseller_Company_Name is null or Reseller_Company_Name = '') then 'Not available'
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (opportunity_id is null or opportunity_id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) '<> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_Company_Name
    end as Reseller_Company_Name,
    case
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (Opportunity_Id is null or Opportunity_Id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) '<> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_AWS_Account_ID
    end as Reseller_AWS_Account_ID,

    -----------------------
    -- Payer Information --
    -----------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Payer_Company_Name = '' then null else Payer_Company_Name end,
      'Not available') as Payer_Company_Name,
    Payer_AWS_Account_ID, -- "Customer AWS Account Number" in legacy report
    Payer_Encrypted_Account_ID,
    Payer_Email_Domain,
    Payer_City,
    Payer_State as Payer_State_or_Region,
    Payer_Country,
    Payer_Postal_Code,
    Payer_Address_ID,

    ---------------------
    -- ISV Information --
    ---------------------
    manufacturer_aws_account_id as ISV_Account_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Manufacturer_Company_Name = '' then null else Manufacturer_Company_Name end,
      'Not available') as ISV_Company_Name,

    ---------------------
    -- Products info --
    ---------------------
    Legacy_Product_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_ID = '' then null else Product_ID end,
      'Not provided') as Product_ID,
    -- this is to get the legacy product id https://sim.amazon.com/issues/MP-INSIGHTS-2561
    Product_Code,

    case when Disbursement_Flag = 'Yes' then round(-1 * seller_net_revenue_this_disbursement_id_or_invoiced,2) else 0 end as Disbursed_Net_Revenue,
    case when Disbursement_Flag = 'No' then round(-1 * seller_net_revenue_this_disbursement_id_or_invoiced,2) else 0 end as Undisbursed_Net_Revenue,
    case
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <= 0 then 'Not due'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=30 then '1-30 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=60 then '31-60 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=90 then '61-90 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=120 then '91-120 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end >=121 then '121+ days late'
      else null
    end as Disbursement_Period
  from
    line_items_with_window_functions_enrich_offer_product_address_name as line
  where disbursement_id_or_invoiced != ''<invoiced>'

  union

  select
    ------------------
    -- Invoice Info --
    ------------------
    buyer_invoice_date as Invoice_Date,
    Payment_Due_Date as Payment_Due_Date,
    concat(
      'Net ',
      case
        when abs(date_diff('Day', Payment_due_date, buyer_invoice_date)) >180 then '180+'
        else cast(abs(date_diff('Day', Payment_due_date, buyer_invoice_date)) as varchar)
      end,
      ' days'
    ) as payment_terms,
    buyer_invoice_id as Invoice_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when seller_invoice_id = '' then null else seller_invoice_id end,
      'Not applicable') as Listing_Fee_Invoice_ID,

    ---------------------------
    --End user Information --
    ---------------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when End_User_Company_Name = '' then null else End_User_Company_Name end,
      'Not available') as End_User_Company_Name,
    End_User_AWS_Account_ID,
    End_User_Encrypted_Account_ID,
    End_User_Email_Domain,
    End_User_City,
    End_User_State as End_User_State_or_Region,
    End_User_Country,
    End_User_Postal_Code,
    End_User_Address_ID,

    ---------------------------
    --Subscriber Information --
    ---------------------------
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Company_Name is null or Subscriber_Company_Name = '' then 'Not provided'
      else Subscriber_Company_Name
    end as Subscriber_Company_Name,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_AWS_Account_ID
    end as Subscriber_AWS_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Subscriber_Encrypted_Account_ID
    end as Subscriber_Encrypted_Account_ID,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Email_Domain is null or Subscriber_Email_Domain = '' then 'Not provided'
      else Subscriber_Email_Domain
    end as Subscriber_Email_Domain,
    case
      when Agreement_id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_City is null or Subscriber_City = '' then 'Not provided'
      else Subscriber_City
    end as Subscriber_City,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_State is null or Subscriber_State = '' then 'Not provided'
      else Subscriber_State
    end as Subscriber_State_or_Region,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Country is null or Subscriber_Country = '' then 'Not provided'
      else Subscriber_Country
    end as Subscriber_Country,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Postal_Code is null or Subscriber_Postal_Code = '' then 'Not provided'
      else Subscriber_Postal_Code
    end as Subscriber_Postal_Code,
    case
      when Agreement_ID is null or Agreement_ID = '' then 'Not available'
      when Subscriber_Address_ID is null or Subscriber_Address_ID = '' then 'Not provided'
      else Subscriber_Address_ID
    end as Subscriber_Address_ID,

    ----------------------
    -- Procurement Info --
    ----------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_Title = '' then null else Product_Title end,
      'Not provided') as Product_Title,
    -- offer name at time of invoice. It is possible that the name changes over time therefore there may be multiple offer names mapped to a single offer id.
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      when (Offer_Name is null or Offer_Name = '') and Offer_Target = 'Public' then 'Not applicable'
      else Offer_Name
    end as Offer_Name,
    case
      when Agreement_Id is null or Agreement_ID = ''
      then 'Not available'
      else Offer_ID
    end as Offer_ID,
    -- offer visibility at time of invoice.,
    case
      when Agreement_Id is null or Agreement_ID = '' then 'Not available'
      else Offer_Target
    end as Offer_Visibility,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Agreement_ID = '' then null else Agreement_ID end,
      'Not available') as Agreement_ID,
    --case when Agreement_Id is null or Agreement_Id = '' then cast(null as timestamp) else Agreement_Start_Date end as Agreement_Start_Date,
    --case when Agreement_Id is null or Agreement_Id = '' then cast(null as timestamp) else Agreement_End_Date end as Agreement_End_Date,
    --case when Agreement_Id is null or Agreement_Id = '' then cast(null as timestamp) else Agreement_Acceptance_Date end as Agreement_Acceptance_Date,
    Agreement_Start_Date,
    Agreement_Acceptance_Date,
    Agreement_End_Date,

    Usage_Period_Start_Date,
    Usage_Period_End_Date,

    -----------------------
    -- Disbursement Info --
    -----------------------
    case
      when Disbursement_Flag = 'Yes' then 'Disbursed'
      when Disbursement_Flag = 'No' then 'Not Disbursed'
      else 'Other'
    end as Disbursement_Status,
    last_disbursement_date as disbursement_date,
    case
      when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date))
      else null
    end as Disbursement_Time,
    case
      when Disbursement_Flag = 'No' then 'Not applicable'
      when bank_trace_id is null or bank_trace_id = '' then 'Not available'
      else bank_trace_id
    end as disburse_bank_trace_id,

    --------------
    -- Revenues --
    --------------
    -- We are rounding the sums using 2 decimal precision
    -- Note that the rounding method might differ between SQL implementations.
    -- The monthly revenue report is using RoundingMode.HALF_UP. This might create tiny discrepancies between this SQL output
    -- and the legacy report
    round(gross_revenue_this_disbursement_id_or_invoiced,2) as Gross_Revenue,
    round(gross_refund_this_disbursement_id_or_invoiced,2) as Gross_Refund,
    round(aws_rev_share_this_disbursement_id_or_invoiced,2) as Listing_Fee,
    round(aws_refund_share_this_disbursement_id_or_invoiced,2) as Listing_Fee_Refund,
    truncate(
      case
        when gross_revenue_this_disbursement_id_or_invoiced != 0 then abs(aws_rev_share_this_disbursement_id_or_invoiced/gross_revenue_this_disbursement_id_or_invoiced)
        when gross_refund_this_disbursement_id_or_invoiced != 0 then abs(aws_refund_share_this_disbursement_id_or_invoiced/gross_refund_this_disbursement_id_or_invoiced)
        else 0
      end
      ,4) as Listing_Fee_Percentage,
    round(seller_tax_share_this_disbursement_id_or_invoiced,2) as Seller_Tax_Share,
    round(seller_tax_share_refund_this_disbursement_id_or_invoiced,2) as Seller_Tax_Share_Refund,
    round(aws_tax_share_listing_fee_this_disbursement_id_or_invoiced,2) as AWS_Tax_Share_Listing_Fee,
    round(aws_tax_share_refund_listing_fee_this_disbursement_id_or_invoiced,2) as AWS_Tax_Share_Refund_Listing_Fee,
    round(cogs_this_disbursement_id_or_invoiced,2) as Wholesale_cost,
    round(cogs_refund_this_disbursement_id_or_invoiced,2) as Wholesale_cost_Refund,
    round(seller_net_revenue_this_disbursement_id_or_invoiced,2) as Seller_Net_Revenue,
    currency as Currency,

    substring(internal_buyer_line_item_id,1,strpos(internal_buyer_line_item_id,'-')-1) as Transaction_Reference_ID,
    broker_id as AWS_seller_of_record,

    -----------------
    -- Resale info --
    -----------------
    case
      when Opportunity_Id is null or Opportunity_Id = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Opportunity_Id
    end as Resale_authorization_ID,
    case
      when Offer_Opportunity_Name is null or Offer_Opportunity_Name = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Offer_Opportunity_Name
    end as Resale_authorization_name,
    case
      when Offer_Opportunity_Description is null or Offer_Opportunity_Description = '' then
        case
          when Offer_Target = 'Public' then 'Not applicable'
          when (Offer_Target is null or Offer_Target = '') and (Agreement_Id is not null and Agreement_Id != '') then 'Not applicable'
          else null
        end
      else Offer_Opportunity_Description
    end as Resale_authorization_description,
    case
      when (Reseller_AWS_Account_ID is not null and Reseller_AWS_Account_ID != '')
        and (Reseller_Company_Name is null or Reseller_Company_Name = '') then 'Not available'
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (opportunity_id is null or opportunity_id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) '<> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_Company_Name
    end as Reseller_Company_Name,
    case
      when (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '')
        and (Opportunity_Id is null or Opportunity_Id = '') then 'Not applicable'
      when (select seller_account_id from seller_account) '<> manufacturer_aws_account_id
        and (Reseller_AWS_Account_ID is null or Reseller_AWS_Account_ID = '') then 'Not applicable'
      else Reseller_AWS_Account_ID
    end as Reseller_AWS_Account_ID,

    -----------------------
    -- Payer Information --
    -----------------------
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Payer_Company_Name = '' then null else Payer_Company_Name end,
      'Not available') as Payer_Company_Name,
    Payer_AWS_Account_ID, -- "Customer AWS Account Number" in legacy report
    Payer_Encrypted_Account_ID,
    Payer_Email_Domain,
    Payer_City,
    Payer_State as Payer_State_or_Region,
    Payer_Country,
    Payer_Postal_Code,
    Payer_Address_ID,

    ---------------------
    -- ISV Information --
    ---------------------
    manufacturer_aws_account_id as ISV_Account_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Manufacturer_Company_Name = '' then null else Manufacturer_Company_Name end,
      'Not available') as ISV_Company_Name,

    ---------------------
    -- Products info --
    ---------------------
    -- product title at time of invoice. It is possible that the title changes over time and therefore there may be multiple product titles mapped to a single product id.
    Legacy_Product_ID,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when Product_ID = '' then null else Product_ID end,
      'Not provided') as Product_ID,
    -- this is to get the legacy product id https://sim.amazon.com/issues/MP-INSIGHTS-2561
    Product_Code,

    case when Disbursement_Flag = 'Yes' then round(seller_net_revenue_this_disbursement_id_or_invoiced,2) else 0 end as Disbursed_Net_Revenue,
    case when Disbursement_Flag = 'No' then round(seller_net_revenue_this_disbursement_id_or_invoiced,2) else 0 end as Undisbursed_Net_Revenue,
    case
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <= 0 then 'Not due'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=30 then '1-30 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=60 then '31-60 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=90 then '61-90 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end <=120 then '91-120 days late'
      when case when Disbursement_Flag = 'Yes' then date_diff('DAY', date_trunc('DAY',payment_due_date), date_trunc('DAY',last_disbursement_date)) else null end >=121 then '121+ days late'
      else null
    end as Disbursement_Period
  from
    invoiced_not_disbursed
  where rownum = 1

)

select *
from collections_and_disbursements
where payment_due_date >= date_add('DAY', -90, current_date)
--where payment_due_date between cast('2023-01-01' as timestamp) and cast('2024-12-31' as timestamp)

--where disbursement_date >= date_add('DAY', -90, current_date)
--where disbursement_date between cast('2023-01-01' as timestamp) and cast('2024-12-31' as timestamp)
```

## 課税請求書
<a name="data-feed-example-tax"></a>

課税請求書を検索するには、次の例のような一連のクエリを実行できます。クエリは相互に構築され、**課税**レポートを作成します。図のように例を使用するか、データやユースケースに合わせてカスタマイズできます。

クエリのコメントは、クエリの動作と変更方法について説明しています。

```
-- Taxation report

-- General note: When executing this query we are assuming that the data ingested in the database is using
-- two time axes (the valid_from column and the update_date column).
-- See documentation for more details: https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed.html#data-feed-details

-- An account_id has several valid_from dates (each representing a separate revision of the data)
-- but because of bi-temporality, an account_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
with accounts_with_uni_temporal_data as (
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    from_iso8601_timestamp(valid_from) as valid_from,
    tax_registration_number
  from
    (
      select
        account_id,
        aws_account_id,
        encrypted_account_id,
        mailing_address_id,
        tax_address_id,
        tax_legal_name,
        valid_from,
        delete_date,
        tax_registration_number,
        row_number() over (partition by account_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
      from
        accountfeed_v1
    )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

accounts_with_history as (
  with accounts_with_history_with_extended_valid_from as (
    select
      account_id,
      -- sometimes, this columns gets imported as a "bigint" and loses heading 0s -> casting to a char and re-adding heading 0s (if need be)
      substring('000000000000'||cast(aws_account_id as varchar),-12) as aws_account_id,
      encrypted_account_id,
      mailing_address_id,
      tax_address_id,
      tax_legal_name tax_legal_name,
      -- The start time of account valid_from is extended to '1970-01-01 00:00:00', because:
      -- ... in tax report transformations, some tax line items with invoice_date cannot
      -- ... fall into the default valid time range of the associated account
      CASE
        WHEN LAG(valid_from) OVER (PARTITION BY account_id ORDER BY valid_from ASC) IS NULL
            THEN CAST('1970-01-01 00:00:00' as timestamp)
        ELSE valid_from
      END AS valid_from
    from
      (select * from accounts_with_uni_temporal_data ) as account
  )
  select
    account_id,
    aws_account_id,
    encrypted_account_id,
    mailing_address_id,
    tax_address_id,
    tax_legal_name,
    valid_from,
    coalesce(
      lead(valid_from) over (partition by account_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to
  from
    accounts_with_history_with_extended_valid_from
),

-- A product_id has several valid_from dates (each representing a product revision),
-- but because of bi-temporality, each product_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
products_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    from_iso8601_timestamp(delete_date) as delete_date,
    product_id,
    manufacturer_account_id,
    product_code,
    title
  from
    (
      select
        valid_from,
        update_date,
        delete_date,
        product_id,
        manufacturer_account_id,
        product_code,
        title,
        row_number() over (partition by product_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
      from
       productfeed_v1
      )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

products_with_history as (
  select
    product_id,
    title,
    valid_from,    
    case
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from < cast('2021-04-01' as timestamp)
        then date_add('Day', -3857, valid_from)
      -- 3827 is the longest delay between acceptance_date of an agreement and the product
      -- we are keeping 3857 as a consistency between the offers and products
      when lag(valid_from) over (partition by product_id order by valid_from asc) is null and valid_from >= cast('2021-04-01' as timestamp)
        then date_add('Day', -2190, valid_from)
      --after 2021 for the two offers we need to adjust for 2 more years
      else valid_from end as valid_from_adjusted,
    coalesce(
      lead(valid_from) over (partition by product_id order by valid_from asc),
      cast('2999-01-01 00:00:00' as timestamp)
    ) as valid_to,
    product_code,
    manufacturer_account_id
  from
    products_with_uni_temporal_data
),

-- A tax_item_id has several valid_from dates (each representing a product revision),
-- but because of bi-temporality, each tax_item_id + valid_from tuple can appear multiple times with a different update_date.
-- We are only interested in the most recent tuple (ie, uni-temporal model)
tax_items_with_uni_temporal_data as (
  select
    from_iso8601_timestamp(valid_from) as valid_from,
    from_iso8601_timestamp(update_date) as update_date,
    delete_date,
    cast(tax_item_id as varchar) as tax_item_id,
    cast(invoice_id as varchar) as invoice_id,
    cast(line_item_id as varchar) as line_item_id,
    cast(customer_bill_id as varchar) as customer_bill_id,
    tax_liable_party,
    transaction_type_code,
    product_id,
    product_tax_code,
    from_iso8601_timestamp(invoice_date) as invoice_date,
    taxed_customer_account_id,
    taxed_customer_country,
    taxed_customer_state_or_region,
    taxed_customer_city,
    taxed_customer_postal_code,
    tax_location_code_taxed_jurisdiction,
    tax_type_code,
    jurisdiction_level,
    taxed_jurisdiction,
    display_price_taxability_type,
    tax_jurisdiction_rate,
    tax_amount,
    tax_currency,
    tax_calculation_reason_code,
    date_used_for_tax_calculation,
    customer_exemption_certificate_id,
    customer_exemption_certificate_id_domain,
    customer_exemption_certificate_level,
    customer_exemption_code,
    customer_exemption_domain,
    transaction_reference_id
  from
    (
      select
        valid_from,
        update_date,
        delete_date,
        tax_item_id,
        invoice_id,
        line_item_id,
        customer_bill_id,
        tax_liable_party,
        transaction_type_code,
        product_id,
        product_tax_code,
        invoice_date,
        taxed_customer_account_id,
        taxed_customer_country,
        taxed_customer_state_or_region,
        taxed_customer_city,
        taxed_customer_postal_code,
        tax_location_code_taxed_jurisdiction,
        tax_type_code,
        jurisdiction_level,
        taxed_jurisdiction,
        display_price_taxability_type,
        tax_jurisdiction_rate,
        tax_amount,
        tax_currency,
        tax_calculation_reason_code,
        date_used_for_tax_calculation,
        customer_exemption_certificate_id,
        customer_exemption_certificate_id_domain,
        customer_exemption_certificate_level,
        customer_exemption_code,
        customer_exemption_domain,
        transaction_reference_id,
        row_number() over (partition by tax_item_id, valid_from order by from_iso8601_timestamp(update_date) desc) as row_num
      from
        taxitemfeed_v1
    )
  where
    -- keep latest ...
    row_num = 1
    -- ... and remove the soft-deleted one.
    and (delete_date is null or delete_date = '')
),

taxation as (
  select
    tax_items.invoice_id,
    tax_items.line_item_id,
    tax_items.customer_bill_id,
    tax_items.tax_liable_party,
    tax_items.transaction_type_code,
    tax_items.product_id,
    product_tax_item.title as product_title,
    tax_items.product_tax_code,
    tax_items.invoice_date,
    accounts_with_history.aws_account_id as taxed_customer_account_id,
    tax_items.taxed_customer_country,
    tax_items.taxed_customer_state_or_region,
    tax_items.taxed_customer_city,
    tax_items.taxed_customer_postal_code,
    tax_items.tax_type_code as tax_type,
    tax_items.jurisdiction_level,
    tax_items.taxed_jurisdiction,
    tax_items.display_price_taxability_type,
    tax_items.tax_jurisdiction_rate,
    tax_items.tax_amount,
    tax_items.tax_currency,
    tax_items.tax_calculation_reason_code,
    tax_items.date_used_for_tax_calculation,
    coalesce(
      --empty value in Athena shows as '', change all '' value to null
      case when tax_items.customer_exemption_certificate_id = '' then null else tax_items.customer_exemption_certificate_id end,
      'Not exempt') customer_exemption_certificate_id,
    coalesce(--empty value in Athena shows as '', change all '' value to null
      case when tax_items.customer_exemption_certificate_id_domain = '' then null else tax_items.customer_exemption_certificate_id_domain end,
      'Not exempt') customer_exemption_certificate_id_domain,
    coalesce(--empty value in Athena shows as '', change all '' value to null
      case when tax_items.customer_exemption_certificate_level = '' then null else tax_items.customer_exemption_certificate_level end,
      'Not exempt') customer_exemption_certificate_level,
    coalesce(--empty value in Athena shows as '', change all '' value to null
      case when tax_items.customer_exemption_code = '' then null else tax_items.customer_exemption_code end,
      'Not exempt') customer_exemption_code,
    tax_items.transaction_reference_id
  from
    tax_items_with_uni_temporal_data as tax_items
    left join products_with_history as product_tax_item on
      tax_items.product_id = product_tax_item.product_id and tax_items.invoice_date >= product_tax_item.valid_from_adjusted and tax_items.invoice_date < product_tax_item.valid_to
    left join accounts_with_history as accounts_with_history on
      tax_items.taxed_customer_account_id = accounts_with_history.account_id and tax_items.invoice_date >= accounts_with_history.valid_from and tax_items.invoice_date < accounts_with_history.valid_to

)

select *
from taxation
where invoice_date >= date_add('DAY', -90, current_date)
--where invoice_date between cast('2023-01-01' as timestamp) and cast('2024-12-31' as timestamp)
```

## 製品別の支払い
<a name="data-feed-example-disbursement-by-product"></a>

製品別に支払われた金額を確認するには、次のようなクエリを実行できます。

これらのサンプルクエリは、相互に構築され、支払いを含む製品詳細の最終リストを作成します。特定の時点での製品情報を取得する方法も示します。このサンプルは、図のように使用したり、データやユースケースに合わせてカスタマイズしたりできます。

クエリのコメントは、クエリの動作と変更方法について説明しています。

**注記**  
このクエリを実行するときは、取り込まれたデータが 2 つの時間軸 (`valid_from` 列と `update` 列) を使用していることを前提としています。詳細については、「[AWS Marketplace データフィードのストレージと構造](data-feed-details.md)」を参照してください。

```
    -- Get all the products and keep the latest product_id, valid_from tuple
    with products_with_uni_temporal_data as (
      select
       *
      from
      (
        select
         *,
         ROW_NUMBER() OVER (PARTITION BY product_id, valid_from 
             ORDER BY from_iso8601_timestamp(update_date) desc) 
             as row_num
        from
         productfeed_v1
      )
      where
        -- A product_id can appear multiple times with the same 
        -- valid_from date but with a different update_date column,
        -- making it effectively bi-temporal. By only taking the most
        -- recent tuple, we are converting to a uni-temporal model.
        row_num = 1
    ),

    -- Gets the latest revision of a product
    -- A product can have multiple revisions where some of the 
    -- columns, like the title, can change.
    -- For the purpose of the disbursement report, we want 
    -- to get the latest revision of a product
    products_with_latest_version as (
     select
      *
     from
     (
      select
       *,
       ROW_NUMBER() OVER (PARTITION BY product_id 
           ORDER BY from_iso8601_timestamp(valid_from) desc) 
           as row_num_latest_version
      from
       products_with_uni_temporal_data
     )
     where
      row_num_latest_version = 1
   ),

    -- Get all the accounts and keep the latest account_id, valid_from tuple
    accounts_with_uni_temporal_data as (
      select
       *
      from
      (
        select
         *,
         ROW_NUMBER() OVER (PARTITION BY account_id, valid_from ORDER BY from_iso8601_timestamp(update_date) desc) as row_num
        from
         accountfeed_v1
      )
      where
        -- An account_id can appear multiple times with the same 
        -- valid_from date but with a different update_date column,
        -- making it effectively bi-temporal. By only taking the most
        -- recent tuple, we are converting to a uni-temporal model.
        row_num = 1
    ),

    -- Gets the latest revision of an account
    -- An account can have multiple revisions where some of the 
    -- columns, like the mailing_address_id, can change.
    -- For the purpose of the disbursement report, we want 
    -- to get the latest revision of a product
    accounts_with_latest_version as (
     select
      *
     from
     (
      select
       *,
       ROW_NUMBER() OVER (PARTITION BY account_id 
           ORDER BY from_iso8601_timestamp(valid_from) desc) 
           as row_num_latest_version
      from
       accounts_with_uni_temporal_data
     )
     where
      row_num_latest_version = 1
   ),

    -- Get all the billing events and keep the 
    -- latest billing_event_id, valid_from tuple:
    billing_events_with_uni_temporal_data as (
      select
       *
      from (
        select
          billing_event_id,
          from_iso8601_timestamp(valid_from) as valid_from,
          from_iso8601_timestamp(update_date) as update_date,
          from_iso8601_timestamp(invoice_date) as invoice_date,
          transaction_type,
          transaction_reference_id,
          product_id,
          disbursement_billing_event_id,
          action,
          from_account_id,
          to_account_id,
          end_user_account_id,
          CAST(amount as decimal(20, 10)) invoice_amount,
          bank_trace_id,
          ROW_NUMBER() OVER (PARTITION BY billing_event_id, valid_from 
              ORDER BY from_iso8601_timestamp(update_date) desc) 
              as row_num
        from
          billingeventfeed_v1
        )
      where row_num = 1
    ),

    -- Get all the disbursements
    -- The billing events data is immutable.
    -- It is not required to use time windows based on the 
    -- valid_from column to get the most recent billing event
    disbursement_events as (
      select
        billing_events_raw.billing_event_id as disbursement_id,
        billing_events_raw.invoice_date as disbursement_date,
        billing_events_raw.bank_trace_id
      from
        billing_events_with_uni_temporal_data billing_events_raw
      where
        -- Only interested in disbursements, so filter out
        -- non-disbursements by selecting transaction type 
        -- to be DISBURSEMENT:
        billing_events_raw.transaction_type = 'DISBURSEMENT'
        -- Select a time period, you can adjust the dates 
        -- below if need be. For billing events use the 
        -- invoice date as the point in time of the 
        -- disbursement being initiated:
        and billing_events_raw.invoice_date >= 
            from_iso8601_timestamp('2020-10-01T00:00:00Z')
        and billing_events_raw.invoice_date < 
            from_iso8601_timestamp('2020-11-01T00:00:00Z')
    ),

    -- Get the invoices along with the line items that 
    -- are part of the above filtered disbursements
    disbursed_line_items as (
      select
        line_items.transaction_reference_id,
        line_items.product_id,
        line_items.transaction_type,
        (case
           -- Get the payer of the invoice from any 
           -- transaction type that is not AWS and 
           -- not BALANCE_ADJUSTMENT.
           -- For AWS and BALANCE_ADJUSTMENT, the billing 
           -- event feed will show the "AWS Marketplace" 
           -- account as the receiver of the funds and the 
           -- seller as the payer. Filter those out.
           when line_items.transaction_type 
               not like '%AWS%' and transaction_type 
               not like 'BALANCE_ADJUSTMENT' 
               then line_items.from_account_id
        end) as payer_account_id,
        line_items.end_user_account_id,
        invoice_amount,
        disbursements.disbursement_date,
        disbursements.disbursement_id,
        disbursements.bank_trace_id
      from
        billing_events_with_uni_temporal_data line_items
        -- Each disbursed line item is linked to the parent 
        -- disbursement via the disbursement_billing_event_id
        join disbursement_events disbursements 
          on disbursements.disbursement_id 
          = line_items.disbursement_billing_event_id
      where
        -- we are interested only in the invoice line 
        -- items that are DISBURSED
        line_items.action = 'DISBURSED'
    ),

  -- An invoice can contain multiple line items
  -- Create a pivot table to calculate the different 
  -- amounts that are part of an invoice.
  -- The new row is aggregated at 
  -- transaction_reference_id - end_user_account_id level
  invoice_amounts_aggregated as (
    select
      transaction_reference_id,
      product_id,
      -- a given disbursement id should have the 
      -- same disbursement_date
      max(disbursement_date) as disbursement_date,
      -- Build a pivot table in order to provide all the
      -- data related to a transaction in a single row.
      -- Note that the amounts are negated. This is because 
      -- when an invoice is generated, we give you the 
      -- positive amounts and the disbursement event 
      -- negates the amounts
      sum(case when transaction_type = 'SELLER_REV_SHARE' 
          then -invoice_amount else 0 end) as seller_rev_share,
      sum(case when transaction_type = 'AWS_REV_SHARE'  
          then -invoice_amount else 0 end) as aws_rev_share,
      sum(case when transaction_type = 'SELLER_REV_SHARE_REFUND'  
          then -invoice_amount else 0 end) as seller_rev_refund,
      sum(case when transaction_type = 'AWS_REV_SHARE_REFUND'  
          then -invoice_amount else 0 end) as aws_rev_refund,
      sum(case when transaction_type = 'SELLER_REV_SHARE_CREDIT'  
          then -invoice_amount else 0 end) as seller_rev_credit,
      sum(case when transaction_type = 'AWS_REV_SHARE_CREDIT'  
          then -invoice_amount else 0 end) as aws_rev_credit,
      sum(case when transaction_type = 'SELLER_TAX_SHARE'  
          then -invoice_amount else 0 end) as seller_tax_share,
      sum(case when transaction_type = 'SELLER_TAX_SHARE_REFUND'  
          then -invoice_amount else 0 end) as seller_tax_refund,
      -- This is the account that pays the invoice:
      max(payer_account_id) as payer_account_id,
      -- This is the account that subscribed to the product:
      end_user_account_id as customer_account_id,
      bank_trace_id
    from
      disbursed_line_items
    group by
      transaction_reference_id,
      product_id,
      disbursement_id,
      -- There might be a different end-user for the same 
      -- transaction reference id. Distributed licenses 
      -- is an example
      end_user_account_id,
      bank_trace_id
),

disbursed_amount_by_product as (
  select
    products.title as ProductTitle,
    products.product_code as ProductCode,
    -- We are rounding the sums using 2 decimal precision
    -- Note that the rounding method might differ 
    -- between SQL implementations.
    -- The disbursement seller report is using 
    -- RoundingMode.HALF_UP. This might create 
    -- discrepancies between this SQL output
    -- and the disbursement seller report
    round(invoice_amounts.seller_rev_share, 2) as SellerRev,
    round(invoice_amounts.aws_rev_share, 2) as AWSRefFee,
    round(invoice_amounts.seller_rev_refund, 2) as SellerRevRefund,
    round(invoice_amounts.aws_rev_refund, 2) as AWSRefFeeRefund,
    round(invoice_amounts.seller_rev_credit, 2) as SellerRevCredit,
    round(invoice_amounts.aws_rev_credit, 2) as AWSRefFeeCredit,
    (
        round(invoice_amounts.seller_rev_share, 2) +
        round(invoice_amounts.aws_rev_share, 2) +
        round(invoice_amounts.seller_rev_refund, 2) +
        round(invoice_amounts.aws_rev_refund, 2) +
        round(invoice_amounts.seller_rev_credit, 2) +
        round(invoice_amounts.aws_rev_credit, 2)
    ) as NetAmount,
    invoice_amounts.transaction_reference_id  
          as TransactionReferenceID,
    round(invoice_amounts.seller_tax_share, 2)  
          as SellerSalesTax,
    round(invoice_amounts.seller_tax_refund, 2)  
          as SellerSalesTaxRefund,
    payer_info.aws_account_id  
          as PayerAwsAccountId,
    customer_info.aws_account_id  
          as EndCustomerAwsAccountId,
    invoice_amounts.disbursement_date  
          as DisbursementDate,
    invoice_amounts.bank_trace_id  
          as BankTraceId
  from
    invoice_amounts_aggregated invoice_amounts
    join products_with_latest_version products  
      on products.product_id = invoice_amounts.product_id
    left join accounts_with_latest_version payer_info  
      on payer_info.account_id = invoice_amounts.payer_account_id
    left join accounts_with_latest_version customer_info  
      on customer_info.account_id = invoice_amounts.customer_account_id
)

select * from disbursed_amount_by_product;
```

## 販売補償レポート
<a name="data-feed-example-sales-compensation"></a>

顧客別の請求済み収益を確認するには、次のようなクエリを実行します。これらのサンプルクエリは、相互に構築され、各顧客のソフトウェア使用料に対して請求された総額を含む顧客詳細の最終リストを作成します。クエリは図のように使用したり、データやユースケースに合わせてカスタマイズしたりできます。

 クエリのコメントは、クエリの動作と変更方法について説明しています。

**注記**  
このクエリを実行するときは、取り込まれたデータが 2 つの時間軸 (`valid_from` 列と `update` 列) を使用していることを前提としています。詳細については、「[AWS Marketplace データフィードのストレージと構造](data-feed-details.md)」を参照してください。

```
    -- Gets all the products and keeps the latest product_id, 
    -- valid_from tuple.
    with products_with_uni_temporal_data as (
      select
       *
      from
      (
        select
         *,
         ROW_NUMBER() OVER (PARTITION BY product_id, valid_from 
                  ORDER BY from_iso8601_timestamp(update_date) desc) 
                  as row_num
        from
         productfeed_v1
      )
      where
        -- A product_id can appear multiple times with the same 
        -- valid_from date but with a different update_date column,
        -- making it effectively bi-temporal. By only taking the most
        -- recent tuple, we are converting to a uni-temporal model.
        row_num = 1
    ),

    -- Gets the latest revision of a product
    -- A product can have multiple revisions where some of the 
    -- columns, like the title, can change.
    -- For the purpose of the sales compensation report, we want 
    -- to get the latest revision of a product
    products_with_latest_revision as (
     select
      *
     from
     (
      select
       *,
       ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY from_iso8601_timestamp(valid_from) desc) as row_num_latest_revision
      from
       products_with_uni_temporal_data
     )
     where
      row_num_latest_revision = 1
   ),

     -- Gets all the addresses and keeps the latest address_id, 
     -- aws_account_id, and valid_from combination.
     -- We're transitioning from a bi-temporal data model to an 
     -- uni-temporal data_model
     piifeed_with_uni_temporal_data as (
       select
        *
       from
       (
         select
          *,
          ROW_NUMBER() OVER (
             PARTITION BY address_id, aws_account_id, valid_from 
             ORDER BY from_iso8601_timestamp(update_date) desc) 
             as row_num
         from
          piifeed
       )
       where
         -- An address_id can appear multiple times with the same
         -- valid_from date but with a different update_date column.
         -- We are only interested in the most recent.
         row_num = 1
     ),

    -- Gets the latest revision of an address.
    -- An address_id can have multiple revisions where some of 
    -- the columns can change.
    -- For the purpose of the sales compensation report, we want to
    -- get the latest revision of an address + account_id pair.
    pii_with_latest_revision as (
      select
       *
      from
      (
       select
        *,
        ROW_NUMBER() OVER (PARTITION BY address_id, aws_account_id 
              ORDER BY from_iso8601_timestamp(valid_from) desc) 
              as row_num_latest_revision
       from
        piifeed_with_uni_temporal_data
      )
      where
       row_num_latest_revision = 1
    ),

    -- Gets all the accounts and keeps the latest 
    -- account_id, valid_from tuple.
    -- We're transitioning from a bi-temporal data 
    -- model to an uni-temporal data_model.
    accounts_with_uni_temporal_data as (
      select
       *
      from
      (
        select
         *,
         ROW_NUMBER() OVER (PARTITION BY account_id, valid_from 
             ORDER BY from_iso8601_timestamp(update_date) desc) 
             as row_num
        from
         accountfeed_v1
      )
      where
        -- An account_id can appear multiple times with the same 
        -- valid_from date but with a different update_date column.
        -- We are only interested in the most recent tuple.
        row_num = 1
    ),

    -- Gets all the historical dates for an account
    -- An account can have multiple revisions where some of the 
    -- columns like the mailing_address_id can change.
    accounts_with_history as (
     select
      *,
      -- This interval's begin_date
      case
        when
        -- First record for a given account_id
          lag(valid_from, 1) over (partition by account_id 
             order by from_iso8601_timestamp(valid_from) asc) is null
        then
          -- 'force' begin_date a bit earlier because of different 
          -- data propagation times. We'll subtract one day as one
          -- hour is not sufficient
          from_iso8601_timestamp(valid_from) - INTERVAL '1' DAY
        else
          -- not the first line -> return the real date
          from_iso8601_timestamp(valid_from)
      end as begin_date,
      -- This interval's end date.
      COALESCE(
           LEAD(from_iso8601_timestamp(valid_from), 1) 
                OVER (partition by account_id 
                ORDER BY from_iso8601_timestamp(valid_from)),
           from_iso8601_timestamp('9999-01-01T00:00:00Z')
      ) as end_date
     from
       accounts_with_uni_temporal_data
   ),

    -- Gets all the billing events and keeps the latest 
    -- billing_event_id, valid_from tuple.
    -- We're transitioning from a bi-temporal data 
    -- model to an uni-temporal data_model.
    billing_events_with_uni_temporal_data as (
      select
       *
      from (
        select
          billing_event_id,
          from_iso8601_timestamp(valid_from) as valid_from,
          from_iso8601_timestamp(update_date) as update_date,
          from_iso8601_timestamp(invoice_date) as invoice_date,
          transaction_type,
          transaction_reference_id,
          product_id,
          disbursement_billing_event_id,
          action,
          currency,
          from_account_id,
          to_account_id,
          end_user_account_id,
          -- convert an empty billing address to null. This will 
          -- later be used in a COALESCE call
          case
           when billing_address_id <> '' then billing_address_id else null
          end as billing_address_id,
          CAST(amount as decimal(20, 10)) invoice_amount,
          ROW_NUMBER() OVER (PARTITION BY billing_event_id, valid_from 
              ORDER BY from_iso8601_timestamp(update_date) desc) 
              as row_num
        from
          billingeventfeed_v1
        where
          -- The Sales Compensation Report does not contain BALANCE 
          -- ADJUSTMENTS, so we filter them out here
          transaction_type <> 'BALANCE_ADJUSTMENT'
          -- Keep only the transactions that will affect any 
          -- future disbursed amounts.
          and balance_impacting = '1'
        )
      where row_num = 1
    ),

    -- Gets the billing address for all DISBURSED invoices. This 
    -- will be the address of the payer when the invoice was paid.
    -- NOTE: For legal reasons, for CPPO transactions, the 
    -- manufacturer will not see the payer's billing address id
    billing_addresses_for_disbursed_invoices as (
      select
        billing_events_raw.transaction_reference_id,
        billing_events_raw.billing_address_id,
        billing_events_raw.from_account_id
      from
        billing_events_with_uni_temporal_data billing_events_raw
      where
        -- the disbursed items will contain the billing address id
        billing_events_raw.action = 'DISBURSED'
        -- we only want to get the billing address id for the 
        -- transaction line items where the seller is the receiver
        -- of the amount
        and billing_events_raw.transaction_type like 'SELLER_%'
      group by
        billing_events_raw.transaction_reference_id,
        billing_events_raw.billing_address_id,
        billing_events_raw.from_account_id
    ),

  -- An invoice can contain multiple line items.
  -- We create a pivot table to calculate the different amounts 
  -- that are part of an invoice.
  -- The new row is aggregated at 
  -- transaction_reference_id - end_user_account_id level
  invoiced_and_forgiven_transactions as (
    select
      transaction_reference_id,
      product_id,
      -- A transaction will have the same invoice date for all 
      -- of its line items (transaction types)
      max(invoice_date) as invoice_date,
      -- A transaction will have the same billing_address_id 
      -- for all of its line items. Remember that the billing event
      -- is uni temporal and we retrieved only the latest valid_from item
      max(billing_address_id) as billing_address_id,
      --  A transaction will have the same currency for all 
      -- of its line items
      max(currency) as currency,
      -- We're building a pivot table in order to provide all the 
      -- data related to a transaction in a single row
      sum(case when transaction_type = 'SELLER_REV_SHARE' 
            then invoice_amount else 0 end) as seller_rev_share,
      sum(case when transaction_type = 'AWS_REV_SHARE' 
            then invoice_amount else 0 end) as aws_rev_share,
      sum(case when transaction_type = 'SELLER_REV_SHARE_REFUND' 
            then invoice_amount else 0 end) as seller_rev_refund,
      sum(case when transaction_type = 'AWS_REV_SHARE_REFUND' 
            then invoice_amount else 0 end) as aws_rev_refund,
      sum(case when transaction_type = 'SELLER_REV_SHARE_CREDIT' 
            then invoice_amount else 0 end) as seller_rev_credit,
      sum(case when transaction_type = 'AWS_REV_SHARE_CREDIT' 
            then invoice_amount else 0 end) as aws_rev_credit,
      sum(case when transaction_type = 'SELLER_TAX_SHARE' 
            then invoice_amount else 0 end) as seller_tax_share,
      sum(case when transaction_type = 'SELLER_TAX_SHARE_REFUND' 
            then invoice_amount else 0 end) as seller_tax_refund,
      -- this is the account that pays the invoice.
      max(case
        -- Get the payer of the invoice from any transaction type 
        -- that is not AWS and not BALANCE_ADJUSTMENT.
        -- For AWS and BALANCE_ADJUSTMENT, the billing event feed 
        -- will show the "AWS Marketplace" account as the
        -- receiver of the funds and the seller as the payer. We 
        -- are not interested in this information here.
        when
         transaction_type not like '%AWS%' 
           and transaction_type not like 'BALANCE_ADJUSTMENT' 
         then from_account_id
       end) as payer_account_id,
      -- this is the account that subscribed to your product
      end_user_account_id as customer_account_id
    from
      billing_events_with_uni_temporal_data
    where
      -- Get invoiced or forgiven items. Disbursements are 
      -- not part of the sales compensation report
      action in ('INVOICED', 'FORGIVEN')
    group by
      transaction_reference_id,
      product_id,
      -- There might be a different end-user for the same 
      -- transaction reference id. Distributed licenses 
      -- is an example.
      end_user_account_id
),

invoiced_items_with_product_and_billing_address as (
  select
    invoice_amounts.*,
    products.product_code,
    products.title,
    payer_info.aws_account_id as payer_aws_account_id,
    payer_info.account_id as payer_reference_id,
    customer_info.aws_account_id as end_user_aws_account_id,
    (
        invoice_amounts.seller_rev_share +
        invoice_amounts.aws_rev_share +
        invoice_amounts.seller_rev_refund +
        invoice_amounts.aws_rev_refund +
        invoice_amounts.seller_rev_credit +
        invoice_amounts.aws_rev_credit +
        invoice_amounts.seller_tax_share +
        invoice_amounts.seller_tax_refund
    ) as seller_net_revenue,
    -- Try to get the billing address from the DISBURSED event 
    -- (if any). If there is no DISBURSEMENT, get the billing 
    -- address from the INVOICED item. If still no billing address, 
    -- then default to getting the mailing address of the payer.
    coalesce(billing_add.billing_address_id, 
             invoice_amounts.billing_address_id, 
             payer_info.mailing_address_id) 
          as final_billing_address_id
  from
    invoiced_and_forgiven_transactions invoice_amounts
    join products_with_latest_revision products 
        on products.product_id = invoice_amounts.product_id
    left join accounts_with_history payer_info 
        on payer_info.account_id = invoice_amounts.payer_account_id
          -- Get the Payer Information at the time of invoice creation
          and payer_info.begin_date <= invoice_amounts.invoice_date 
          and invoice_amounts.invoice_date < payer_info.end_date
    left join accounts_with_history customer_info 
        on customer_info.account_id = invoice_amounts.customer_account_id
          -- Get the End User Information at the time of invoice creation
          and customer_info.begin_date <= invoice_amounts.invoice_date 
          and invoice_amounts.invoice_date < customer_info.end_date
    left join billing_addresses_for_disbursed_invoices billing_add 
        on billing_add.transaction_reference_id = 
           invoice_amounts.transaction_reference_id
        and billing_add.from_account_id = 
            invoice_amounts.payer_account_id
),

invoices_with_full_address as (
  select
    payer_aws_account_id as "Customer AWS Account Number",
    pii_data.country as "Country",
    pii_data.state_or_region as "State",
    pii_data.city as "City",
    pii_data.postal_code as "Zip Code",
    pii_data.email_domain as "Email Domain",
    product_code as "Product Code",
    title as "Product Title",
    seller_rev_share as "Gross Revenue",
    aws_rev_share as "AWS Revenue Share",
    seller_rev_refund as "Gross Refunds",
    aws_rev_refund as "AWS Refunds Share",
    seller_net_revenue as "Net Revenue",
    currency as "Currency",
    date_format(invoice_date, '%Y-%m')as "AR Period",
    transaction_reference_id as "Transaction Reference ID",
    payer_reference_id as "Payer Reference ID",
    end_user_aws_account_id as "End Customer AWS Account ID"
  from
    invoiced_items_with_product_and_billing_address invoice_amounts
    left join pii_with_latest_revision pii_data 
        on pii_data.aws_account_id = invoice_amounts.payer_aws_account_id
        and pii_data.address_id = invoice_amounts.final_billing_address_id
    -- Filter out FORGIVEN and Field Demonstration Pricing transactions
    where seller_net_revenue <> 0
)

select * from invoices_with_full_address;
```

# データフィード
<a name="data-feeds"></a>

AWS Marketplace は、販売者が製品の販売に関する情報を収集および分析するのに役立つ多数のデータフィードを提供します。データフィードは、登録されたすべての AWS Marketplace 販売者が利用できます。データフィードは 1 日以内に生成されるため、最新のデータを利用できます。

以降のセクションでは、それぞれのデータフィードについて説明します。

**Topics**
+ [アカウントデータフィード](data-feed-account.md)
+ [住所データフィード](data-feed-address.md)
+ [契約データフィード](data-feed-agreements.md)
+ [契約料金データフィード](data-feed-agreement-charge.md)
+ [契約期間データフィード](data-feed-agreement-term.md)
+ [請求イベントデータフィード](data-feed-billing-event.md)
+ [日次使用状況データフィード](data-feed-daily-usage.md)
+ [レガシーマッピングデータフィード](data-feed-legacy-mapping.md)
+ [オファーデータフィード](data-feed-offer.md)
+ [オファー製品データフィード](data-feed-offer-product.md)
+ [オファーターゲットデータフィード](data-feed-offer-target.md)
+ [製品データフィード](data-feed-product.md)
+ [税品目データフィード](data-feed-tax-item.md)

# アカウントデータフィード
<a name="data-feed-account"></a>

このデータフィードは、ユーザーが操作するすべてのアカウント (ユーザー自身、使用しているチャネルパートナー、購入者、支払者、およびすべての課税対象アカウント) に関する情報を提供します。

アカウントデータはイミュータブルであり、バージョン番号は関連付けられません。フィールドに対する変更は付け加えられるため、このデータフィードには同じ `account_id` 値と、異なる `valid_from` 値を持つ複数の行が存在する場合があります。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。

アカウントデータフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。


| 列名  | 説明  | 
| --- | --- | 
| account\$1id  | アカウントのグローバル一意識別子 (GUID)。`Product`、`Offer_Target`、`Billing_Event`、`Tax_Item` およびデータフィードのフィールドへの結合に使用できます。結合に使用できるフィールドについては、これらのデータフィードを参照してください。 | 
| aws\$1account\$1id  | 販売者の AWS アカウントの AWS アカウント番号。AWS パーティションごとに一意です。 | 
| encrypted\$1account\$1id | アプリケーションの購入者別の一意の暗号化された ID。encrypted\$1account\$1id の値は、例えば、[https://docs.aws.amazon.com/marketplacemetering/latest/APIReference/API_ResolveCustomer.html](https://docs.aws.amazon.com/marketplacemetering/latest/APIReference/API_ResolveCustomer.html) アクションによって返される CustomerIdentifier の値として、AWS Marketplace メータリングサービスによって使用されます。 | 
| mailing\$1address\$1id | このアカウントの郵送先住所の参照。 | 
| tax\$1address\$1id | このアカウントの税宛先住所の参照。 | 
| tax\$1registration\$1number | 米国以外のアカウントの場合、このアカウントの税登録番号。 | 
| tax\$1legal\$1name | 米国以外のアカウントの場合、法人名。これは、税金請求書で使用される名前です。 | 

## アカウントデータフィードの例
<a name="data-feed-account-sample-data"></a>

アカウントデータフィードの例は次のとおりです。見やすいように、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| account\$1id  | aws\$1account\$1id  | encrypted\$1account\$1id | mailing\$1address\$1id | tax\$1address\$1id | tax\$1registration\$1number | tax\$1legal\$1name | 
| --- | --- | --- | --- | --- | --- | --- | 
| xk0CSmiAm6PQ4QqEog9iiaochIzuPlkMfba7a1oDlZ | 444456660000 | Zf7oMzheGWpH | 25o3k46eN6eViOfFiiqtxwX8e3kaOiPalUiofjyFa3 |  |  |  | 
| 7nyo5jwTRoPlyX81vx9ji04eEwTurO1Ff8biQi88W8 | 555567679999 | 373vuQUqmQ8v | 5oJ6vTjSzMrrF2gvh2Vj9HfqiM800MuLEHmyFY5Lr42s8 | 5oJ6vTjSzMrrF2gvh2Vj9HfqiM800MuLEHmyFY5Lr42s8 | SE823935083345 |  | 
| VIeGa2t9j3MuxioH9wc8lsndXXCgGCGUreeXriocM5 | 73739998888 | 8SPxAYmi8MwX | NLUc5UeiMlGFTrDWCoftDPhDUF1oaSd8xgl5QM8Db7 | V5NhBYBiYogwy0WMhndGU4AfMggmuoTC2j7Pm8ZKKNNyT | DE469558025 |  | 

# 住所データフィード
<a name="data-feed-address"></a>

**重要**  
AWS Marketplace では、[販売者配送データフィードサービス](https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed-service.html)を使用して配信される PIIFeed を 2023 年 12 月に廃止します。必要な住所データには AddressFeed\$1v1 データフィードを使用してください。質問がある場合やサポートが必要な場合は、[AWS Marketplace Seller Operations](https://aws.amazon.com/marketplace/management/contact-us/) チームまでお問い合わせください。

このデータフィードは、ユーザーが操作するすべてのアカウント (ユーザー自身、使用しているチャネルパートナー、購入者、支払者、およびすべての課税対象アカウント) に関する連絡先情報を提供します。新しい取引が発生するたびに、その取引の顧客住所がスキャンされ、その住所がデータフィードにない場合は、新しいエントリがデータフィードファイルに追加されます。

住所データはイミュータブルです。

住所データフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。


| 列名  | 説明  | 
| --- | --- | 
| address\$1id  | 住所の一意のキー。`billing_address_id` フィールドの `Billing_Event` データフィード、`mailing_address_id` または `tax_address_id` フィールドの `Account` データフィードからの結合に使用できます。 | 
| email\$1domain  | このアカウントの登録済み E メールアドレスのドメイン。 | 
| company\$1name  | このアカウントの登録済み会社名。 | 
| country\$1code | この住所の登録済み ISO 3166 alpha-2 国コード。 | 
| state\$1or\$1region  | この住所の登録済み都道府県またはリージョン。 | 
| city  | この住所の登録済み市区町村。 | 
| postal\$1code  | この住所の登録済み郵便番号。 | 
| address\$1line\$11  | この住所の登録済み行 (1 行目)。 | 
| address\$1line\$12  | この住所の登録済み行 (2 行目)。 | 
| address\$1line\$13  | この住所の登録済み行 (3 行目)。 | 

## 住所データフィードの例
<a name="data-feed-address-sample-data"></a>

住所データフィードの例を次に示します。この情報は、データフィードの単一のテーブルに表示されます。見やすいように、ここではデータを 2 つのテーブルに表示し、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| address\$1id  | email\$1domain  | company\$1name  | country\$1code  | state\$1or\$1region  | city  | postal\$1code  | 
| --- | --- | --- | --- | --- | --- | --- | 
| V5NhBYBiYogwy0WMhndGU4AfMggmuoTC2j7Pm8ZKKNNyT | a.com | Mateo Jackson's Company | DE |  | Hamburg | 67568 | 
| G68xdbkZQDVVHzfBGw6yf5yos0A6NiSVWHmH5ViLjf | b.com | Mary Major's Company | 米国 | OH | Dayton | 57684 | 
| NLUc5UeiMlGFTrDWCoftDPhDUF1oaSd8xgl5QM8Db7 | c.com | Our Seller | 米国 | NY | New York | 89475 | 




| address\$1line\$11  | address\$1line\$12  | address\$1line\$13  | 
| --- | --- | --- | 
|   |   |  | 
|  |   |  | 
|  | 19th Floor |  | 



# 契約データフィード
<a name="data-feed-agreements"></a>

このデータフィードは、製品の使用を開始するために提案者 (登録販売者) とアクセプタ (AWS 購入者) の間で署名された契約である契約に関する情報を提供します。このデータフィードは、登録販売者として作成したすべての製品オファーの契約に関する情報を提供します。

契約データフィードは 24 時間ごとに更新されます。

次の表は、データフィードの項目を一覧表示し、説明しています。


| 列 | [Description] (説明) | 
| --- | --- | 
| valid\$1from | 主キーの値が他のフィールドの値に関連して有効である最初の日付。 | 
| insert\$1date | レコードがデータフィードに挿入された日付。 | 
| update\$1date | レコードが最後に更新された日付。 | 
| delete\$1date | この列は常に空白です。 | 
| ステータス |  契約の現在の状態。サポートされているステータスは次のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-agreements.html)  | 
| estimated\$1agreement\$1value | 契約のライフサイクル全体で顧客による支払いが見込まれる既知の合計金額。 | 
| currency\$1code | 契約のライフサイクル全体で顧客による支払いが見込まれる既知の合計金額の通貨。 | 
| agreement\$1id | 契約の一意の識別子。 | 
| license\$1ids | 配列として表される、契約に関連付けられたライセンス識別子。 | 
| proposer\$1account\$1id | この購入契約を提案した販売者は、販売者のアカウントのグローバル一意識別子 (GUID) で表されます。アカウントデータフィードに参加するために使用できます。 | 
| acceptor\$1account\$1id | この購入契約を承認した購入者は、購入者のアカウントのグローバル一意識別子 (GUID) で表されます。アカウントデータフィードに参加するために使用できます。 | 
| offer\$1revision\$1at\$1acceptance | 本契約に対応するオファーのわかりやすい ID。オファーおよびオファーターゲットデータフィードに参加するために使用できます。 | 
| offer\$1set\$1id | オファーに関連付けられたオファーセットの識別子。 | 
| start\$1time | 契約開始日時。 | 
| end\$1time | 契約開始日時。終了日のない従量制料金の場合、このフィールドは、null です。 | 
| acceptance\$1time | オファー承認日時または、契約作成日時。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-agreements.html)  | 
| intent | 契約が最後に変更されたときの購入者の意向。 | 
| preceding\$1agreement\$1id | 前の契約の契約 ID。 | 
| status\$1reason\$1code | 契約ステータスが変更された理由。 | 
| recipient\$1account\$1id | フィードでデータを受信している販売者のアカウント。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 

## 契約データフィードの例
<a name="agreements-feed-example"></a>


| valid\$1from | agreement\$1id | proposer\$1account\$1id | acceptor\$1account\$1id | offer\$1id | offer\$1revision\$1at\$1acceptance | offer\$1set\$1id | start\$1time | end\$1time | acceptancet\$1time | intent | preceding\$1agreement\$1id | ステータス | status\$1reason\$1code | estimated\$1agreement\$1value | currency\$1code | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| 2024 年 6 月 21 日 20:58:00.0 | agmt-34g544dfgsd5678adsrgwe5t | 88a3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 88a3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | offer-krxxxxxxxxxxx | 1 | offerset-yricpu74oqox2 | 2024 年 6 月 21 日 20:58:00.0 | 2025 年 6 月 21 日 20:58:00.0 | 2024 年 6 月 21 日 20:58:00.0 | 新規 |  | アクティブ |  | 1,000 | USD | 

# 契約料金データフィード
<a name="data-feed-agreement-charge"></a>

このデータフィードは、登録販売者としてユーザーが作成した契約に関連する料金の概要を提供します。このデータフィードは現在、支払いスケジュール期間に関連付けられた契約に対してのみ料金情報を提供します。

契約料金データフィードは 24 時間ごとに更新されます。

次の表は、データフィードの項目を一覧表示し、説明しています。


| 列 | [Description] (説明) | 
| --- | --- | 
| valid\$1from | 主キーの値が他のフィールドの値に関連して有効である最初の日付。 | 
| insert\$1date | レコードがデータフィードに挿入された日付。 | 
| update\$1date | レコードが最後に更新された日付。 | 
| delete\$1date | この列は常に空白です。 | 
| amount | 請求される金額。 | 
| currency\$1code | 支払いの料金通貨。 | 
| 時間 | 予定された分割払いのスケジュールされた請求日。 | 
| agreement\$1id | 契約の一意の識別子。 | 
| term\$1id | 用語の一意の識別子。 | 

## 契約料金データフィードの例
<a name="agreement-charge-feed-example"></a>


| valid\$1from | insert\$1date | update\$1date | delete\$1date | amount | currency\$1code | 時間 | agreement\$1id | term\$1id | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| 2024-12-24 11:31:47.0 | 2025-10-01 01:03:41.0 | 2025-10-01 01:03:41.0 | null | 28440.00 | USD | 2025-11-06 00:00:00.00000 | agmt-3kk39tbw3j6id2vakbp0XXXXX | term-3986e2c7f73768ed4ff7cd8a97b41ac0ae2aa02ada6b68deb9349c8604cXXXXX | 

# 契約期間データフィード
<a name="data-feed-agreement-term"></a>

このデータフィードは、登録販売者としてユーザーが作成した契約に関連する契約期間の概要を提供します。

契約期間データフィードは 24 時間ごとに更新されます。

次の表は、データフィードの項目を一覧表示し、説明しています。


| 列 | [Description] (説明) | 
| --- | --- | 
| valid\$1from | 主キーの値が他のフィールドの値に関連して有効である最初の日付。 | 
| insert\$1date | レコードがデータフィードに挿入された日付。 | 
| update\$1date | レコードが最後に更新された日付。 | 
| delete\$1date | レコードが削除された日付。 | 
| agreement\$1id | 契約の一意の識別子。 | 
| term\$1id | 用語の一意の識別子。 | 
| term\$1type | 契約に関連付けられている用語のタイプ。利用可能な用語の完全なリストについては、https://docs.aws.amazon.com/marketplace/latest/APIReference/API\$1Types\$1AWS\$1Marketplace\$1Agreement\$1Service.html を参照してください。 | 
| term\$1configuration | 用語を受け入れているときにアクセプタによって指定された追加のパラメータ。これは、ConfigurableUpfrontPricingTerms と RenewalTerms に適用されます。 | 

## 契約期間データフィードの例
<a name="agreement-term-feed-example"></a>


| valid\$1from | insert\$1date | update\$1date | delete\$1date | agreement\$1id | term\$1id | term\$1type | term\$1configuration | 
| --- | --- | --- | --- | --- | --- | --- | --- | 
| 2024-12-24 11:31:47.0 | 2025-10-01 01:03:41.0 | 2025-10-01 01:03:41.0 | null | agmt-3kk39tbw3j6id2vakbp0XXXXX | term-3986e2c7f73768ed4ff7cd8a97b41ac0ae2aa02ada6b68deb9349c8604cXXXXX | ConfigurableUpfrontPricingTerm | \$1"selectorValue"P36M"dimensions":[\$1"dimensionKey"Applications"dimensionValue":1\$1]\$1 | 

# 請求イベントデータフィード
<a name="data-feed-billing-event"></a>

このデータフィードは、請求や支払いなど、請求イベントに関する情報を提供します。

例えば、このデータフィードを使用して、購入者への請求日や請求内容を確認できます。[サンプルの SQL クエリ](#data-feeds-billing-event-query-examples)を使用して、このデータフィードのデータを分析することもできます。

このデータフィードは、登録販売者としての請求イベントに関連する情報を示します。チャネルパートナーを介して締結された契約の場合、このデータフィードはメーカーと登録販売者との請求イベントに関する情報を示します。

請求イベントデータフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

請求イベントデータはイミュータブルです。

以下の表では、データフィードの列の名前と説明を示しています。


| [列名]  | 説明  | 
| --- | --- | 
| billing\$1event\$1id | 請求イベントの識別子。この ID は、販売者の環境内で一意です。 | 
| from\$1account\$1id |  請求イベントを開始したアカウント。`transaction_type` が `SELLER_REV_SHARE` である場合は、購入者の支払いアカウントです。これは、[アカウント](data-feed-account.md)データフィードへの外部キーです。 `account_id`フィールドの `Account` データフィードへの結合に使用できます。  | 
| to\$1account\$1id | 製品の取引金額を受け取るアカウント。これは、アカウントデータフィードへの外部キーです。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 
| end\$1user\$1account\$1id | 製品を使用するアカウント。このアカウントは、購入者アカウントや支払者アカウントとは異なる場合があります。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 
| product\$1id | 製品の識別子。これは [製品](data-feed-product.md)データフィードへの外部キーです。`product_id`フィールドの `Product` データフィードへの結合に使用できます。 | 
| action |  このイベントのアクションのタイプ。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| transaction\$1type |  取引のタイプ。例については「[課税シナリオ](#data-feeds-billing-event-tax-examples)」を参照してください。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| parent\$1billing\$1event\$1id |  `broker_id` の値が `AWS_INC` で、`action` の値が `DISBURSED` または `FORGIVEN` で、`transaction_type` の値が `DISBURSEMENT` の場合、`parent_billing_event_id` はこの請求イベントを開始した元の `billing_event_id` の金額を指します。`action` に別の値がある場合、このフィールドは null です。 `broker_id` の値が `AWS_EUROPE` の場合、`parent_billing_event_id` は次のシナリオで請求イベントを開始した元の `billing_event_id` を指します。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html) `broker_id` の値が `AWS_EUROPE` の場合、`parent_billing_event_id` は次のシナリオで前回成功した支払い請求イベントの元の `billing_event_id` を指します。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html) `broker_id` の値が `AWS_EUROPE` の場合、残りのシナリオではこのフィールドは null になります。  | 
| disbursement\$1billing\$1event\$1id |  `action` の値が `DISBURSED` であり、さらに次のいずれかに該当する場合の関連支払額。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html) 他のすべてのシナリオでは、この値は null です。  | 
| amount | 請求イベントの金額。 | 
| currency | ISO 639 通貨コード。 | 
| disbursement\$1amount | 支払い額。二重請求シナリオの場合、このフィールドには支払い金額が含まれます。統合請求シナリオの場合、このフィールドは null です。 | 
| disbursement\$1currency | 支払い金額の ISO 639 通貨コード。二重請求シナリオの場合、このフィールドには支払い通貨コードが含まれます。統合請求シナリオの場合、このフィールドは null です。 | 
| balance\$1impacting | 販売者の支払いを計算する際に該当金額を考慮するかどうか。0 の値は、該当金額が情報提供のために表示されており、残高には影響しないことを示します。1 の値は、該当金額が販売者の支払いを決定する際に考慮されることを示します。 | 
| invoice\$1date | 請求書が作成された日付。 | 
| payment\$1due\$1date |  `action` の値が `INVOICED` である場合は、請求書の支払期限日です。  | 
| usage\$1period\$1start\$1date | レコードの期間の開始日。 | 
| usage\$1period\$1end\$1date | レコードの期間の終了日。 | 
| invoice\$1id |   AWS 請求書 ID。  | 
| billing\$1address\$1id | 住所データフィードにおける支払人の請求連絡先の参照。`address_id`フィールドの `Address` データフィードへの結合に使用できます。 | 
| transaction\$1reference\$1id |  以下のレポートのデータを相互参照できる識別子。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| bank\$1trace\$1id |  支払い取引 (`transaction_type` = `DISBURSEMENT` で、アクションは`DISBURSED`) の場合、銀行によって割り当てられたトレース ID。トレース ID は、銀行が提供する販売者銀行からのレポートと関連付けるために使用できます。  | 
| broker\$1id |  取引を促進した事業体の識別子。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| buyer\$1transaction\$1reference\$1id |  `GROUP BY` または SQL で作成されたウィンドウ関数を使用して、請求フィード内のすべての関連レコードをグループ化する識別子。これらの関連レコードには、購入者請求書、販売者請求書、および出品料金にかかる付加価値税 (VAT) が含まれる場合があります。  | 
| action\$1date |  トランザクションイベントが発生した日付。特定の日付はアクションタイプによって異なります。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| recipient\$1account\$1id | フィードでデータを受信している販売者のアカウント。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 
| offer\$1id | 購入者請求書の明細項目に関連付けられているオファーのフレンドリ ID。`offer_id`フィールドの `Offer` データフィードへの結合に使用できます。 | 
| Buyer\$1invoice\$1date | 関連する購入者請求書明細項目の請求書日付。 | 
| line\$1item\$1id | 支払いの詳細度での請求書明細項目 ID。 | 
| Buyer\$1line\$1item\$1id | 支払いの詳細度での購入者請求書明細項目 ID。 | 
| charge\$1variant | 何を購入または販売するかを示します。 | 
| charge\$1side | 販売者が請求バリアントを売買しているかどうかを示します。 | 

## 課税シナリオ
<a name="data-feeds-billing-event-tax-examples"></a>

購入者と販売者の国および州に適用されている課税モデルによって、税金の徴収と支払の方法が決まります。考えられるシナリオは次のとおりです。
+ 税金は によって収集され、送金されます AWS。この場合、`transaction_type` は `AWS_TAX_SHARE` です。
+ 税金は AWS、販売者が徴収し、販売者に支払い、販売者が税務当局に送金します。この場合、`transaction_type` は `SELLER_TAX_SHARE` です。
+ 税金は によって徴収されません AWS。販売者が税金を計算して税務当局に納税する必要があります。このような場合、 は税計算を実行 AWS Marketplace したり、税情報を受信したりしません。販売者が収益分配金から納税します。

## 請求イベントデータフィードの例
<a name="data-feed-billing-event-sample-scenario"></a>

このセクションでは、請求時と 1 か月後の請求イベントデータ期間の例を示します。このセクションのすべての表について、次の点に注意してください。
+ データフィードの `billing_event_id` 値は 40 文字の英数字文字列です。ここでは、見やすいように 2 文字の文字列として表示しています。
+ この情報は、データフィードの単一のテーブルに表示されます。見やすいように、ここではデータを複数のテーブルに表示し、一部の列を省略しています。

このセクションの例では、以下を前提とします。
+ Arnav は購入者です。
  + アカウント ID は `737399998888` です。
  + 居住国のフランスでは、マーケットプレイスファシリテーター法が適用されます。詳細については、「[アマゾン ウェブ サービス税務ヘルプ](https://aws.amazon.com/tax-help/)」を参照してください。
  + `prod-o4grxfafcxxxx` を購入し、この製品の月間使用料として 120.60 USD を請求されました。
  + 当月内に請求額を支払いました。
+ Jane はメーカーです。
  + アカウント ID は `111122223333` です。
+ Paulo は登録販売者です。
  + アカウント ID は `777788889999` です。
  + 居住しているカンザス州は、マーケットプレイスファシリテーター法の対象ではありません。

### 登録販売者の請求イベントデータフィード
<a name="billing-event-example-seller-of-record"></a>

Paulo は、登録販売者として購入者の Arnav に請求を行います。

次の表は、Paulo が Arnav に請求した際のデータフィードの関連情報を示しています。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I0 | 737399998888 | 777788889999 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I1 | 737399998888 | AWS | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1TAX\$1SHARE | 
| I2 | 777788889999 | 111122223333 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I3 | 777788889999 | AWS | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1SHARE | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | amount | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 100 | USD | 2018-12-31T00:00:00Z | 781216640 | 
|  |  | 20.6 | USD | 2018-12-31T00:00:00Z | 781216640 | 
|  |  | -80 | USD | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | -0.2 | USD | 2018-12-31T00:04:07Z | 788576665 | 

次の表は、Arnav が請求額を支払った後の月末における Paulo のデータフィードの関連情報を示しています。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I10 | 737399998888 | 777788889999 | 737399998888 |  | DISBURSED | SELLER\$1REV\$1SHARE | 
| I12 | 777788889999 | 111122223333 | 737399998888 |  | DISBURSED | SELLER\$1REV\$1SHARE | 
| I13 | 777788889999 | AWS | 737399998888 | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1SHARE | 
| I14 | AWS | 777788889999 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | amount | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
| I0 | I14 | -100 | USD | 2018-12-31T00:00:00Z | 781216640 | 
| I2 | I14 | 80 | USD | 2018-12-31T00:04:07Z | 788576665 | 
| I3 | I14 | 0.2 | USD | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | 19.8 | USD |  |  | 

### メーカーの請求イベントデータフィード
<a name="billing-event-example-manufacturer"></a>

次の表は、Paulo が Arnav に請求した際の Jane のデータフィードの関連情報を示しています。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I5 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I6 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | INVOICED | SELLER\$1TAX\$1SHARE | 
| I7 | 111122223333 | AWS |  | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1SHARE | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | amount | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
|  |  | 73.5 |  | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | 6.5 |  | 2018-12-31T00:04:07Z | 788576665 | 
|  |  | -7.35 |  | 2018-12-31T00:04:07Z | 788576665 | 

次の表は、請求額が支払われた後の月末における Jane のデータフィードの関連情報を示しています。


| billing\$1event\$1id  | from\$1account\$1id  | to\$1account\$1id  | end\$1user\$1account\$1id | product\$1id | action | transaction\$1type | 
| --- | --- | --- | --- | --- | --- | --- | 
| I30 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | DISBURSED | SELLER\$1REV\$1SHARE | 
| I31 | 777788889999 | 111122223333 |  | prod-o4grxfafcxxxx | DISBURSED | SELLER\$1TAX\$1SHARE | 
| I32 | 111122223333 | AWS |  | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1SHARE | 
| I33 | AWS | 111122223333 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | amount | currency | invoice\$1date | invoice\$1id | 
| --- | --- | --- | --- | --- | --- | 
| I5 | I33 | -73.5 | USD |  |  | 
| I6 | I33 | -6.5 | USD |  |  | 
| I7 | I33 | 7.35 | USD |  |  | 
|  |  | 72.65 | USD |  |  | 

## クエリの例
<a name="data-feeds-billing-event-query-examples"></a>

[データフィードを使用したデータ収集と分析](data-feed-using.md) で説明しているように、[ Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) を使用して、マネージド Amazon S3 バケットにデータフィードとして収集されて保存されたデータに対してクエリを実行できます。このセクションでは、これを行う一般的な方法の例をいくつか示します。すべての例で、単一の通貨を使用するものとします。

## 例 1: 請求金額 (税込み)
<a name="data-feed-example-query-tax-invoice"></a>

購入者への請求金額 (税込み) を確認するには、次の例に示すようなクエリを実行できます。

```
SELECT sum(amount) FROM billing_event 
WHERE 
  action = 'INVOICED'
  AND
  (
    (transaction_type in ('SELLER_REV_SHARE', 'SELLER_TAX_SHARE')
      -- to discard SELLER_REV_SHARE from Manufacturer to Channel Partner, aka cost of goods
      AND to_account_id='seller-account-id'
    )
  OR transaction_type= 'AWS_TAX_SHARE'
  );
```

## 例 2: 販売者に代わって購入者に請求する金額
<a name="data-feed-example-query-invoice-for-seller"></a>

販売者に代わって購入者に請求した金額を確認するには、次の例に示すようなクエリを実行できます。

```
SELECT sum(amount) FROM billing_event 
WHERE
  action = 'INVOICED'
  AND transaction_type in ('SELLER_REV_SHARE', 'SELLER_TAX_SHARE')
  AND to_account_id='seller-account-id'
;
```

## 例 3: 販売者に代わって回収 AWS できる金額
<a name="data-feed-example-query-aws-collect"></a>

販売者に代わって が回収 AWS できる金額から返金、クレジット、許されたアカウントを差し引いた金額を調べるには、次の例に示すようにクエリを実行できます。

```
SELECT sum(amount) FROM billing_event 
WHERE
  -- what is invoiced on behalf of SELLER, incl. refunds/ credits and cost of goods
  transaction_type like 'SELLER_%' 
  -- FORGIVEN action records will "negate" related INVOICED
  and action in ('INVOICED','FORGIVEN') 
;
```

## 例 4: 販売者が徴収できる金額
<a name="data-feed-example-query-seller-collect"></a>

販売者が徴収できる金額を確認するには、次の例に示すようなクエリを実行できます。この例では、 が AWS 徴収する出品料金と税金を削除し、例外的な残高調整を追加します。

```
SELECT sum(amount) FROM billing_event
WHERE
  (transaction_type like 'SELLER_%' -- what is invoiced on behalf of SELLER
  or transaction_type like 'AWS_REV_%' -- what is owed to AWS
  or transaction_type = 'BALANCE_ADJUSTMENT' -- exceptionnal case
  )
  and action in ('INVOICED','FORGIVEN')
;
```

また、次の例に示すように、次のクエリを使用して同じ情報を収集することもできます。

```
SELECT sum(amount) FROM billing_event
WHERE
  balance_impacting = 1
  and action in ('INVOICED','FORGIVEN')
;
```

次の例は同じ情報を示していますが、2018 年の取引に限定し、すべての購入者が請求額を支払ったと仮定しています。

```
SELECT sum(amount) FROM billing_event
WHERE
  invoice_date between '2018-01-01' and '2018-12-31'
  and balance_impacting = 1
  and action in ('INVOICED','FORGIVEN')
;
```

## 例 5: 支払い額
<a name="data-feed-example-query-disbursements"></a>

支払われた金額を確認するには、次の例に示すようなクエリを実行できます。

```
select sum(amount) FROM billing_event
WHERE
  action ='DISBURSED'
  and transaction_type like 'DISBURSEMENT%'
;
```

## 例 6: 保留中の支払い金額
<a name="data-feed-example-query-pending-disbursement"></a>

保留中の支払い金額を確認するには、次の例に示すようなクエリを実行できます。このクエリでは、支払い済みの金額を除外します。

```
SELECT sum(amount) FROM billing_event targeted 
WHERE
   (transaction_type like 'SELLER_%'  -- what is invoiced on behalf of SELLER
    or transaction_type like 'AWS_REV_%'  -- what is owed to AWS
    or transaction_type = 'BALANCE_ADJUSTMENT' -- exceptionnal case
   ) 
  -- DISBURSEMENT action records will "negate" 'INVOICED'
  -- but do not take into account failed disbursements
   AND 
    (not exists
      (select 1 
        from billing_event disbursement
          join billing_event failed_disbursement
           on disbursement.billing_event_id=failed_disbursement.parent_billing_event_id
        where
         disbursement.transaction_type='DISBURSEMENT'
         and failed_disbursement.transaction_type='DISBURSEMENT_FAILURE'
         and targeted.disbursement_billing_event_id=disbursement.billing_event_id
      )
    ) 
;
```

同じ情報を取得する別の方法としては、次の例に示すようなクエリを実行して販売者の残高を取得します。

```
SELECT sum(amount) FROM billing_event
WHERE
 balance_impacting = 1
;
```

次のクエリでは、この例を拡張します。クエリ結果を 2018 年の取引に限定し、これらの取引に関する追加の詳細を返します。

```
select sum(residual_amount_per_transaction)
from
 (SELECT
    max(billed_invoices.amount) invoiced_amount,
    sum(nvl(disbursed_invoices.amount,0)) disbursed_amount,
    -- Exercise left to the reader:
    -- use transaction_type to distinguish listing fee vs seller-owed money
    -- still pending collection
    max(transaction_type) transaction_type,
    max(billed_invoices.amount) 
      + sum(nvl(disbursed_invoices.amount,0)) residual_amount_per_transaction
  FROM billing_event billed_invoices
    -- find related disbursements
    left join billing_event disbursed_invoices
      on disbursed_invoices.action='DISBURSED'
      and disbursed_invoices.parent_billing_event_id=billed_invoices.billing_event_id
  WHERE
    billed_invoices.invoice_date between '2018-01-01' and '2018-12-31'
    and billed_invoices.transaction_type like 'SELLER_%' -- invoiced on behalf of SELLER
    and billed_invoices.action in ('INVOICED','FORGIVEN')
    -- do not take into account failed disbursements
    AND not exists
      (select 1 from billing_event failed_disbursement
       where disbursed_invoices.disbursement_billing_event_id = failed_disbursement.parent_billing_event_id
      )
   GROUP BY billed_invoices.billing_event_id
);
```

## 例 7: 一連の請求書の残高
<a name="data-feed-example-query-balance-invoice-set"></a>

一連の請求書の合計額を確認するには、次の例に示すようなクエリを実行できます。

```
SELECT invoice_id, sum(amount) FROM billing_event targeted
WHERE
  -- invoice_id is only not null for invoiced records AND disbursed records 
  -- linking them to related disbursement -> no need to filter more precisely
  invoice_id in ('XXX','YYY') 
  -- filter out failed disbursements 
  AND not exists
      (select 1 
        from billing_event disbursement
          join billing_event failed_disbursement
           on disbursement.billing_event_id=failed_disbursement.parent_billing_event_id
        where
         disbursement.transaction_type='DISBURSEMENT'
         and failed_disbursement.transaction_type='DISBURSEMENT_FAILURE'
         and targeted.disbursement_billing_event_id=disbursement.billing_event_id
      ) 
  group by invoice_id;
```

# 日次使用状況データフィード
<a name="data-feed-daily-usage"></a>

このデータフィードは、顧客の使用状況メトリクス、推定収益、料金の詳細など、製品の詳細な毎日の使用状況情報を提供します。このデータは、顧客が製品をどのように使用しているかを追跡し、使用状況パターンに基づいて推定収益を計算するのに役立ちます。

日次使用状況データフィードは 24 時間ごとに更新されます。

次の表は、データフィードの項目を一覧表示し、説明しています。


| 列 | [Description] (説明) | 
| --- | --- | 
| valid\$1from | 主キーの値が他のフィールドの値に関連して有効である最初の日付。 | 
| insert\$1date | レコードがデータフィードに挿入された日付。 | 
| update\$1date | レコードが最後に更新された日付。 | 
| delete\$1date | レコードがソフト削除された日付。 | 
| usage\$1feed\$1id | 使用状況レコードの一意の識別子。これは、レコードの一意性を維持しながらデータプライバシーを確保する、販売者ごとのソルトハッシュです。 | 
| usage\$1date | 時間コンポーネントを含まないお客様の使用日。使用量は日ごとに集計されるため、時間は省略されます。 | 
| product\$1id | 製品のフレンドリ ID。Account、Billing\$1Event、および Offer\$1Product データフィードの`product_id`フィールドに結合するために使用できます。 | 
| agreement\$1id | 契約の一意の識別子。存在する場合、これは常に で始まります`agmnt-`。このフィールドは null であるか、対応する請求書明細項目と一致しない場合があります。 | 
| end\$1user\$1account\$1id | 実際に製品を使用したアカウント。エンドユーザーのアカウントのグローバル一意識別子 (GUID) で表されます。アカウントデータフィードに参加するために使用できます。これは販売者ごとのソルトハッシュであり、未加工の AWS アカウント ID ではありません。 | 
| payer\$1account\$1id | 支払者のアカウントのグローバル一意識別子 (GUID) で表される、製品の使用に対して支払うことが予想されるアカウント。アカウントデータフィードに参加するために使用できます。これは販売者ごとのソルトハッシュであり、未加工の AWS アカウント ID ではありません。 | 
| リージョン | 購入者の使用が発生した AWS リージョン。 | 
| dimension\$1key | オファーの公開時に販売者が設定したディメンションキー。 | 
| usage\$1unit | 使用量単位の分類。使用量測定のタイプを記述します。 | 
| usage\$1quantity | 請求レコードに関連付けられた AWS サービスまたは使用タイプの使用値。値は小数点以下 2 桁まで指定します。 | 
| pricing\$1currency | 推定収益の通貨。 | 
| estimated\$1revenue\$1in\$1pricing\$1currency | `usage_rate_per_unit` および を使用して計算された推定収益`usage_quantity`。値は小数点以下 2 桁まで指定します。リセラーオファーの使用状況の ISV ビューでは、これを収益配分の割合で乗算する必要があります。 | 
| recipient\$1account\$1id | フィードでデータを受信している販売者のアカウント。 | 
| offer\$1id | オファーのフレンドリ ID。これは、利用可能な場合、購入契約の offer\$1id と一致します。オファーおよびオファーターゲットデータフィードに参加するために使用できます。一貫性を保つため、このフィールドは常に null ではありません。 | 
| usage\$1rate\$1per\$1unit\$1in\$1pricing\$1currency | を検証`usage_quantity`するために で乗算できる単位あたりの使用率`estimated_revenue_in_pricing_currency`。値は小数点以下 6 桁まで指定します。 | 
| charge\$1item\$1description | 料金項目の完全な説明。通常は、使用ベースの料金の offer\$1term\$1description\$1region\$1dimension\$1description としてフォーマットされます。 | 

## 日次使用状況データフィードの例
<a name="daily-usage-feed-example"></a>

キー列を含む日次使用状況データフィードの例を次に示します。読みやすいように、一部の列は表示されません。


| usage\$1date | product\$1id | agreement\$1id | リージョン | dimension\$1key | usage\$1unit | usage\$1quantity | pricing\$1currency | estimated\$1revenue\$1in\$1pricing\$1currency | offer\$1id | usage\$1rate\$1per\$1unit\$1in\$1pricing\$1currency | charge\$1item\$1description | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| 2025-01-15 | prod-abcd1234efgh5678 | agmnt-wxyz9876abcd5432 | us–east–1 | USE1\$1InputTokenCount | 単位 | 24.00 | USD | 12.00 | offer-mnop5432qrst7890 | 0.50000 | AWS Marketplace ソフトウェアの使用\$1us-east-1\$1百万の入力トークン | 
| 2025-01-15 | prod-ijkl9876mnop1234 | agmnt-stuv5432wxyz9876 | us-west-2 | USE1\$1InputTokenCount | 単位 | 1000.00 | USD | 5.50 | offer-abcd9876efgh5432 | 0.005500 | AWS Marketplace ソフトウェアの使用\$1us-west-2\$1API コール | 

# レガシーマッピングデータフィード
<a name="data-feed-legacy-mapping"></a>

このデータフィードは、製品 ID とオファー ID をレガシーのグローバル一意識別子 (GUID) にマッピングする方法を示します。レガシー GUIDs は古いレポートで使用され、新しい IDsはデータフィードと AWS Marketplace APIsで使用されます。

このデータフィードは、登録販売者として作成したすべての製品と、再販が許可されているすべての製品に関する情報を提供します。

レガシーマッピングデータフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。


| [列名]  | 説明  | 
| --- | --- | 
| mapping\$1type | 製品 ID とオファー ID のいずれであるかを示します。 | 
| legacy\$1id | この製品またはオファーのレガシー ID。 | 
| new\$1id | この製品またはオファーのわかりやすい ID。この ID は、現在のすべての API アクションで主キーとして使用されます。 | 

## レガシーマッピングデータフィードの例
<a name="data-feed-legacy-mapping-sample-data"></a>

レガシーマッピングデータフィードの例は次のとおりです。見やすいように、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| mapping\$1type | legacy\$1id  | new\$1id | 
| --- | --- | --- | 
| OFFER | 8a806c74-dbd6-403e-9362-bb08f417ff37 | offer-dacpxznflfwin | 
| PRODUCT | 1368541d-890b-4b6c-9bb9-4a55306ab642 | prod-o4grxfafcxxxy | 
| OFFER | 558d8382-6b3a-4c75-8345-a627b552f5f1 | offer-gszhmle5npzip | 



# オファーデータフィード
<a name="data-feed-offer"></a>

オファーデータフィードは、登録販売者として作成したすべてのオファーに関する情報を提供します。1 つのオファーに複数のリビジョンがある場合、すべてのリビジョンがデータフィードに含まれます。

オファーリビジョンを作成し、公開フィールドのデータが変わると、同じプライマリキー (`offer_id` プラス `offer_revision`) データフィードに新しいレコードが作成されます。ただし、`valid_from` フィールドの値は異なります。データフィードの履歴列の詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。

オファーデータフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表には、データフィードの列の名前と説明が示されています。


| [列名]  | 説明  | 
| --- | --- | 
| offer\$1id | オファーのわかりやすい識別子。`Offer_Product` データフィードの `offer_id` フィールドへの結合に使用できます。 | 
| offer\$1revision | オファーリビジョン。このフィールドと offer\$1id フィールドを組み合わせて主キーを形成します。`offer_id` では、`Target_Offer` データフィードの `offer_id` と `offer_revision` フィールドの結合に使用できます。 | 
| name | 販売者が定義したオファー名。 | 
| expiration\$1date | オファーの有効期限が切れる日時。 | 
| opportunity\$1name | このオファーにリンクされた営業案件データ。オファーが AWS の営業案件にバインドされている場合、このフィールドは入力済みです。 | 
| opportunity\$1description | このオファーにリンクされているすべての説明情報。オファーが AWS の営業案件にバインドされている場合、このフィールドは入力済みです。 | 
| seller\$1account\$1id | 販売者のアカウントのグローバル一意識別子 (GUID)。アカウントデータフィードの account\$1id フィールドと結合するために使用できます。 | 
| opportunity\$1id | 機会の ID は、リセラーが製品を販売している場合にのみ入力されます。製品が同じであれば、異なるチャネルパートナー (または販売者) が作成したオファーにはすべて同じ opportunity\$1id があります。 | 
| recipient\$1account\$1id | フィードでデータを受信している販売者のアカウント。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 

## オファーデータフィードの例
<a name="data-feed-offer-sample-data"></a>

オファーデータフィードの例は次のとおりです。見やすいように、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| offer\$1id  | offer\$1revision | 名前 | expiration\$1date | opportunity\$1name | opportunity\$1description | seller\$1account\$1id | opportunity\$1id | 
| --- | --- | --- | --- | --- | --- | --- | --- | 
| offer-dacpxznflfwin | 1 | エンタープライズ契約プログラムオファー | 9999-01-01T00:00:00Z |  |  |  |  | 
| offer-gszhmle5npzip | 1 | 販売者が作成したプライベートオファー | 2020-10-31T00:00:00Z |  |  |  |  | 
| offer-hmzhyle8nphlp | 1 | エンタープライズ契約プログラムオファー | 9999-01-01T00:00:00Z |  |  |  |  | 

# オファー製品データフィード
<a name="data-feed-offer-product"></a>

1 つのオファーには複数の製品を含めることができ、1 つの製品は複数の異なるオファーに含めることができます。このデータフィードは、オファーと製品との関係に関する情報を示します。

このデータフィードは、登録販売者として作成したすべての製品オファーに関する情報を提供します。

オファーに対して製品を追加または削除した場合は、オファーリビジョンを作成できます。

オファー製品データフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。データフィードの履歴列の詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| 列名  | 説明  | 
| --- | --- | 
| offer\$1id | このオファーのわかりやすい識別子。`Offer` データフィードの `offer_id` フィールドへの結合に使用できます。 | 
| offer\$1revision | offer\$1id フィールドと組み合わせて、オファーリビジョンへの外部キーを形成します。 | 
| product\$1id | 製品のわかりやすい識別子。これは、このオファーで公開する製品への外部キーです。`Product` データフィードの `product_id` フィールドへの結合に使用できます。 | 

## オファー製品データフィードの例
<a name="data-feed-offer-product-sample-data"></a>

オファー製品データフィードの例は次のとおりです。


| offer\$1id  | offer\$1revision | product\$1id | 
| --- | --- | --- | 
| offer-dacpxznflfwin | 10 | prod-o4grxfafcxxxx | 
| offer-gszhmle5npzip | 24 | prod-o4grxfafcxxxy | 

# オファーターゲットデータフィード
<a name="data-feed-offer-target"></a>

このデータフィードは、登録販売者として作成したすべてのオファーに関するオファーのリビジョンのターゲットを示します。1 つのオファーに複数のリビジョンがある場合、すべてのリビジョンがデータフィードに含まれます。

オファーリビジョンを作成し、公開フィールドのデータが変わると、別のレコードがデータフィードに作成されます。このレコードの主キー (`offer_id` プラス `offer_revision`) は同じですが、`valid_from` フィールドの値は異なります。

オファーターゲットデータフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。


| 列名  | 説明  | 
| --- | --- | 
| offer\$1target\$1id | フィードの主キー。 | 
| offer\$1id\$1offer\$1revision | オファーの識別子とリビジョン。これら 2 つの列は、このターゲットに関連するオファーを参照します。`Target`データフィードの `offer_id` および `offer_revision` フィールドへの結合に使用できます。 | 
| target\$1type | オファーの受取人が BuyerAccounts (プライベートオファーを示す) であるか、ParticipatingPrograms であるかを示します。 | 
| polarity | オファーが `target_type` を対象にしているかどうかを示します。指定できる値は次のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-offer-target.html)  | 
| 値 | ターゲットを表す文字列 (AWS アカウント ID またはオファーで使用できるプログラム)。例: [AWS Marketplace の標準契約 (SCMP)](standardized-license-terms.md#standard-contracts)、または [AWS Marketplace フィールドデモンストレーションプログラム (FDP)](field-demonstration-program.md)。 | 

## オファーターゲットデータフィードの例
<a name="data-feed-offer-target-sample-data"></a>

オファーターゲットデータフィードの例を次に示します。見やすいように、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| offer\$1target\$1id  | offer\$1id  | offer\$1revision | target\$1type | polarity | 値 | 
| --- | --- | --- | --- | --- | --- | 
| 925ddc73f6a373b7d5544ea3210610803b600 | offer-dacpxznflfwin | 1 | ParticipatingPrograms | PositiveTargeting | EnterpriseContract | 
| 471ff22ae3165278f1fb960d3e14517bcd601 | offer-gszhmle5npzip | 1 | ParticipatingPrograms | PositiveTargeting | FieldDemonstration | 
| 511ff22adfj65278f1fb960d3e14517bcd6e602 | offer-gszhmle5npzip | 1 | ParticipatingPrograms  | PositiveTargeting | EnterpriseContract | 

# 製品データフィード
<a name="data-feed-product"></a>

このデータフィードは、登録販売者として作成したすべての製品と、再販が許可されているすべての製品に関する情報を提供します。

製品データは変更可能です。つまり、次のいずれかのフィールドの値を変更すると、`valid_from` フィールドの値が異なる別のレコードがデータフィードに作成されます。データフィードの履歴列の詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。

製品データフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

以下の表では、データフィードの列の名前と説明を示しています。


| 列名  | 説明  | 
| --- | --- | 
| product\$1id | 製品のわかりやすい識別子。`Account`、`Billing_Event`、`Offer_Product` データフィードの `product_id` フィールドと結合するために使用できます。 | 
| manufacturer\$1account\$1id | 製品の所有者の識別子。これは、[アカウント](data-feed-account.md)データフィードへの外部キーです。`Account` データフィードの `account_id` フィールドへの結合に使用できます。 | 
| product\$1code | 製品の計測に使用される、権利が付与された既存の製品コード。この値は、データをレポートに結合する場合や、AWS Marketplace Metering Service で提供される情報を参照する場合にも使用されます。 | 
| title | 製品のタイトル。 | 

## 製品データフィードの例
<a name="data-feed-product-sample-data"></a>

オファーターゲットデータフィードの例を次に示します。見やすいように、データの履歴列は表示していません。データの履歴フィールドの詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| product\$1id  | manufacturer\$1account\$1id  | product\$1code | title | 
| --- | --- | --- | --- | 
| prod-o4grxfafcxxxx | 555568000000 | product\$1code\$11 | Product1 | 
| prod-t3grxfafcxxxy | 444457000000 | product\$1code\$12 | Product2 | 
| prod-x8faxxfafcxxy | 666678000000 | product\$1code\$13 | Product3 | 

# 税品目データフィード
<a name="data-feed-tax-item"></a>

このデータフィードは、顧客請求書の税額計算に関する情報を提供します。

特定の顧客請求書 (`invoice_id`) の特定の製品 (`product_id`) に対して複数の明細行品目 (`line_item_id`) が存在する場合があり、顧客請求書は各税務管轄区域に 1 つ以上存在する場合があります。これは、例えば、異なる AWS エンティティ (米国とアイルランドなど) によって異なる AWS リージョンルールを使用しているお客様の使用量ベースの請求で発生します。が売上に対して消費税、VAT、または GST を AWS 徴収し、AWS, Inc. の名でそのような税金を現地の税務当局に送金する場所の詳細については、[「Amazon Web Service Tax Help](https://aws.amazon.com/tax-help/)」を参照してください。

税品目データフィードは 24 時間ごとに更新されるため、新しいデータを毎日利用できます。

税項目データはイミュータブルです。

以下の表では、データフィードの列の名前と説明を示しています。データの履歴列の詳細については、「[データの履歴化](data-feed-details.md#data-feed-historization)」を参照してください。


| [列名]  | 説明  | 
| --- | --- | 
| tax\$1item\$1id | 税品目レコードの一意の識別子。 | 
| invoice\$1id |  AWS 請求書 ID。この値と product\$1id の値を組み合わせて、関連する税金請求イベントを検索できます。 | 
| line\$1item\$1id | 顧客請求明細項目の一意の識別子。返金取引の明細項目 ID は先渡し取引税のものと同じです。 | 
| customer\$1bill\$1id | 顧客請求書の一意の識別子。購入者は、この識別子を販売者と共有し、税額計算に関する質問を特定して解決できます。 | 
| tax\$1liable\$1party | `AWS` または `Seller` です。販売者が納税義務者である場合は、税金が徴収されます。 AWS が納税義務者である場合、消費税は によって徴収および送金されます AWS。詳細については、「[AWS Marketplace Sellers & Tax Collection](https://aws.amazon.com/tax-help/marketplace)」を参照してください。 徴税しない場合、ここには値が表示されません。販売者は、徴税の義務があるため、請求書ごとに徴税されたかどうかを確認する必要があります。 | 
| transaction\$1type\$1code | 取引のタイプ。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-tax-item.html) 返金取引の明細項目 ID は元の先渡し取引のものと同じです | 
| product\$1id | 製品の外部キー。`product_id`フィールドの `Product` データフィードへの結合に使用できます。 | 
| product\$1tax\$1code | 製品の税プロパティを識別するための標準コード。販売者は、製品の作成時または変更時にプロパティを選択します。 | 
| invoice\$1date | 請求書が作成された日付。 | 
| taxed\$1customer\$1account\$1id | 課税対象の取引先企業エンティティの外部キー。`account_id`フィールドの `Account` データフィードへの結合に使用できます。 | 
| taxed\$1customer\$1country | 税額計算に使用する住所の ISO 3166 alpha 2 の国別コード。 | 
| taxed\$1customer\$1state\$1or\$1region | 税額計算に使用する州、区、郡。 | 
| taxed\$1customer\$1city | 税額計算に使用する市。 | 
| taxed\$1customer\$1postal\$1code | 税額計算に使用する郵便番号。 | 
| tax\$1location\$1code\$1taxed\$1jurisdiction | 課税場所に関連付けられている頂点ジオコード。 | 
| tax\$1type\$1code | 取引に適用される税のタイプ。指定できる値は、None、Sales および SellerUse です。 | 
| jurisdiction\$1level | 納税地に使用される住所の管轄区域。指定できる値は、State、County、City、District です。 | 
| taxed\$1jurisdiction | 税務管轄区域の名前。 | 
| display\$1price\$1taxability\$1type | 購入者に料金を税込みで表示するか、税抜きで表示するか。すべての AWS Marketplace サービスには税金は含まれていません。 | 
| taxable\$1amount | 該当する管轄区域レベルで課税対象となる取引金額。 | 
| nontaxable\$1amount | 該当する管轄区域レベルで非課税となる取引金額。 | 
| tax\$1jurisdiction\$1rate | 該当する管轄区域レベルで適用される税率。 | 
| tax\$1amount | 該当する管轄区域レベルで請求される税額。 | 
| tax\$1currency | 上記の金額に関する ISO 4217 alpha 3 の通貨コード。 | 
| tax\$1calculation\$1reason\$1code | 取引が課税対象となるか、非課税となるか、免除とされるか、ゼロ評価済みであるかを管轄区域別に整理したもの。 | 
| date\$1used\$1for\$1tax\$1calculation | 取引の税金の計算に使用される日付。 | 
| customer\$1exemption\$1certificate\$1id | 免除証明書の証明書 ID。 | 
| customer\$1exemption\$1certificate\$1id\$1domain | Amazon システム上の証明書の保存先。 | 
| customer\$1exemption\$1certificate\$1level | 免除を提供した管轄区域。 | 
| customer\$1exemption\$1code | 免税を指定するコード (RESALE など)。 | 
| customer\$1exemption\$1domain | 顧客の免税情報 (ある場合) をキャプチャするために使用する Amazon システム。 | 
| transaction\$1reference\$1id | 以下のレポートのデータを相互参照できる識別子。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/data-feed-tax-item.html)  | 
| legal\$1amount | 支払う税金の法定通貨での税額。 | 
| legal\$1currency | 支払う税金の法定通貨。 | 
| tax\$1invoice\$1id | 二重請求の場合の税金明細の税金請求書識別子。統合請求シナリオでは、このフィールドは null になります。 | 
| tax\$1invoice\$1date | 税金請求書の日付。統合請求シナリオでは、このフィールドは null になります。 | 

**注記**  
2021 年 8 月 5 日以降、 AWS Marketplace 売上に対する国際 Marketplace ファシリテーター税は税項目データフィードに入力されます。つまり、2021 年 8 月 5 日以降、請求イベントデータフィードのすべての AWS\$1TAX\$1SHARE レコードと SELLER\$1TAX\$1SHARE レコードは、税項目データフィードに対応するレコードを持つことが予想されます。

## 税品目データフィードの例
<a name="data-feed-tax-item-sample-data"></a>

税品目データフィードの例を次に示します。この情報は、データフィードの単一のテーブルに表示されます。見やすいように、ここではデータを複数のテーブルに表示し、一部の列を省略しています。


| tax\$1item\$1id | invoice\$1id | line\$1item\$1id | customer\$1bill\$1id | 
| --- | --- | --- | --- | 
| 6p2ni6tu041xagvhbyanbgxl3xameha16txjoav\$10001 | 781216640 | 71000000000000000000 | 2210000000000000000 | 
| 6p2ni6tu041xagvhbyanbgxl3xameha16txjoav\$10002 | 781216640 | 53000000000000000000 | 2210000000000000000 | 
| flr4jobxjzww8czdsrq4noue2uxd56j39wxw0k7\$10001 | 250816266 | 76400000000000000000 | 5720000000000000000 | 
| gfkjjobxjzw56jgkrsrqgjtk52uxd56j39wgj567d\$10002 | 280336288 | 76400000000000000000 | 5724390000000000000 | 
| wwk1qpvb8ran3geiw8e3mp6dgs2qj7wpkuwhgk1\$10001 | 451431024 | 99300000000000000000 | 1230000000000000000 | 
| wwk1qpvb8ran3geiw8e3mp6dgs2qj7wpkuwhgk1\$10002 | 451431024 | 99300000000000000000 | 3120000000000000000 | 
| fnohdid8kwgqq9lvii2k30spn3ftgwihbe8h75x\$10001 | 229987654 | 92100000000000000000 | 6390000000000000000 | 




| tax\$1liable\$1party | transaction\$1type\$1code | product\$1id | product\$1tax\$1code | invoice\$1date | 
| --- | --- | --- | --- | --- | 
| 販売者 | AWS | prod-o4grxfafcxxxx | AWSMP\$1SOFTWARE\$1RA | 2018-12-31T00:00:00Z | 
| 販売者 | AWS | prod-o4grxfafcxxxx | AWSMP\$1SOFTWARE\$1RA | 2018-12-31T00:00:00Z | 
| 販売者 | AWS | prod-t3grxfafcxxxy | AWS\$1REMOTE\$1ACCESS\$1SOFTWARE | 2018-08-31T00:00:00Z | 
| 販売者 | REFUND | prod-t3grxfafcxxxy | AWS\$1REMOTE\$1ACCESS\$1SOFTWARE | 2018-08-31T00:00:00Z | 
| 販売者 | AWS | prod-x8faxxfafcxxy | AWS\$1REMOTE\$1ACCESS\$1SOFTWARE | 2018-08-31T00:00:00Z | 
| 販売者 | TAXONLYREFUND | prod-x8faxxfafcxxy | AWS\$1REMOTE\$1ACCESS\$1SOFTWARE | 2018-05-31T00:00:00Z | 
| AWS | AWS | prod-wghj8xfafrhgj | AWS\$1REMOTE\$1ACCESS\$1SOFTWARE | 2019-07-31T00:00:00Z | 




| taxed\$1customer\$1account\$1id | taxed\$1customer\$1country | taxed\$1customer\$1state\$1or\$1region | taxed\$1customer\$1city | taxed\$1customer\$1postal\$1code | 
| --- | --- | --- | --- | --- | 
| VIeGa2t9j3MuxioH9wc8lsndXXCgGCGUreeXriocM5 | 米国 | GA | MILTON | 48573-4839 | 
| VIeGa2t9j3MuxioH9wc8lsndXXCgGCGUreeXriocM5 | 米国 | GA | MILTON | 48573-4839 | 
| 7nyo5jwTRoPlyX81vx9ji04eEwTurO1Ff8biQi88W8 | 米国 | NC | DURHAM | 27517-4834 | 
| 7nyo5jwTRoPlyX81vx9ji04eEwTurO1Ff8biQi88W8 | 米国 | NC | DURHAM | 27517-4834 | 
| 7nyo5jwTRoPlyX81vx9ji04eEwTurO1Ff8biQi88W8 | 米国 | TX | NOT APPLICABLE | 75844-1235 | 
| 7nyo5jwTRoPlyX81vx9ji04eEwTurO1Ff8biQi88W8 | 米国 | TX | HOUSTON | 75844-1235 | 
| 192a0421313e41f069b52962ed7babf716291b688 | 米国 | CT | NEW HAVEN | 06002-2948 | 




| tax\$1location\$1code\$1taxed\$1jurisdiction | tax\$1type\$1code | jurisdiction\$1level | taxed\$1jurisdiction | display\$1price\$1taxability\$1type | taxable\$1amount | nontaxable\$1amount | 
| --- | --- | --- | --- | --- | --- | --- | 
| 460473664 | セールス | State | GA | 除外 | 100 | 0 | 
| 66301164 | セールス | County | FULTON | 除外 | 0 | 100 | 
| 692938178 | SellerUse | State | NC | 除外 | 58.1 | 523.8 | 
| 692938178 | SellerUse | State | NC | 除外 | -58.1 | 523.8 | 
| 356794387 | セールス | State | TX | 税抜き | 1105.14 | 0 | 
| 528887443 | セールス | City | HOUSTON | 除外 | -36 | 0 | 
| 171248162 | セールス | State | CT | 除外 | 0 | 114.55 | 




| tax\$1jurisdication\$1rate | tax\$1amount | tax\$1currency | tax\$1calculation\$1reason\$1code | date\$1used\$1for\$1tax\$1calculation | 
| --- | --- | --- | --- | --- | 
| 0.206 | 20.6 | USD | 課税対象 | 2018-10-31T00:00:00Z | 
| 0 | 0 | USD | 非課税 | 2018-10-31T00:00:00Z | 
| 0.1 | 5.8 | USD | 課税対象 | 2018-07-31T00:00:00Z | 
| 0.1 | -5.8 | USD | 課税対象 | 2018-07-31T00:00:00Z | 
| 0.06 | 66.3 | USD | 課税対象 | 2018-07-31T00:00:00Z | 
| 0.01 | -0.36 | USD | 非課税 | 2018-07-31T00:00:00Z | 
| 0 | 0 | USD | 免税 | 2019-06-30T00:00:00Z | 



# 補足レポート
<a name="supplementary-reports"></a>

AWS Marketplace は[AWS Marketplace の販売者配信データフィード](data-feed-service.md)、 を通じて、販売者の AWS Marketplace 出品に関連付けられた AWS Marketplace 販売者アカウント ID に接続されている販売者所有の Amazon S3 アカウントに補足レポートを提供します。詳細については、「[Amazon Simple Storage Service バケットを作成する](https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed-service.html#data-feed-accessing)」を参照してください。

補足レポートは、前日に新しいサブスクライバーがいた場合、毎日 16:00 UTC に発行されます。これらのレポートは、前日の 13:59 UTC から翌日の 16:01 UTC までの期間を対象としています。

## 契約詳細レポート
<a name="agreement-details-report"></a>

契約詳細レポートは、Software as a Service (SaaS) の無償トライアルを利用している顧客をサポートするのに役立ちます。レポートには、サブスクライバー名、サブスクライバー ID、オファー ID、契約開始、契約終了日などの契約の詳細が含まれます。

該当する情報が使用可能な場合にのみ、このレポートを受け取ります。受け取るべきと思われるレポートが届かない場合は、[AWS Marketplace Seller Operations](https://aws.amazon.com/marketplace/management/contact-us/) チームまでお問い合わせください。

このレポートには、 AWS Marketplace Seller Account ID に関連付けられた Amazon S3 バケットからアクセスできます。

次の表は、契約詳細レポートの列名と説明をまとめたものです。


**SaaS 契約無料トライアルレポートデータ**  

| 名前 | 説明 | 
| --- | --- | 
| vendor\$1display\$1name | 製品を販売したベンダーの名前。 | 
| vendor\$1aws\$1account\$1id | 製品を販売したベンダーの ID。 | 
| subscriber\$1aws\$1account\$1id | 製品にサブスクライブ AWS アカウント されている に関連付けられた ID。 | 
| customer\$1id | ソフトウェア製品の一意の識別子。 | 
| product\$1title | 製品のタイトル。 | 
| offer\$1id | 購入者が署名したオファーの識別子。 | 
| offer\$1visibility | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるかの表示。 | 
| reseller\$1name | チャネルパートナーリセラーの名前。 | 
| reseller\$1aws\$1account\$1id | チャネルパートナーリセラー用の一意の識別子。 | 
| agreement\$1id | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| agreement\$1acceptance\$1date | 契約が受諾された日付。 | 
| agreement\$1start\$1date | 契約の開始日。 | 
| agreement\$1end\$1date | 契約の終了日。従量制/従量課金制/サブスクリプションの場合は、9999 年 1 月 1 日に設定されます。 | 
| is\$1free\$1trial\$1offer | オファーまたは契約が無料トライアルオファーかどうかを示すフラグ。 | 
| is\$1upgraded\$1after\$1free\$1trial | 契約が有料契約にアップグレードされたかどうかを示すフラグ。 | 
| total\$1contract\$1value | 契約の総額。 | 

# 販売者ダッシュボード
<a name="dashboards"></a>

AWS Marketplace は、[Amazon Quick](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) を利用したダッシュボードに、財務、売上、マーケティングデータへのアクセスと分析に役立つグラフ、グラフ、インサイトを提供します。販売者ダッシュボードには以下が含まれます。

**[財務業務用ダッシュボード](finance-operations.md)**
+ [請求済み収益ダッシュボード](billed-revenue-dashboard.md) - 会計やその他の財務報告の目的で請求された収益に関する情報を提供します。
+ [回収と支払いダッシュボード](collections-disbursement-dashboard.md) – 前回の支払い以降に銀行口座に AWS 回収および支払われた資金に関する情報を提供します。
+ [税ダッシュボード](taxation-dashboard.md) – 販売者トランザクションの税金に関する情報を提供します。

**[販売業務用ダッシュボード](sales-operations.md)**
+ [契約および更新ダッシュボード](agreements-renewals-dashboard.md) – AWS Marketplaceで契約に署名してから 24 時間以内に、契約と更新に関する情報が表示されます。
+ [使用状況ダッシュボード](usage-dashboard.md) - SaaS およびサーバー使用量ベースの製品を使用しているお客様に、視覚化ときめ細かなデータを提供します。
+ [マーケティング用ダッシュボード](marketing-dashboards.md) - マーケティングデータの追跡に役立つ複数のダッシュボードが用意されています。

**[マーケティング用ダッシュボード](marketing-dashboards.md)**
+ [顧客契約ダッシュボード](customer-agreements-dashboard.md) – 契約と製品をサブスクライブする顧客に関するデータを提供します。
+ [出品パフォーマンスダッシュボード](listing-performance-dashboard.md) – AWS Marketplace リスト内のトラフィックとユーザー動作に関するデータを提供します。
+ [検索パフォーマンスダッシュボード](search-performance-dashboard.md) – AWS Marketplace 出品に適用されたキーワードに関するデータを提供します。

ダッシュボードは、適切なアクセス許可を持つ AWS Marketplace 販売者が利用できます。

## ダッシュボードへのアクセス
<a name="reports-accessing"></a>

デフォルトでは、販売者アカウントの AWS Marketplace システム管理者は、 のインサイトタブのすべてのダッシュボードにアクセスできます AWS Marketplace 管理ポータル。システム管理者は AWS Identity and Access Management 、 (IAM) ポリシーを作成して、販売会社の他のユーザーに特定のダッシュボードへのアクセスを提供できます。

**注記**  
2023 年 9 月には、従来の IAM 権限で有効になっていた出品者ダッシュボードへのアクセスはサポートされなくなります。以下のコード例の新しい Amazon リソースネーム (ARN) 形式を使用して IAM 許可を更新してください。

ポリシーの作成の詳細については、「[IAM ポリシーの作成](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)」を参照してください。

### ダッシュボードポリシー
<a name="dashboard-policy"></a>

ダッシュボードの一部またはすべてへのアクセスを提供するには、次のいずれかのポリシーを使用します。

次の例では、ダッシュボードやレポートなど、現在および将来の AWS Marketplace リソースへのアクセスを提供します。現在および将来のすべてのデータフィードを使用します。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "aws-marketplace:GetSellerDashboard"
            ],
            "Resource": [
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/*"
            ]
        }
    ]
}
```

------

ARN を含めて、1 つ以上のダッシュボードへのアクセスを提供することもできます。次の例は、すべてのダッシュボードへのアクセスを提供する方法を示しています。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "aws-marketplace:GetSellerDashboard"
            ],
            "Resource": [
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/BillingEvent_V1/Dashboard/BilledRevenue_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/BillingEvent_V1/Dashboard/CollectionsAndDisbursements_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/Agreement_V1/Dashboard/AgreementsAndRenewals_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/Usage_V1/Dashboard/Usage_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/TaxItem_V1/Dashboard/Tax_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/Marketing_V1/Dashboard/CustomerAgreements_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/Marketing_V1/Dashboard/ListingPerformance_V1",
                "arn:aws:aws-marketplace::111122223333:AWSMarketplace/ReportingData/Marketing_V1/Dashboard/SearchPerformance_V1"
            ]
        }
    ]
}
```

------

ダッシュボードへのアクセスを削除するには、ポリシーの `Resource` セクションから削除します。

**注記**  
 AWS Identity and Access Management (IAM) ポリシーの作成の詳細については、*AWS Identity and Access Management 「 ユーザーガイド*」の[「IAM ポリシーの作成](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)」を参照してください。

# 財務業務用ダッシュボード
<a name="finance-operations"></a>

AWS Marketplace では、財務データの追跡に役立つ複数のダッシュボードが用意されています。

**Topics**
+ [請求済み収益ダッシュボード](billed-revenue-dashboard.md)
+ [回収と支払いダッシュボード](collections-disbursement-dashboard.md)
+ [税ダッシュボード](taxation-dashboard.md)

# 請求済み収益ダッシュボード
<a name="billed-revenue-dashboard"></a>

請求済み収益ダッシュボードには、 AWS Marketplaceのすべての請求済み売上に関する情報が表示されます。請求済み収益ダッシュボードを用いてレポートを作成すると時間の節約となり、[従来の月次請求収益レポート](https://docs.aws.amazon.com/marketplace/latest/userguide/monthly-billed-revenue-report.html)よりも約 45 日早くレポートを入手できます。従来の月次請求収益レポートは毎月 15 日に配信されるため、前月の請求額の確認が遅れます。

このダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインして、**[インサイト]**、**[財務オペレーション]**、**[請求収益]** タブの順に選択します。

**Topics**
+ [請求済み収益ダッシュボードの更新頻度](#publication-schedule)
+ [セクション 1: コントロール](#billed-revenue-dashboard-controls)
+ [セクション 2: フィルター](#section-2-invoice-date-range)
+ [セクション 3: 主要なメトリクス](#section-3-metrics)
+ [セクション 4: トレンド](#section-3-metrics)
+ [セクション 5: 内訳](#section-4-breakdowns)
+ [セクション 6: 詳細なデータ](#section-5-new-product-subscribers)

## 請求済み収益ダッシュボードの更新頻度
<a name="publication-schedule"></a>

ダッシュボードは、UTC の午前 0 時に毎日更新されます。請求書が、UTC の午前 0 時*前*の 5 月 10 日に作成された場合、5 月 11 日の更新が請求書に表示されます。請求書が、UTC の午前 0 時*後*の 5 月 10 日に作成された場合、5 月 12 日の更新が請求書に表示されます。アップストリームシステムから受信した最新の請求データまたは支払いデータが遅延した場合、最新のデータがダッシュボードに反映されるまでに 1～2 日かかる場合があります。

予想される顧客請求書が表示されない場合は、 AWS Marketplace ビジネス開発担当者に連絡する前に、次の手順を使用します。

**請求済み収益ダッシュボードの顧客請求書が見つからない場合のトラブルシューティング方法**

1. まず次の 1 つ以上のツールを使用して、顧客がオファーを受け入れたことを確認します。
   + [AWS Marketplace イベントの通知](https://docs.aws.amazon.com/marketplace/latest/userguide/notifications.html)
   + [AWS Marketplace 管理ポータル 契約タブ](https://docs.aws.amazon.com/marketplace/latest/userguide/private-offers-upgrades-and-renewals.html#private-offers-upgrades-and-renewals-process)

1. (プライベートオファーの場合) 顧客がオファーを受け入れたことを確認したら、オファーの請求書のスケジュールと金額を確認します。
   + プライベートオファーについては、 AWS Marketplace 管理ポータル **オファー**タブを確認してください。
   + チャネルパートナーのプライベートオファーについては、 AWS Marketplace 管理ポータル **パートナー**タブをチェックして、パートナーオポチュニティ内のカスタム支払いスケジュールを表示します。

1. 取引において、前月の使用分を毎月 2 日と 3 日に顧客に請求する[使用量料金モデル](https://docs.aws.amazon.com/marketplace/latest/userguide/pricing.html#usage-pricing)が指定されているかどうかを確認してください。

## セクション 1: コントロール
<a name="billed-revenue-dashboard-controls"></a>

請求済み収益ダッシュボードの本セクション内には、同ダッシュボードのデータを絞り込むためのフィルターがあります。たとえば、[AWS Marketplace イベントの通知](https://docs.aws.amazon.com/marketplace/latest/userguide/notifications.html)からフィールドのフィルターを選択して、特定の顧客アカウント ID、サブスクライバーの会社名、またはオファー ID の請求を確認できます。また、ビジュアルに含める日付範囲などを設定できるフィルターを分析に追加することも可能です。セクション内で選択済みのフィルターにより、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。

フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

### コントロールの記述
<a name="control-descriptions"></a>


| コントロール名 | 説明 | 
| --- | --- | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの会社名  | 製品をサブスクライブしているアカウント名。 | 
| 製品のタイトル | 製品のタイトル。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| AWS 登録販売者 | 取引を促進した事業体の識別子。可能な値は以下のとおりです:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/billed-revenue-dashboard.html) | 
| 支払者 AWS アカウント ID | 料金の請求先となるアカウントの ID。 | 
| 支払人の会社名 | 料金の請求先となるアカウントの商号。 | 
| リセラー会社 |  ソフトウェア製造元の製品の販売を許可されているリセラーアカウントの商号。  | 
| リセラー AWS アカウント ID | ISV から卸売で製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 再販承認 ID | 登録された機会の一意の識別子。 | 
| 再販承認名 | 登録された機会の一意の名前。 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられている 2 文字の国コード。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある州または地域 | 
| 取引リファレンス ID |  AWS Marketplace レガシーレポート間でトランザクションを関連付けるのに役立つトランザクションの一意の識別子。 | 

## セクション 2: フィルター
<a name="section-2-invoice-date-range"></a>

ダッシュボードの本セクションには、オファーの通貨と請求日付範囲に基づいてレコードを絞り込めるフィルターがあります。請求日付範囲を使用すると、請求日が指定された日付より前か後か、日付範囲内かを選択できます。選択したフィルターは、メトリック、傾向、内訳および詳細データセクションで表示されるデータを更新します。デフォルトの請求日付範囲は、過去 6 か月のデータを取り込むように設定されています。

## セクション 3: 主要なメトリクス
<a name="section-3-metrics"></a>

ダッシュボードのこのセクションでは、主要業績評価メトリクス (KPI) が表示され、選択したフィルターを使用した主な請求済み収益の数値を視覚的に比較できます。指定した請求日付範囲と通貨における総収益、返金総額、出品料金、卸売コスト (該当する場合)、販売者純収益の KPI が表示されます。フィルター条件を更新すると、さまざまな通貨と日付のメトリクスを表示できます。

## セクション 4: トレンド
<a name="section-3-metrics"></a>

ダッシュボードの本セクションには、指定した日付範囲の請求済み収益のトレンドが表示されます。日ごと、前月比ごと、四半期ごと、前年比ごとなど、指定した日付の集計別にトレンドを表示して、請求済み収益に関するインサイトを得ることができます。請求済み収益のトレンド情報は、集計レベル、またはオファーの表示タイプ別に確認できます。
+ **請求トレンド** - 日付集計フィルターから選択した日付範囲における総収益、販売者純収益、卸売コスト (該当する場合) 返金額の推移のスナップショットを表示します。
+ **オファーの可視性別の請求トレンド** - [プライベートオファー](https://docs.aws.amazon.com/marketplace/latest/userguide/private-offers-overview.html)、パブリックオファー (またはセルフサービス)、エンタープライズプログラムにおけるオファー数と総収益の推移のスナップショットを、オファーの可視性タイプ別に表示します。

## セクション 5: 内訳
<a name="section-4-breakdowns"></a>

ダッシュボードの本セクションには、サブスクライバー、登録販売者、サブスクライバーの地域、製品のタイトルにわたるビジネスに関する主要なメトリクスが表示されます。総収益、支払人数、サブスクライバー数、総返金額、出品手数料、販売者純収益、卸売コストでフィルタリングできます。

## セクション 6: 詳細なデータ
<a name="section-5-new-product-subscribers"></a>

ダッシュボードのこのセクションには、製品の時間単位、年単位、または月単位の使用に対して が顧客に AWS 請求する合計金額を含む、すべての請求済み売上が表示されます。 は、次の 3 つの頻度で顧客に AWS 請求します。
+ サブスクリプションの承認日 (前払い請求)
+ カスタム支払いスケジュール (柔軟な支払いスケジューラによって作成されたプライベートオファー)
+ 前月の使用量に対する当月の 2 日目と 3 日目の従量制使用量

**注記**  
2021 年 4 月 1 日より前に作成された請求書には、関連する契約 ID、オファー ID、サブスクライバー AWS アカウント ID、またはサブスクライバー会社名がない場合があります。

顧客への請求は、顧客に請求されてから 24 時間後に、本詳細データセクションに表示されます。例えば、11 月 3 日に顧客に請求が行われた場合、ダッシュボードには 11 月 4 日に同請求書が表示されます。クイックテーブルからデータをエクスポートおよびダウンロードする方法の詳細については、*「 クイックユーザーガイド*[」の「ビジュアルからのデータのエクスポート](https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html)」を参照してください。

### 詳細なデータの説明
<a name="billed-revenue-dashboard-granular-data"></a>


| 列 | 説明 | 
| --- | --- | 
| 請求書日付 | 製品サブスクリプションの料金を顧客に請求した日付。 | 
| 支払期日 | YYYY-MM-DD 形式の支払期日。 | 
| 支払い条件 | 顧客の AWS請求書の支払い条件。 | 
| 請求書 ID | 料金が請求された AWS 請求書に割り当てられた AWS ID。 | 
| 出品料金の請求書 ID |  AWS EMEA SARL、日本、またはオーストラリアの法人 (登録販売者) を通じて AWS Marketplace サブスクリプションが取引される場合、販売者は販売者出品料金に付加価値税 (VAT) を請求し、税準拠の請求書を提出する必要があります。該当する取引において出品料金に課される VAT の請求書 ID は、ソフトウェアまたは製品のサブスクリプション請求書 ID とは異なります。AWS, Inc. からのトランザクションの値は「MISSING\$1LISTING\$1FEE\$1Invoice\$1ID」となります。これは、出品料金の請求書 ID が適用されないためです。 | 
| 卸売請求書 ID | チャネルパートナープライベートオファー (CPPO) で ISV とチャネルパートナー間の販売を表す支払い不可能な請求書に割り当てられた AWS ID。パブリックオファーと Marketplace プライベートオファー (MPO) の場合、このフィールドは「該当なし」になります。 | 
| 販売者発行の請求書 ID | 販売者が AWS に発行する請求書。 | 
| 販売者が発行した請求書バリアント | invoice\$1id 列に対応する請求書の種類。可能な値は以下のとおりです:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/billed-revenue-dashboard.html) | 
| サブスクライバーの会社名 | 製品をサブスクライブしているアカウント名。 | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの E メールドメイン | 製品をサブスクライブしているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが liu-jie@example.com の場合、エントリは example.com です。 | 
| サブスクライバーの市町区村 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の市町区村。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある都道府県 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある国  | 
| サブスクライバーの郵便番号 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の郵便番号。 | 
| 製品のタイトル | 製品のタイトル。 | 
| オファー名 | 販売者が定義したオファー名。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| 契約開始日 | 顧客の製品サブスクリプションの開始日 (MM-DD-YYYY) 形式。将来の日付の契約の場合、この日付は受理日とは異なる場合があります。 | 
| 契約受理日 | 顧客が製品をサブスクライブした日付 (MM-DD-YYYY 形式)。 | 
| 契約終了日 | 契約の有効期限が終了する日付 (MM-DD-YYYY 形式)。従量制/従量制料金サブスクリプションの場合、この日付は 9999 年 1 月 1 日に設定されます。 | 
| 契約期間タイプ | 契約の作成時にアクセプタが関連し、承諾する条件のタイプ。 | 
| 使用期間終了日 | 製品の使用期間終了日。 | 
| 使用期間開始日 | 製品の使用期間開始日。 | 
| 支払いステータス |  AWS が銀行口座に資金、一部、または全部を支払っていないことを確認する請求書に関連付けられたステータス。ステータスには、支払い済み、一部支払い済み、失敗、未支払いが考えられます。 | 
| 支払日 | 販売者の銀行への支払い AWS が開始された日付。 | 
| 支払いリファレンス番号 | 支払いの場合、支払いリファレンス番号は、各支払いリクエストを作成する AWS と によって生成されます。支払いリファレンス番号は、販売者の銀行提供の預金通知とレポートを AWS Marketplace レポートの請求書に関連付けるために使用できます。 | 
| 銀行への支払いのトレース ID | 銀行への支払いの場合、トレース ID は銀行によって割り当てられます。支払い銀行トレース ID を使用して、販売者の銀行提供の預金通知とレポートを AWS Marketplace レポートの請求書に関連付けることができます。 | 
| 総収益 | 顧客に請求される製品の従量課金額または月額料金。 | 
| 総返金 | データカバレッジ期間中に返金が処理された場合に顧客に払い戻されるサブスクリプション費用の合計金額。 | 
| 出品料金 | 請求額から差し引かれる AWS Marketplace 料金額。 | 
| 出品料の払い戻し | データカバレッジ期間中に返金が処理された場合に返金された AWS Marketplace 料金の一部。 | 
| 出品料金の割合 | 請求額から差し引かれる AWS Marketplace 料金の割合。 | 
| 販売者のタックスシェア | この取引で請求された米国の消費税と使用税の合計額 | 
| 販売者のタックスシェアの払い戻し | 返金が処理される場合にこの取引に対して払い戻される米国の消費税と使用税の合計金額。 | 
| AWS タックスシェア | 販売者の代理でこの取引で請求された米国の消費税と使用税の合計額。 | 
| AWS タックスシェア返金 | 返金が処理された場合に、このトランザクションに対して返金される米国の売上税および使用税の合計額 (出品者に代わってそのような税金が徴収されたとき)。 | 
| 卸売コスト | チャネルパートナーのプライベートオファーのみ。リセラーに請求される製品のコスト。例えば、リセラーが製造元の製品を販売したときに製造元に支払う金額などです。卸売コストは、希望小売り価格に割引率を掛けたものです。 | 
| 卸売コストの払い戻し | チャネルパートナーのプライベートオファーのみ。リセラーから返金された製品のコスト。 | 
| 卸売販売者タックスシェア | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合の、ISV とチャネルパートナー間の取引にかかる税額です。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売販売者のタックスシェア返金 | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合に、ISV とチャネルパートナー間の取引にかかる税金の返金額です。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売の他の販売者のタックスシェア | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合の、ISV とチャネルパートナー間の取引にかかる税額です。このフィールドは、取引に関与するもう一方の販売者に納税義務がある場合に入力されます。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売の他の販売者のタックスシェアの返金 | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合に、ISV とチャネルパートナー間の取引にかかる税金の返金額です。このフィールドは、取引に関与するもう一方の販売者に納税義務がある場合に入力されます。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売 AWS 税配分 | が課税対象となるチャネルパートナープライベートオファー (CPPO) での ISV とチャネルパートナー間の販売に対する AWS 税金。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売 AWS 税配分の返金 |  AWS が課税対象となるチャネルパートナープライベートオファー (CPPO) での ISV とチャネルパートナー間の販売に対する税金の返金。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 販売者の純収益 | 取引に対して請求される合計金額。 AWS Marketplace 料金、返金、米国の消費税と使用税を差し引いた額。 | 
| 回収純収益 | このトランザクションで AWS が購入者から正常に収集した合計金額。 | 
| 未回収純収益 | このトランザクションで AWS が購入者からまだ回収していない合計金額。 | 
| 最終収集日 | AWS が購入者からこのトランザクションの支払いを収集した最新の日時。 | 
| 通貨 | 取引の通貨。例えば、取引が US ドルの場合、エントリは USD です。 | 
| 取引リファレンス ID | トランザクションを表す一意の識別子。これを使用して、 AWS Marketplace レポート間でトランザクションを関連付けることができます。 | 
| AWS 登録販売者 |  取引を促進した事業体の識別子。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/billed-revenue-dashboard.html)  | 
| 再販承認 ID |  登録された機会の一意の識別子。  | 
| 再販承認名 | 登録された機会の一意の名前。 | 
| 再販承認の説明 | ISV の定義による登録済み機会の説明。 | 
| 再販会社名 | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウント名。 | 
| 支払者 AWS アカウント ID | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 支払人の E メールドメイン |  料金の請求先となるアカウントに関連付けられている E メールドメイン。例えば、E メールアドレスが liu-jie@example.com の場合、エントリは example.com です。  | 
| 支払人の市町区村 | ソフトウェア料金の請求先となるアカウントに関連付けられた請求先住所の市区町村。 | 
| 支払人の都道府県または地域 | 料金の請求先となるアカウントに関連付けられた請求先住所の都道府県。 | 
| 支払人の国 | 料金の請求先となるアカウントに関連付けられた 2 文字の国コード。 | 
| 支払人の郵便番号 |  ソフトウェア料金の請求先となるアカウントに関連付けられた請求先住所の郵便番号。  | 
| ISV アカウント ID | 製品またはサービスの所有者の識別子。 | 
| ISV の会社名 | 製品またはサービスの所有者の商号。 | 
| 製品 ID |  ソフトウェア製品のわかりやすい一意の識別子。  | 
| 支払済み純収益 |  販売者に支払われた取引の合計額 この金額が「販売者の純収益」と一致しない場合、これは部分的な支払いとなります。  | 
| 未支払いの純収益 |  販売者に支払われていない取引の合計額。金額が 0 以外の場合、顧客には未払い残高があることを意味します。  | 

# 回収と支払いダッシュボード
<a name="collections-disbursement-dashboard"></a>

回収と支払いダッシュボードでは、銀行口座に支払った資金に関する情報が提供されます。また、一部支払い、全額支払い、または支払いの失敗が発生したすべての請求書のリストも表示されます。このリストには、支払いが実行されていない請求書は含まれません。未払いの請求書を確認するには、**請求済み収益**ダッシュボードを使用します。

支払いには、製品のサブスクリプションに対する顧客の支払い、実行された返金、顧客に対して徴収または返金される税金が含まれます。返金は販売者による承認後に行われるため、ダッシュボード上の返金はマイナスの金額として表示されます。

回収と支払いダッシュボードを使用すると、顧客の支払いにすばやくアクセスできます。支払いが送信されてから 5 日後に作成される従来の[支払いレポート](https://docs.aws.amazon.com/marketplace/latest/userguide/monthly-disbursement-report.html)と比較して、約 4 日間の節約が見込まれます。

**注記**  
顧客の支払い条件は異なるため AWS、未回収の年齢カテゴリの一部の資金は顧客から支払われていない可能性があります。

回収と支払いダッシュボードには、運用プロセスと財務プロセスに関する情報が表示されます。ダッシュボードは毎日更新されます。詳細については、以下のトピックを参照してください。

ダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインし、**[インサイト]**、**[財務オペレーション]** を選択して、**[回収と支払い]** タブを選択します。

**Topics**
+ [回収と支払いダッシュボードの更新頻度](#publication-schedule)
+ [セクション 1: コントロール](#collections-disbursement-dashboard-controls)
+ [セクション 2: フィルター](#section-2-select-date-range)
+ [セクション 3: 主要なメトリクス](#section-3-metrics-collections)
+ [セクション 4: トレンド](#section-4-trends-collections)
+ [セクション 5: 内訳](#section-5-breakdowns)
+ [セクション 6: 詳細なデータ](#section-6-granular-data)

## 回収と支払いダッシュボードの更新頻度
<a name="publication-schedule"></a>

回収と支払いダッシュボードは、北米の営業日にのみ更新されます。支払い済みの請求書は、銀行に入金されてから 1 日以内に確認できます。

## セクション 1: コントロール
<a name="collections-disbursement-dashboard-controls"></a>

ダッシュボードの本セクション内には、ダッシュボードのデータを絞り込むためのフィルターがあります。たとえば、[AWS Marketplace イベントの通知](https://docs.aws.amazon.com/marketplace/latest/userguide/notifications.html)からフィールドのフィルターを選択して、特定の顧客アカウント ID、サブスクライバーの会社名、またはオファー ID の支払いを確認できます。また、支払いステータス別にフィルタリングして、自分に支払われたすべての請求書、または未払いの請求書を確認することもできます。ビジュアルに含める日付範囲などを設定できるフィルターを分析に追加することが可能です。セクション内で選択済みのフィルターにより、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。

フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

### コントロールの記述
<a name="control-descriptions-collections"></a>


| コントロール名 | 説明 | 
| --- | --- | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの会社名  | 製品をサブスクライブしているアカウント名。 | 
| 製品のタイトル | 製品のタイトル。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| AWS 登録販売者 | 取引を促進した事業体の識別子。可能な値は以下のとおりです:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/collections-disbursement-dashboard.html) | 
| 支払いステータス |  AWS が銀行口座に資金、一部、または全部を支払っていないことを確認する請求書に関連付けられたステータス。ステータスには、支払い済み、一部支払い済み、失敗、未支払いが考えられます。 | 
| 支払者 AWS アカウント ID | 料金の請求先となるアカウントの ID。 | 
| 支払人の会社名 | 料金の請求先となるアカウントの商号。 | 
| リセラー会社 |  ソフトウェア製造元の製品の販売を許可されているリセラーアカウントの商号。  | 
| リセラー AWS アカウント ID | ISV から卸売で製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 再販承認 ID | 登録された機会の一意の識別子。 | 
| 再販承認名 | 登録された機会の一意の名前。 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられている 2 文字の国コード。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある州または地域 | 
| 取引リファレンス ID |  AWS Marketplace レガシーレポート間でトランザクションを関連付けるのに役立つトランザクションの一意の識別子。 | 
| 銀行への支払いのトレース ID | 銀行への支払いの場合、トレース ID は銀行によって割り当てられます。銀行のトレース ID では、販売者の銀行が提供する入金通知や AWS Marketplace レポートをレポート内の請求書と関連付けることができます。 | 

## セクション 2: フィルター
<a name="section-2-select-date-range"></a>

ダッシュボードの本セクションは、オファーの通貨と 2 つの異なる日付ディメンション (日付フィールドの値が、指定日の前か後か、または日付範囲内か) に基づいてレコードを絞り込むフィルタについて説明しています。日付ディメンションは支払い期日または最終支払い日です。支払い日は、指定された日付範囲内に支払われる請求書に結果を制限します。支払期日には、支払日に関係なく、指定範囲内の支払い期限が記載された請求書が含まれます。日付カテゴリフィルターでは、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。デフォルトの日付カテゴリは最終支払い日で、過去 6 か月のデータを取得します。

## セクション 3: 主要なメトリクス
<a name="section-3-metrics-collections"></a>

ダッシュボードの本セクションには、主要業績評価メトリクス (KPI) が表示され、支払い済みおよび未支払いの収益を視覚的に比較できます。KPI は、指定されたフィルタ条件に基づいた総収益、純利益、卸売原価 (該当する場合)、支払額、未払額に対して表示されます。

## セクション 4: トレンド
<a name="section-4-trends-collections"></a>

ダッシュボードのこのセクションには、指定した日付範囲における支払いと延滞のトレンドが表示されます。日、月、四半期、年など、指定された日付集計で傾向を表示して、 AWS Marketplace コレクションの状態を把握できます。トレンドビューには、次のようなものが含まれます。
+ **支払いトレンド** - 支払いまでの平均日数とそれに関連する純収益のスナップショットが表示されます。このトレンドでは、請求日から支払い日までの日数を測定して、回収効率をレポートします。日付集計フィルターから日付範囲を選択できます。
+ **支払い済み金額の期間** - 標準期間の売掛金バケット (期限前、1～30 日、31～60 日など)で分類された純利益および支払い済み請求書数のスナップショットを提供します。トレンドでは、支払い期日と支払い日の間の日数を測定して、支払いが顧客の支払い条件の範囲内であったかどうかを報告します。
+ **未払い金額の期間** - 期日経過バケット (期限前、1～30 日、31～60 日など) で分類された、純収益、未対応請求書数や未支払い請求書数のスナップショットが表示されます。未払い資金には、期限を過ぎていない金額が含まれる場合があります。トレンドでは、本日の日付から支払期日までの日数を測定して、受取売掛金を表示します。

## セクション 5: 内訳
<a name="section-5-breakdowns"></a>

ダッシュボードのこのセクションには、オファー ID、製品のタイトル、支払者の会社名、サブスクライバーの会社名、リセラー名 (チャネルパートナーのプライベートオファーに参加している場合)、支払人の地域、サブスクライバーの地域ごとに、売掛金が表示されます。この内訳を使用して、各カテゴリの支払い済み売掛金と未払いの売掛金を比較します。

## セクション 6: 詳細なデータ
<a name="section-6-granular-data"></a>

ダッシュボードのこのセクションには、製品、顧客、オファーの詳細別に、すべての支払いと未回収額が表示されます。

**注記**  
2021 年 4 月 1 日より前に作成された請求書には、関連する契約 ID、オファー ID、サブスクライバー AWS アカウント ID、またはサブスクライバー会社名がない場合があります。

クイックテーブルからデータをエクスポートおよびダウンロードする方法については、*「 クイックユーザーガイド*[」の「ビジュアルからのデータのエクスポート](https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html)」を参照してください。

### 詳細なデータの説明
<a name="collections-dashboard-granular-data"></a>


| 列 | 説明 | 
| --- | --- | 
| 請求書日付 | 製品サブスクリプションの料金を顧客に請求した日付。 | 
| 支払期日 | YYYY-MM-DD 形式の支払期日。 | 
| 支払い条件 | 顧客の AWS 請求書の支払い条件。 | 
| 請求書 ID | 料金が請求された AWS 請求書に割り当てられた AWS ID。 | 
| 出品料金の請求書 ID |   AWS EMEA SARL、日本、またはオーストラリアの法人 (登録販売者) を通じて AWS Marketplace サブスクリプションが取引される場合、販売者の出品料金に VAT を請求するには、販売者のマーケットプレイスオペレーター ( AWS EMEA SARL など) が必要です。該当する取引において出品料金に課される VAT の請求書 ID は、ソフトウェアまたは製品のサブスクリプション請求書 ID とは異なります。  | 
| 卸売請求書 ID |  チャネルパートナープライベートオファー (CPPO) で ISV とチャネルパートナー間の販売を表す支払い不可能な請求書に割り当てられた AWS ID。パブリックオファーと Marketplace プライベートオファー (MPO) の場合、このフィールドは「該当なし」になります。  | 
| 販売者発行の請求書 ID | 販売者が AWS に発行する請求書。 | 
| 販売者発行の請求書バリアント | invoice\$1id 列に対応する請求書の種類。可能な値は以下のとおりです:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/collections-disbursement-dashboard.html) | 
| サブスクライバーの会社名 | 製品をサブスクライブしているアカウント名。 | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの E メールドメイン | 製品をサブスクライブしているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが liu-jie@example.com の場合、エントリは example.com です。 | 
| サブスクライバーの市町区村 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の市町区村。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある都道府県 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある国  | 
| サブスクライバーの郵便番号 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の郵便番号。 | 
| 製品のタイトル | 製品のタイトル。 | 
| オファー名 | 販売者が定義したオファー名。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| 契約開始日 | 顧客の製品サブスクリプションの開始日 (MM-DD-YYYY) 形式。将来の日付の契約の場合、この日付は受諾日とは異なる場合があります。 | 
| 契約終了日 | 契約の有効期限が終了する日付 (MM-DD-YYYY 形式)。従量制/従量制料金サブスクリプションの場合、この日付は 9999 年 1 月 1 日に設定されます。 | 
|  |  | 
| 契約受理日 | 顧客が製品をサブスクライブした日付 (MM-DD-YYYY 形式)。 | 
| 使用期間終了日 | 製品の使用期間終了日。 | 
| 使用期間開始日 | 製品の使用期間開始日。 | 
| 支払いステータス |  AWS が前回の支払い以降に資金を回収して銀行口座に支払ったことを確認する請求書に関連付けられたステータス。関連する請求書の支払い資金が回収され、支払いが完了しました。関連する未払請求書の資金は、回収も支払いも行われていません。 | 
| 支払日 | 販売者の銀行への支払い AWS が開始された日付。 | 
| 銀行への支払いのトレース ID | 銀行への支払いの場合、トレース ID は銀行によって割り当てられます。銀行トレース ID を使用して、販売者の銀行提供の預金通知とレポートを AWS Marketplace レポートの請求書に関連付けることができます。 | 
| 総収益 | 顧客に請求される製品の従量課金額または月額料金。 | 
| 総返金 | データカバレッジ期間中に返金が処理された場合に顧客に払い戻されるサブスクリプション費用の合計金額。 | 
| 出品料金 | 請求額から差し引かれる AWS Marketplace 料金額。 | 
| 出品料の払い戻し | データカバレッジ期間中に返金が処理された場合に返金された AWS Marketplace 料金の一部。 | 
| 出品料金の割合 | 請求額から差し引かれる AWS Marketplace 料金の割合。 | 
| 販売者のタックスシェア | この取引で請求された米国の消費税と使用税の合計額 | 
| 販売者のタックスシェアの払い戻し | 返金が処理される場合にこの取引に対して払い戻される米国の消費税と使用税の合計金額。 | 
| AWS タックスシェア出品料金 | マーケットプレイスオペレーター AWS として、販売者が行った売上に対して独自の名前で VAT を請求および徴収する必要があります。この金額は、 AWS Marketplace 販売者アカウントに請求される VAT の金額に対応します。 | 
| AWS タックスシェア返金出品料金 | マーケットプレイスオペレーター AWS として、販売者が行った販売に対して、独自の名前で VAT を返金する必要があります。この金額は、 AWS Marketplace 販売者アカウントに返金される VAT の金額に対応します。 | 
| 卸売コスト | チャネルパートナーのプライベートオファーのみ。リセラーに請求される製品のコスト。例えば、リセラーが製造元の製品を販売したときに製造元に支払う金額などです。卸売コストは、希望小売り価格に割引率を掛けたものです。 | 
| 卸売コストの払い戻し | チャネルパートナーのプライベートオファーのみ。リセラーから返金された製品のコスト。 | 
| 卸売販売者のタックスシェア | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合の、ISV とチャネルパートナー間の取引にかかる税額です。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売販売者のタックスシェア返金 | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合に、ISV とチャネルパートナー間の取引にかかる税金の返金額です。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売の他の販売者のタックスシェア | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合の、ISV とチャネルパートナー間の取引にかかる税額です。このフィールドは、取引に関与するもう一方の販売者に納税義務がある場合に入力されます。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売の他の販売者のタックスシェアの返金 | チャネルパートナー向けプライベートオファー (CPPO) において、販売者に納税義務がある場合に、ISV とチャネルパートナー間の取引にかかる税金の返金額です。このフィールドは、取引に関与するもう一方の販売者に納税義務がある場合に入力されます。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売 AWS 税配分 | が課税対象となるチャネルパートナープライベートオファー (CPPO) での ISV とチャネルパートナー間の販売に対する AWS 税金。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 卸売 AWS 税配分の返金 |  AWS が課税対象となるチャネルパートナープライベートオファー (CPPO) での ISV とチャネルパートナー間の販売に対する税金の返金。パブリックオファーと Marketplace プライベートオファー (MPPO) の場合、このフィールドは「該当なし」になります。 | 
| 販売者の純収益 | 取引に対して請求される合計金額。 AWS Marketplace 料金、返金、米国の消費税と使用税を差し引いた額。 | 
| 通貨 | 取引の通貨。例えば、取引が US ドルの場合、エントリは USD です。 | 
| 取引リファレンス ID | トランザクションを表す一意の識別子。これを使用して、 AWS Marketplace レポート間でトランザクションを関連付けることができます。 | 
| AWS 登録販売者 |  取引を促進した事業体の識別子。可能な値は以下のとおりです。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/collections-disbursement-dashboard.html)  | 
| 再販承認 ID |  登録された機会の一意の識別子。  | 
| 再販承認名 | 登録された機会の一意の名前。 | 
| 再販承認の説明 | ISV の定義による登録済み機会の説明。 | 
| リセラーの会社名 | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウント名。 | 
| リセラー AWS アカウント ID | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 支払人の会社名 | 料金の請求先となるアカウントの名前。 | 
| 支払者 AWS アカウント ID | 料金の請求先となるアカウントの ID。 | 
| 支払人の E メールドメイン |  料金の請求先となるアカウントに関連付けられている E メールドメイン。例えば、E メールアドレスが liu-jie@example.com の場合、エントリは example.com です。  | 
| 支払人の市町区村 | ソフトウェア料金の請求先となるアカウントに関連付けられた請求先住所の市区町村。 | 
| 支払人の都道府県または地域 | 料金の請求先となるアカウントに関連付けられた請求先住所の都道府県。 | 
| 支払人の国 | 料金の請求先となるアカウントに関連付けられた 2 文字の国コード。 | 
| 支払人の郵便番号 |  ソフトウェア料金の請求先となるアカウントに関連付けられた請求先住所の郵便番号。  | 
| ISV アカウント ID | 製品またはサービスの所有者の識別子。 | 
| ISV の会社名 | 製品またはサービスの所有者の商号。 | 
| 製品 ID |  ソフトウェア製品のわかりやすい一意の識別子。  | 
| 支払いステータス |  AWS が銀行口座に資金、一部、または全部を支払っていないことを確認する請求書に関連付けられたステータス。ステータスには、支払い済み、一部支払い済み、失敗、未支払いが考えられます。 | 
| 支払済み純収益 | 販売者に支払われた取引の合計額 この金額が「販売者の純収益」と一致しない場合、これは部分的な支払いとなります。 | 
| 未支払いの純収益 | 販売者に支払われていない取引の合計額。金額が 0 以外の場合、顧客には未払い残高があることを意味します。 | 
| 支払い期間 | 資金が収集される売掛金範囲を説明しているカテゴリー (期限前、1～30 日、31～60 日など)。 | 

# 税ダッシュボード
<a name="taxation-dashboard"></a>

税ダッシュボードは、 AWS Marketplaceでのトランザクションの米国税と国際税に関する視覚化データときめ細かなデータを提供します。

このダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインして、**[インサイト]**、**[マーケティング]** を選択し、**[リスティングパフォーマンス]** タブを選択します。

**Topics**
+ [税ダッシュボードの更新頻度](#publication-schedule)
+ [セクション 1: コントロール](#billed-revenue-dashboard-controls)
+ [セクション 2: 日付フィルター](#section-2-invoice-date-range)
+ [セクション 3: メトリクス](#section-3-metrics)
+ [セクション 4: トレンド](#section-3-metrics)
+ [セクション 5: 内訳](#section-4-breakdowns)
+ [セクション 6: 詳細なデータ](#section-5-new-product-subscribers)
+ [米国の免除コード](#us-exemption-code-key)
+ [EU 適用免除コード](#eu-exemption-codes)

## 税ダッシュボードの更新頻度
<a name="publication-schedule"></a>

ダッシュボードは毎日更新されます。アップストリームシステムからの最新のトランザクションデータが遅延した場合、最新のデータがダッシュボードに反映されるまでに 1～2 日かかる場合があります。

## セクション 1: コントロール
<a name="billed-revenue-dashboard-controls"></a>

ダッシュボードの本セクション内には、税データを絞り込むためのフィルターがあります。また、ビジュアルに含める日付範囲などを設定できるフィルターを分析に追加することも可能です。セクション内で選択済みのフィルターにより、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。

フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

### コントロールの記述
<a name="control-descriptions"></a>


| コントロール名 | 説明 | 
| --- | --- | 
| 請求書 ID  | 顧客に請求される料金に割り当てられた AWS ID。 | 
| 課税対象顧客 AWS アカウント ID | 製品サブスクリプションに課税されたアカウントの AWS ID。 | 
| AWS 登録販売者 | 取引を促進した事業体の識別子。 | 
| 課税対象顧客の国 | 課税対象顧客に関連付けられた 2 文字の国コード | 
| 課税対象顧客の州またはリージョン | 課税対象顧客に関連付けられた請求先住所の州またはリージョン。 | 
| 課税対象顧客の都市 | 課税対象顧客に関連付けられた請求先住所の都市 | 
| 課税対象 | 課税対象、非課税、税還付の対象となるソーストランザクション。 | 
| 納税義務者 |  `AWS` または `Seller` です。販売者が納税義務者である場合は、税金が徴収されます。 AWS が納税義務者である場合、消費税は によって徴収および送金されます AWS。詳細については、「[AWS Marketplace 出品者の税務ヘルプ](https://aws.amazon.com/tax-help/marketplace-sellers/)」を参照してください。 徴税しない場合、ここには値が表示されません。販売者は、徴税の義務があるため、請求書ごとに徴税されたかどうかを確認する必要があります。  | 
| 税タイプ | 取引に適用される税のタイプ。使用できる値は None、Sales、および SellerUse、Tax registration type、VAT (付加価値税)、CNPJ、IGST、CT です。 | 

## セクション 2: 日付フィルター
<a name="section-2-invoice-date-range"></a>

ダッシュボードの本セクションには、特定の期間中の請求書の日付に基づいてレコードを絞り込むためのフィルターがあります。請求書の日付が選択されたフィルターにより、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。例えば、日付フィルター `Past 30 days` を選択すると、すべてのセクションに過去 30 日以内に課税された請求書に関連するデータが反映されます。

## セクション 3: メトリクス
<a name="section-3-metrics"></a>

ダッシュボードのこのセクションには、課税額、非課税額、税額、課税された請求書の数、トランザクションの合計数など、税に関連するメトリクスを視覚化するための主要業績評価指標 (KPI) が表示されます。これらの**フィルター**セクションの使用日条件を更新して、日付範囲を更新できます。

## セクション 4: トレンド
<a name="section-3-metrics"></a>

ダッシュボードの本セクションには、指定した日付範囲の税のトレンドが表示されます。日ごと、前月比、前四半期比、前年比など、指定した日付の集計別にトレンドを表示して、税に関するインサイトを得ることができます。税に関する以下のトレンド情報を利用できます。
+ **税のトレンド - 金額** - 選択した期間の課税額と税金額の両方を、請求書日付別にスナップショットで表示します。
+ **税のトレンド - 請求書の数** - 選択した期間の請求書の数のスナップショットを、請求書の日付別に表示します。

## セクション 5: 内訳
<a name="section-4-breakdowns"></a>

ダッシュボードのこのセクションには、請求書 ID、税タイプ、製品タイトル、および顧客の地域別に、税メトリクスが表示されます。

## セクション 6: 詳細なデータ
<a name="section-5-new-product-subscribers"></a>

ダッシュボードのこのセクションには、 AWS Marketplaceでの組織のトランザクションの詳細な税金データが表示されます。

### 詳細なデータの説明
<a name="billed-revenue-dashboard-granular-data"></a>


| 列 | [Description] (説明) | 
| --- | --- | 
| 請求書 ID | 料金が請求された AWS 請求書に割り当てられた AWS ID。これは、購入者のコマーシャルインボイス、販売者の卸売請求書、または販売者の出品料金請求書です。 | 
| 出品料金の請求書 ID | 販売者出品料金と VAT が販売者に請求された請求書に割り当てられた AWS ID。ISV にのみ適用されます。 | 
| 明細項目 ID | 明細項目の一意の識別子。返金取引の明細項目 ID は先渡し取引税のものと同じです。 | 
| 顧客請求書 ID | 顧客請求書 ID | 
| 税金請求書 ID | 二重請求の場合の税金明細の税金請求書識別子。統合請求シナリオでは、このフィールドは null になります。 | 
| 税金請求書の日付 | 税金請求書の日付。統合請求シナリオでは、このフィールドは null になります。 | 
| 納税義務者  |  `AWS` または `Seller` です。販売者が納税義務者である場合は、税金が徴収されます。 AWS が納税義務者である場合、消費税は によって徴収および送金されます AWS。詳細については、「[AWS Marketplace 出品者の税務ヘルプ](https://aws.amazon.com/tax-help/marketplace-sellers/)」を参照してください。 徴税しない場合、ここには値が表示されません。販売者は、徴税の義務があるため、請求書ごとに徴税されたかどうかを確認する必要があります。  | 
| 取引タイプコード | 取引のタイプコード。値には以下のものが含まれます。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/taxation-dashboard.html)返金取引の明細項目 ID は元の先渡し取引のものと同じです | 
| 製品 ID | ソフトウェア製品のわかりやすい一意の識別子。 | 
| 製品のタイトル | 購入された製品の名前。 | 
| 製品税コード | 製品の税プロパティを識別するための標準コード。製品を作成または変更するときにプロパティを選択します。 | 
| 請求書日付 | 製品サブスクリプションの料金および税を顧客に請求した日付。 | 
| 課税対象顧客 AWS アカウント ID | 課税対象顧客の AWS アカウント ID。 | 
| 課税対象顧客の国 | 課税対象顧客に関連付けられた 2 文字の国コード | 
| 課税対象顧客の州またはリージョン | 課税対象顧客に関連付けられた請求先住所の州またはリージョン。 | 
| 課税対象顧客の都市 | 課税対象顧客に関連付けられた請求先住所の都市 | 
| 課税対象顧客の郵便番号 | 税額計算に使用する郵便番号。 | 
| 税タイプ | 取引に適用される税のタイプ。取り得る値は None、Sales、SellerUse、ax registration type、VAT、CNPJ、IGST、CT です。 | 
| 管轄区域 | 納税地に使用される住所の管轄区域。指定できる値は、State、County、City、District です。 | 
| 課税管轄 | 課税管轄地域の名前。 | 
| 表示価格課税タイプ | 顧客に表示される価格の課税タイプ。すべての AWS Marketplace サービスは排他的です。 | 
| 課税管轄地域の税率 | 管轄区域で適用される税率。 | 
| 課税額 | 管轄区域で課される税額。 | 
| 通貨 | 課税される通貨。例えば、取引が US ドルの場合、エントリは USD です。 | 
| 法的な課税額 | 管轄区域レベルにおいて課される法定通貨で表示される税額。 | 
| 法的な税通貨 | 課税される法定通貨で表示された通貨。 | 
| 税計算理由コード | 取引が課税対象となるか、非課税となるか、免除とされるか、ゼロ評価済みであるかを管轄区域別に整理したもの。 | 
| 税計算に使用された日付 | 取引の税金の計算に使用される日付。 | 
| 顧客の免除証明書 ID | 免除証明書の証明書 ID。 | 
| 顧客の免除証明書 ID ドメイン | 証明書が Amazon システムに保存されている場所。 | 
| 顧客の免除証明書レベル | 免除を提供した管轄区域。 | 
| 顧客の免除コード | 免税を指定するコード。例えば、RESALE。 | 
| 取引リファレンス ID |  AWS Marketplace レポート間でトランザクションを関連付けるのに役立つトランザクションの一意の識別子。 | 
| AWS 登録販売者 | 取引を促進した事業体の識別子。 | 
| 購入者請求書 ID | 購入者に請求された AWS 請求書に割り当てられた AWS ID。販売者は、卸売請求書または出品料金請求書を、対応する購入者への請求と関連付けることができます。 | 

**注記**  
合計税額と購入者の合計請求額は、[[請求済み収益ダッシュボード]](https://docs.aws.amazon.com/marketplace/latest/userguide/billed-revenue-dashboard.html) の **[AWS 税配分]** フィールドと **[総収益]** フィールドに移動しました。

## 米国の免除コード
<a name="us-exemption-code-key"></a>


| 免除コード | 説明 | 
| --- | --- | 
| 501C | 501C 組織 | 
| AP | 農業生産 | 
| CO | 慈善団体 | 
| DIRECT | 直接支払いの許可 | 
| DISTSBT | ディストリビューター | 
| DP | 国連/外交官 | 
| DV | 障害のある退役軍人 | 
| EDI | 教育機関 | 
| FG | 連邦政府 | 
| HCP | 医療プロバイダー | 
| HO | 病院 (非営利または州) | 
| INSUR | Insurance | 
| IPM | IPM | 
| LB | ライブラリ | 
| MPU | 複数のポイントオブユースの免除、デジタル製品/ソフトウェアの免除 | 
| NA | ネイティブアメリカン  | 
| NAI | ネイティブアメリカン個人 | 
| NP | 非営利組織 | 
| NPR | 非営利宗教組織 | 
| OT | その他 | 
| RESALE | リセラー | 
| SBE | 中小企業の免除 | 
| SLG | 州/地方自治体 | 

## EU 適用免除コード
<a name="eu-exemption-codes"></a>


| 免除コード | 説明 | 
| --- | --- | 
| SpecialOrg | VAT の請求が免除される組織。 | 
| SpecialZone | 非課税のエリア。 | 
| SplitPayment | 購入者は、請求書に記載されている付加価値税を税務当局に直接支払います。 | 

# 販売業務用ダッシュボード
<a name="sales-operations"></a>

AWS Marketplace には、販売データの追跡に役立つ複数のダッシュボードが用意されています。

**Topics**
+ [契約および更新ダッシュボード](agreements-renewals-dashboard.md)
+ [使用状況ダッシュボード](usage-dashboard.md)

# 契約および更新ダッシュボード
<a name="agreements-renewals-dashboard"></a>

このダッシュボードには、 AWS Marketplaceで契約に署名してから 24 時間以内に、契約と更新に関する情報が表示されます。このダッシュボードは、期限切れのサブスクリプションを追跡するのに役立ちます。

ダッシュボードを開くには、 を起動し AWS Marketplace 管理ポータル、**インサイト**タブを選択し、**セールスオペレーション**を選択します。

**Topics**
+ [セクション 1: コントロール](#agreements-renewals-dashboard-controls)
+ [セクション 2: 日付カテゴリの選択](#agreements-renewals-dashboard-select-date-category)
+ [セクション 3: メトリクス](#agreements-renewals-dashboard-metrics)
+ [セクション 4: サブスクリプションのトレンド](#agreements-renewals-dashboard-subscription-trends)
+ [セクション 5: 内訳](#agreements-renewals-dashboard-breakdowns)
+ [セクション 6: 詳細なデータ](#agreements-renewals-dashboard-granular-data)

## セクション 1: コントロール
<a name="agreements-renewals-dashboard-controls"></a>

このセクションには、契約および更新データを絞り込むためのフィルターがあります。以下のフィルターから選択できます。

**注記**  
フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

### コントロールの記述
<a name="agreements-renewals-dashboard-controls-descriptions"></a>


| コントロール名 | 説明 | 
| --- | --- | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの会社名 | 製品をサブスクライブしているアカウント名。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、またはエンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| CPPO フラグ |  チャネルパートナーのプライベートオファーを使用して契約が締結されたかどうかを示す「はい/いいえ」のフラグ。「はい」の場合、登録販売者がチャネルパートナーです。「いいえ」の場合、登録販売者はソフトウェアメーカー (独立系ソフトウェアベンダー) です。  | 
| ISV AWS アカウント ID |  製品またはサービスの所有者のアカウント。  | 
| ISV の会社名 |  製品またはサービスの所有者の商号。  | 
| レガシーの製品 ID | ソフトウェア製品のレガシーの一意の識別子。 | 
| 製品のタイトル | 製品のタイトル。 | 
| 再販承認 ID |  ISV がチャネルパートナーに提供した再販承認の ID。  | 
| 再販承認名 | ISV がチャネルパートナーに提供した再販承認の名前。 | 
| リセラー AWS アカウント ID | ISV から卸売で製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| リセラーの会社名 | ソフトウェア製造元の製品の販売を許可されているリセラーアカウントの商号。 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられている 2 文字の国コード。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある州または地域 | 
| サブスクライバーの市町区村 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の市町区村。 | 

## セクション 2: 日付カテゴリの選択
<a name="agreements-renewals-dashboard-select-date-category"></a>

ダッシュボードのこのセクションには、指定した日付範囲の契約終了日、契約終了期間、または契約開始日に基づいてレコードを絞り込むためのフィルターが用意されています。選択した日付カテゴリ内で選択したフィルターにより、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。

最近署名した契約書に関する情報は、契約開始日で絞り込むことができます。契約の更新について知りたい場合は、契約終了日を使用してフィルタリングできます。

## セクション 3: メトリクス
<a name="agreements-renewals-dashboard-metrics"></a>

ダッシュボードの本セクションには、主要業績評価メトリクス (KPI) が表示され、主要な契約データを視覚的に比較できます。有効な契約の数と終了した契約の数を示す KPI が表示されます。[日付カテゴリを選択] フィールドの日付条件を更新して、日付範囲を更新できます。

## セクション 4: サブスクリプションのトレンド
<a name="agreements-renewals-dashboard-subscription-trends"></a>

ダッシュボードの本セクションには、指定した日付範囲のサブスクリプションのトレンドが表示されます。日ごと、前月比ごと、四半期ごと、前年比ごとなど、指定した日付の集計別にトレンドを表示して、契約に関するインサイトを得ることができます。契約と更新のトレンド情報は集計されたレベルで確認できます。
+ **サブスクリプションのトレンド** - 選択した日付集計フィルターと選択した日付カテゴリフィルターに基づいて、有効な契約の数と終了した契約の数のスナップショットが表示されます。契約開始日のサブスクリプションのトレンドを表示するには、**[日付カテゴリを選択]** フィルターで**[契約開始日]** を選択します。契約終了日のサブスクリプションのトレンドを表示するには、**[日付カテゴリを選択]** フィルターで**[契約終了日]** を選択します。
+ **更新内訳** - 特定の日数内に終了した、または終了間近である更新のスナップショットが表示されます。1～30 日前、31～60 日前、または 61 日以上前に終了した契約など、複数の期間の更新内訳を表示できます。また、0～30 日、31～60 日というような期間以内に終了する、終了間近の契約を絞り込むこともできます。

## セクション 5: 内訳
<a name="agreements-renewals-dashboard-breakdowns"></a>

ダッシュボードのこのセクションには、アクティブなサブスクライバー、ISV、リセラーの会社名にわたるビジネス指標が表示されます。契約 ID、終了契約 ID、オファー ID、更新契約 ID、サブスクライバーの数を表示できます。

## セクション 6: 詳細なデータ
<a name="agreements-renewals-dashboard-granular-data"></a>

ダッシュボードのこのセクションには、契約、オファー、製品、契約の提案者、サブスクライバー、再販承認、リセラー、ISV に関する詳細なデータが表示されます。

**注記**  
クイックテーブルからデータをエクスポートおよびダウンロードする方法の詳細については、*「 クイックユーザーガイド*[」の「ビジュアルからのデータのエクスポート](https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html)」を参照してください。

### 詳細なデータの説明
<a name="agreements-renewals-dashboard-granular-data-descriptions"></a>


| 列 | [Description] (説明) | 
| --- | --- | 
| サブスクライバーの会社名 | サブスクライバーの会社の名前。 | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの E メールドメイン | 製品をサブスクライブしているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが liu-jie@example.com の場合、エントリは example.com です。 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある国 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある州または地域 | 
| サブスクライバーの市町区村 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の市町区村。 | 
| サブスクライバーの郵便番号 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の郵便番号。 | 
| 製品のタイトル | 製品のタイトル。 | 
| 製品 ID | ソフトウェア製品のわかりやすい一意の識別子。 | 
| レガシーの製品 ID | ソフトウェア製品のレガシーの一意の識別子。 | 
| オファー名 | 販売者が定義したオファー名。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、またはエンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| 契約開始日 | 顧客の製品サブスクリプションの開始日 (MM-DD-YYYY) 形式。将来の日付の契約の場合、この日付は受理日とは異なる場合があります。 | 
| 契約受理日 | 顧客が製品をサブスクライブした日付 (MM-DD-YYYY 形式)。 | 
| 契約終了日 | 契約の有効期限が終了する日付 (MM-DD-YYYY 形式)。従量制/従量制料金サブスクリプションの場合、この日付は 9999 年 1 月 1 日に設定されます。 | 
| ステータス | 契約の現在の状態。サポートされているステータスは次のとおりです。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/agreements-renewals-dashboard.html)  | 
| 契約期間タイプ |  契約の作成時にアクセプタが関連し、承諾する条件のタイプ。 | 
| 推定契約額 | 「契約総額」または「購入額」と呼ばれる契約の推定費用です。これは、SaaS、プロフェッショナルサービス、サーバー、契約または年間料金タイプなどの製品タイプに適用されます。 | 
| 通貨コード | 契約の推定費用に関連付けられたオファー料金の通貨です。 | 
| リセラーの会社名 | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウント名。 | 
| リセラー AWS アカウント ID | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 再販承認 ID | 登録された機会の一意の識別子。 | 
| 再販承認名 | 登録された機会の一意の名前。 | 
| 再販承認の説明 | ISV の定義による登録済み機会の説明。 | 
| CPPO フラグ | Quick の計算フィールド。 | 
| 契約の意図 | 現在の契約が、以前の agreement\$1id 列に入力された以前の契約の更新またはアップグレードである場合に入力されます。可能な値は以下のとおりです:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/agreements-renewals-dashboard.html) | 
| 以前の契約 ID | 本契約が更新またはアップグレードされた場合の契約リファレンス。 | 
| 次の契約 ID | 現在の契約が更新またはアップグレードされた場合の、次の契約の契約 ID。 | 
| 以前のオファー ID | 現在の契約が更新またはアップグレードされた場合の、以前の契約に関連付けられたオファー ID。 | 
| 次のオファー ID | 現在の契約が更新またはアップグレードされた場合の、次の契約に関連付けられたオファー ID。 | 
| 次の契約 ID の承認日 | 購入者が次の契約を承諾した日付。 | 
| 提案者 AWS アカウント ID | 製品またはサービスの所有者の識別子。 | 
| 提案者の会社名 | 製品またはサービスの所有者の商号。 | 
| ISV AWS アカウント ID | 販売者の AWS 識別子。 | 
| ISV の会社名 | 販売者のビジネス名。 | 
| 契約終了 (日単位) | QuickSight 内の計算フィールド。本日から契約が終了するまでの残り日数。 | 
| 契約終了期間 | Quick の計算フィールド。契約が終了するまでの期間。 | 

# 使用状況ダッシュボード
<a name="usage-dashboard"></a>

使用状況ダッシュボードは、SaaS およびサーバー使用状況ベースの製品を使用しているお客様に視覚化ときめ細かなデータを提供します。 AWS Marketplace 販売者は、このダッシュボードを使用して、使用状況ベースの製品全体の顧客消費を追跡し、製品サポート、料金設定、パブリックオファーからプライベートオファーへの変換、製品の中止を決定できます。このダッシュボードには、過去 6 か月間のデータが表示されます。この期間はローリングウィンドウです。

ダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインし、**[インサイト]**、**[セールスオペレーション]**、**[使用]** タブの順に選択します。

**注記**  
このダッシュボードには、オファー作成時に指定されたすべてのディメンションキーの使用状況が表示されます。例えば、Amazon マシンイメージ (AMI) 製品の場合、ディメンションキーはインスタンスタイプであり、価格が 0 USD の場合でも、オファーで指定されているすべてのインスタンスタイプがこのダッシュボードに表示されます。オファーの作成時に指定されていなかったディメンションの製品使用状況を確認するには、必要なディメンションを含むように製品を再公開することを検討します。

**米ドル以外のプライベートオファーに関する重要な注意事項**  
Usage Dashboard には、オファーの元の通貨 (JPY、EUR、GBP など) に関係なく、すべてのプライベートオファーの使用状況データが USD で表示されます。これは意図した動作です。AWS コストと使用状況レポート (CUR) は現在、米ドルのみで料金を報告しているためです。USD 以外の通貨でプライベートオファーを作成した場合は、次の点に注意してください。  
ダッシュボードのすべての使用状況メトリクスと見積りは USD で表示されます。
表示された USD 金額は、元のオファー通貨から変換されます。
実際の請求書と支払いには、プライベートオファーの元の通貨が反映されます。
正確な財務調整を行うには、Usage Dashboard の見積りのみに依存するのではなく、請求書を参照してください。

**Topics**
+ [使用状況ダッシュボードの更新頻度](#usage-publication-schedule)
+ [セクション 1: コントロール](#usage-dashboard-controls)
+ [セクション 2: フィルター](#section-2-invoice-date-range)
+ [セクション 3: メトリクス](#section-3-metrics)
+ [セクション 4: トレンド](#section-3-metrics)
+ [セクション 5: 内訳](#section-4-breakdowns)
+ [セクション 6: 詳細なデータ](#section-5-new-product-subscribers)

## 使用状況ダッシュボードの更新頻度
<a name="usage-publication-schedule"></a>

請求済み収益ダッシュボードは毎日午後 4 時 (UTC 時間の午前 0 時) に更新されます。使用状況データは上流のデータソースから受信されるため、遅延が発生する可能性があることに注意してください。使用日と使用状況報告日を参照して、使用がなされた時期を、ダッシュボード上で報告対象期間との対比で明確にすることができます。

## セクション 1: コントロール
<a name="usage-dashboard-controls"></a>

ダッシュボードの本セクション内には、使用状況データを絞り込むためのフィルターがあります。例えば、以下のフィルターから選択できます。

**注記**  
フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

### コントロールの記述
<a name="usage-control-descriptions"></a>


| コントロール名 | 説明 | 
| --- | --- | 
| エンドユーザー会社名 | 製品を使用しているアカウント名。 | 
| エンドユーザー AWS アカウント ID | 製品を使用しているアカウントの ID。 | 
| エンドユーザー国 | 製品を使用しているアカウントに関連付けられている 2 文字の国コード。 | 
| 製品のタイトル | 製品のタイトル。 | 
| 製品コード | 製品の計測に使用される、権利が付与された既存の製品コード。この値は、データをレポートに結合する場合や、 AWS Marketplace メータリングサービスで提供される情報を参照する場合にも使用されます。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファーの可視性 | オファーがパブリック、プライベート、エンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| ディメンションキー | 製品の使用状況に関連するリソースタイプ。ディメンションキーは SaaS およびサーバー使用量ベースの製品に適用されます。 | 
| サブスクライバーの会社名 | 製品をサブスクライブしているアカウント名。 | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられている 2 文字の国コード。 | 
| リセラーの会社名 | 製品製造元の製品の販売を認可されているリセラーアカウントの名前。 | 
| リセラー AWS アカウント ID | ISV から卸売で製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 再販承認 ID | ISV から卸売で製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| CPPO フラグ | チャネルパートナーのプライベートオファーを使用して契約が締結されたかどうかを示す「はい/いいえ」のフラグ。「はい」の場合、登録販売者がチャネルパートナーです。「いいえ」の場合、記録上の販売者は製品製造元 (独立系ソフトウェアベンダー) です。 | 

## セクション 2: フィルター
<a name="section-2-invoice-date-range"></a>

ダッシュボードの本セクションには、使用日に基づいてレコードを絞り込むためのフィルターがあります。これらのフィルターで選択された値により、メトリクス、トレンド、内訳、詳細データセクションに表示されるデータが更新されます。デフォルトの選択では、過去 6 か月間の使用量のデータを取得するようになっています。

## セクション 3: メトリクス
<a name="section-3-metrics"></a>

ダッシュボードの本セクションには、推定使用単位数、使用のある顧客、使用量の多い製品などの、使用に関するメトリクスを視覚化する主要業績評価指標 (KPI) が表示されます。これらのフィルターセクションの使用日条件を更新して、日付範囲を更新できます。主要メトリクスにはすべての単位タイプのデータが表示されることに注意してください。

## セクション 4: トレンド
<a name="section-3-metrics"></a>

ダッシュボードの本セクションには、指定した日付範囲の使用状況のトレンドが表示されます。日ごと、前月比、前四半期比、前年比など、指定した日付の集計別にトレンドを表示して、使用状況に関するインサイトを得ることができます。また、使用単位タイプを選択して、その使用状況のトレンドをグラフィカルに表示することもできます。

## セクション 5: 内訳
<a name="section-4-breakdowns"></a>

ダッシュボードの本セクションには、会社名、製品名、ディメンションキー、選択した単位タイプのオファー ID についてのビジネスの推定使用状況メトリクスが表示されます。また、表示するエントリ数も選択できます。

## セクション 6: 詳細なデータ
<a name="section-5-new-product-subscribers"></a>

ダッシュボードの本セクションには、使用状況、オファー、製品、サブスクライバー、支払者、エンドユーザー、再販認可、リセラー、独立系ソフトウェアベンダー (ISV) に関する詳細なデータが表示されます。詳細データテーブルには、すべての単位タイプのデータが表示されることに注意してください。

月末に請求が確定するまでは、収益は推定値とみなす必要があります。使用料ベースの請求書は、当月分の使用量について、翌月の 2 日または 3 日に購入者に提示されます (例えば、11 月 1 日から 11 月 30 日までの使用量を計測した顧客には、12 月 2 日または 12 月 3 日に使用量の請求書が提示されます)。計測された使用量は、実際の使用日の数日後にこのダッシュボードに届く場合があるため、使用日と、使用量の報告日は異なる場合があります。つまり、当月の最新情報を把握するために、1 か月を通して毎日ダッシュボードにアクセスしなければならない場合があります。権威のある顧客請求情報については、**[財務業務]** タブの「[請求収益ダッシュボード](https://docs.aws.amazon.com/marketplace/latest/userguide/billed-revenue-dashboard.html)」を参照してください。

**注記**  
フィルタリングの詳細については、「 *クイックユーザーガイド*[」の「ビジュアルからのデータのエクスポート](https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html)」を参照してください。

### 詳細なデータの説明
<a name="billed-revenue-dashboard-granular-data"></a>


| 列 | 説明 | 
| --- | --- | 
| 使用日 | 顧客が製品を使用した日付。 | 
| 使用状況レポート日 | 顧客の製品使用状況がインサイトダッシュボードに表示された日付。 | 
| エンドユーザー会社名 | 製品を使用しているアカウント名。 | 
| エンドユーザー AWS アカウント ID | 製品を使用しているアカウントの ID。 | 
| エンドユーザー E メールドメイン | 製品を使用しているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが abc@example.com の場合、エントリは example.com です。 | 
| エンドユーザー市区町村 | 製品を使用したアカウントに関連付けられている市区町村。 | 
| エンドユーザーの都道府県またはリージョン | 製品を使用したアカウントに関連付けられていると都道府県または地域。 | 
| エンドユーザー国 | 製品を使用しているアカウントに関連付けられている 2 文字の国コード。 | 
| エンドユーザー郵便番号 | 製品を使用しているアカウントに関連付けられた請求先住所の郵便番号。 | 
| 製品のタイトル | 製品のタイトル。 | 
| レガシーの製品 ID | 製品のレガシーの一意の識別子。 | 
| 製品 ID | 製品のわかりやすい一意の識別子。 | 
| 製品コード | 製品の計測に使用される、権利が付与された既存の製品コード。この値は、データをレポートに結合する場合や、 AWS Marketplace Metering Serviceで提供される情報を参照する場合にも使用されます。 | 
| オファー ID | 購入者が署名したオファーの識別子。 | 
| オファー名 | 販売者が定義したオファー名。 | 
| オファーの可視性 | オファーがパブリック、プライベート、またはエンタープライズ契約オファーのいずれになるか。 | 
| オファーセット ID | オファーに関連付けられたオファーセットの識別子。 | 
| 契約 ID | 製品の使用を開始するために提案者と承諾者の間で締結された、契約書の一意の契約データフィードリファレンス。 | 
| 契約受理日 | 顧客が製品をサブスクライブした日時 (UTC) のタイムスタンプ。 | 
| 契約開始日 | 顧客の製品サブスクリプションが開始された日付 (UTC) のタイムスタンプ。将来の日付の契約の場合、この日付は受理日とは異なる場合があります。 | 
| 契約終了日 | 契約が失効する日付 (UTC)。計測制/従量制料金サブスクリプションの場合、この日付は 9999 年 1 月 1 日 12:00 AM に設定されます。 | 
| 契約期間タイプ | 契約の作成時にアクセプタが関連し、承諾する条件のタイプ。 | 
| ディメンションキー | 製品の使用状況に関連するリソースタイプ。ディメンションキーは SaaS およびサーバー使用量ベースの製品に適用されます。 | 
| リージョン | Amazon EC2 インスタンスを購入者がデプロイしたリージョン。 | 
| 推定使用量 | 製品について記録された使用量。 | 
| 使用単位タイプ | 使用量が記録される単位タイプ。 | 
| 単位あたりの使用率 | 単位あたりの使用率。 | 
| 請求項目の説明 | 料金の説明。 | 
| 予想収益 | 製品の使用量からの予想収益。月末に請求が確定するまでは、収益は推定値とみなす必要があります。使用量ベースの請求書は、当月分の使用量が、翌月の 2 日または 3 日に購入者に提示されます。 | 
| 通貨 | 取引の通貨。例えば、取引が米ドル建ての場合、エントリは USD です。 | 
| サブスクライバーの会社名 | 製品をサブスクライブしているアカウント名。 | 
| サブスクライバー AWS アカウント ID | 製品をサブスクライブしているアカウントの ID。 | 
| サブスクライバーの E メールドメイン | 製品をサブスクライブしているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが abc@example.com の場合、エントリは example.com です。 | 
| サブスクライバーの市町区村 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の市町区村。 | 
| サブスクライバーの州または地域 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある都道府県 | 
| サブスクライバーの国 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所がある国 | 
| サブスクライバーの郵便番号 | 製品をサブスクライブしているアカウントに関連付けられた請求先住所の郵便番号。 | 
| 支払人の会社名 | 製品の支払いを行っているアカウント名。 | 
| 支払者 AWS アカウント ID | 製品の支払いを行っているアカウントの ID。 | 
| 支払人の E メールドメイン | 製品の支払いを行っているアカウントに関連付けられた E メールドメイン。例えば、E メールアドレスが abc@example.com の場合、エントリは example.com です。 | 
| 支払人の市町区村 | 製品の支払いを行っているアカウントに関連付けられた請求先住所の市町区村。 | 
| 支払人の都道府県または地域 | 製品の支払いを行っているアカウントに関連付けられた請求先住所がある都道府県 | 
| 支払人の国 | 製品の支払いを行っているアカウントに関連付けられた請求先住所がある国 | 
| 支払人の郵便番号 | 製品の支払いを行っているアカウントに関連付けられた請求先住所の郵便番号。 | 
| リセラーの会社名 | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウント名。 | 
| リセラー AWS アカウント ID | ISV から卸売コストで製品またはサービスを購入して顧客に再販したアカウントの ID。 | 
| 再販承認 ID | 登録された再販オポチュニティの一意の識別子。 | 
| 再販承認名 | 登録された再販オポチュニティの一意の名前。 | 
| 再販承認の説明 | 登録された再販オポチュニティの説明。 | 
| CPPO フラグ | チャネルパートナーのプライベートオファーを使用して契約が締結されたかどうかを示す「はい/いいえ」のフラグ。「はい」の場合、登録販売者がチャネルパートナーです。「いいえ」の場合、記録上の販売者は製品メーカー (ISV) です。 | 
| ISV の会社名 | 製品またはサービスの所有者の名前。 | 
| ISV AWS アカウント ID |  製品またはサービスの所有者の識別子。 | 

# マーケティング用ダッシュボード
<a name="marketing-dashboards"></a>

AWS Marketplace には、マーケティングデータの追跡に役立つ複数のダッシュボードが用意されています。

**Topics**
+ [顧客契約ダッシュボード](customer-agreements-dashboard.md)
+ [出品パフォーマンスダッシュボード](listing-performance-dashboard.md)
+ [検索パフォーマンスダッシュボード](search-performance-dashboard.md)
+ [AWS ダッシュボードでの購入について](buy-with-aws-dashboard.md)

# 顧客契約ダッシュボード
<a name="customer-agreements-dashboard"></a>

顧客契約ダッシュボードには、 で製品をサブスクライブする契約と顧客の概要が表示されます AWS Marketplace。 ダッシュボードには、新規およびアクティブな契約に関するデータに加えて、顧客の傾向とプロファイルが表示されます。

**注記**  
このダッシュボードを解除するには、[AWS Marketplace Seller Prime](https://pages.awscloud.com/aws-marketplace-seller-prime.html) プログラムに登録する必要があります。
このダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインして、**[インサイト]**、**[マーケティング]** を選択し、**[顧客契約]** タブを選択します。

 AWS Marketplace ダッシュボードの使用の詳細については、このセクションの前半の[販売者ダッシュボード](dashboards.md)「」を参照してください。

**Topics**
+ [セクション 1: フィルター](#customer-agreements-filters)
+ [セクション 2: 日付フィルターの詳細](#customer-agreements-date-deep-dive)
+ [セクション 3:  パブリックオファー契約とプライベートオファー契約](#customer-agreements-public-private-agreements)
+ [セクション 4:  顧客メトリクス](#section-5-customer-metrics)

## セクション 1: フィルター
<a name="customer-agreements-filters"></a>

次のフィルターを使用すると、契約データを絞り込むことができます。


|  コントロール名  |  説明  | 
| --- | --- | 
|  製品のタイトル  |  製品のタイトル。 | 
|  日付フィルター  |  過去 30、60、90 日間のデータ、過去 12 か月 (TTM)、および年初来 (YTD) のデータが含まれます。[カスタム] を選択して、特定の開始日と終了日を定義します。 | 
|  顧客業界  |  販売者製品をサブスクライブした顧客に対して が AWS 定義する業界。 | 
|  顧客セグメント  |  販売者製品をサブスクライブした顧客に対して が AWS 定義するセグメント。顧客セグメントには以下が含まれます。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/marketplace/latest/userguide/customer-agreements-dashboard.html)  | 

フィルタリングの詳細については、*「Amazon Quick User Guide*[」の「Filtering data on Quick](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。

## セクション 2: 日付フィルターの詳細
<a name="customer-agreements-date-deep-dive"></a>

この日付フィルターは、カスタマー契約ダッシュボードのすべてのメトリクスに適用されます。  

例えば、デフォルトの [年の初めから今まで] のフィルター値を使用すると、次のメトリクスが表示されます。


|  メトリクス  |  説明  | 
| --- | --- | 
|  パブリックオファー契約数  |  オファーの可視性をパブリックオファーとし、YTD 期間中に少なくとも 1 日以上アクティブな契約数。 | 
|  プライベートオファー契約数  |  オファーの可視性をプライベートオファーとし、YTD 期間中に少なくとも 1 日以上アクティブな契約数。 | 
|  新しいパブリックオファー契約数  |  オファーの可視性をパブリックオファーとし、YTD 期間内に承認日がある契約数。 | 
|  新しいプライベートオファー契約数  |  オファーの可視性をプライベートオファーとし、YTD 期間内に承認日がある契約数。 | 
|  アクティブなお客様  |  サブスクライバー AWS アーカイブ ID として特定され、YTD 期間中に少なくとも 1 日以上アクティブな契約がある固有の顧客数。アクティブな契約は、特定の期間に 少なくとも 1 日以上アクティブな日がある契約として定義されます。 | 
|  新規有料顧客  |  YTD 期間内に最初の請求月がある、サブスクライバー AWS アカウント ID として識別される固有の顧客数。 | 

## セクション 3:  パブリックオファー契約とプライベートオファー契約
<a name="customer-agreements-public-private-agreements"></a>

ダッシュボードのこのセクションには、契約の概要が表示されます。重要業績評価指標 (KPI) には、パブリックオファー契約数、プライベートオファー契約数、新しいパブリックオファー契約数、新しいプライベートオファー契約数が含まれます。前年比または期間比の変化を数量と割合で確認できます。これらのフィルターセクションの日付フィルタ－を更新すると日付範囲を更新できます。

 *契約*は、提案者 (製品またはサービスの所有者) と承認者 (顧客) の間で署名された契約で、製品の使用を開始します。

**注記**  
新しい契約メトリクスには、アクティブ、期限切れ、キャンセル、終了の各契約が含まれます。

 以下の表では、契約の状態の一覧と説明が示されています。


|  ステータス  |  説明  | 
| --- | --- | 
|  アクティブ  |  アクティブ - 契約内容の一部またはすべてが有効な状態です。 | 
|  失効  |  契約が事前に合意された終了日に終了した状態です。 | 
|  キャンセル  |  承認者が、終了日前に契約を終了することを選択した状態です。 | 
|  終了  |  支払不履行などの理由で AWS から終了を催促されたため、契約が終了日前に終了した状態です。 | 
|  更新済み  |  自動更新機能などを使用して契約が新しい契約に更新された状態です。 | 
|  置き換え済み  |  契約が代替オファーを使用して置き換えられた状態です。 | 

## セクション 4:  顧客メトリクス
<a name="section-5-customer-metrics"></a>

ダッシュボードの本セクションには、指定した日付範囲の顧客傾向が表示されます。KPI には、アクティブな顧客数、新規有料顧客数が含まれます。
+ **月次傾向** – チャート内のフィルターに基づいて、月別にアクティブな顧客数と新規有料顧客数を表示します。 
+ **顧客メトリクス** – 選択したメトリクスフィルターに基づいて、アクティブ顧客数と新規有料顧客数に関するデータを提供します。顧客セグメントまたは顧客業界を選択すると、それぞれがどのように総顧客メトリックに貢献しているかを把握できます。

**注記**  
契約にはステータスが指定されます。ステータスの詳細については、[前のセクションの表](#customer-agreements-public-private-agreements)を参照してください。

以下の表では、メトリックスの一覧と説明を示しています。


|  メトリクス  |  説明  | 
| --- | --- | 
|  パブリックオファー契約  | パブリックオファーの可視性を持つ契約 ID として特定される契約数。契約の長さは、選択した日付範囲と少なくとも 1 日重複します。長さは、契約開始日と終了日の間で特定されます。 | 
|  プライベートオファー契約  | プライベートオファーの可視性を持つ契約 ID として特定される契約数。契約の長さは、選択した日付範囲と少なくとも 1 日重複します。長さは、契約開始日と終了日の間で特定されます。 | 
|  新しいパブリックオファー契約  | パブリックオファーの可視性を持つ契約 ID として識別される契約数。契約の承認日は選択した日付範囲内です。 | 
|  新しいプライベートオファー契約  |  プライベートオファーの可視性を持つ契約 ID として識別される契約数。契約の承認日は選択した日付範囲内です。 | 
|  アクティブなお客様  | 有効な契約が 1 つ以上あるサブスクライバー AWS アカウント IDsとして識別された顧客の数。 契約期間が、選択した日付範囲と少なくとも 1 日重複している  | 
| 新規有料顧客  |  選択した日付範囲内に最初の請求月 があるサブスクライバー AWS アカウント IDs として識別された顧客の数。 | 

 契約の詳細については、このセクションの「[契約および更新ダッシュボード](agreements-renewals-dashboard.md)」および「[請求済み収益ダッシュボード](billed-revenue-dashboard.md)」を参照してください。

# 出品パフォーマンスダッシュボード
<a name="listing-performance-dashboard"></a>

出品パフォーマンスダッシュボードには、 AWS Marketplace の出品の概要と詳細なデータが表示されます。ダッシュボードには、トラフィックボリューム、およびお客様が製品をサブスクリプション登録するために実行する手順に関するデータが表示されます。ダッシュボードには、マーケティングチャネル別のトラフィックの詳細な内訳も表示されます。

**注記**  
このダッシュボードを解除するには、[AWS Marketplace Seller Prime](https://pages.awscloud.com/aws-marketplace-seller-prime.html) プログラムに登録する必要があります。
このダッシュボードを開くには、[AWS Marketplace 管理ポータル](https://aws.amazon.com/marketplace/management/) にサインインして、**[インサイト]**、**[マーケティング]** を選択し、**[リスティングパフォーマンス]** タブを選択します。

 AWS Marketplace ダッシュボードの使用の詳細については、このセクションの前半の[販売者ダッシュボード](dashboards.md)「」を参照してください。

**Topics**
+ [セクション 1: フィルター](#listing-section-1-filters)
+ [セクション 2: 日付フィルターの詳細](#date-filter-deep-dive)
+ [セクション 3:  概要メトリクス](#listing-summary-metrics)
+ [セクション 4:  毎月の傾向とファネル変換](#monthly-trend-funnel)
+ [セクション 5: チャネル別のトラフィックの傾向](#traffic-trend-by-channel)
+ [セクション 6: 毎月のトラフィックと契約メトリクス](#monthly-traffic-agreement)
+ [セクション 7: ユニークビジターの ウェブトラフィックソース](#traffic-sources-unique-visitors)
+ [セクション 8: ウェブトラフィックソースの内訳](#traffic-source-breakdown)

## セクション 1: フィルター
<a name="listing-section-1-filters"></a>

次のフィルターを使用してデータを絞り込むことができます。


|  コントロール名  |  説明  | 
| --- | --- | 
|  製品のタイトル  |  製品のタイトル。 | 
|  日付  |  過去 30 日、60 日、90 日、過去 12 か月 (TTM)、および年初来 (YTD) が含まれます。カスタムを選択して、特定の開始日と終了日を定義できます。 | 

フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

## セクション 2: 日付フィルターの詳細
<a name="date-filter-deep-dive"></a>

 この日付フィルターは、出品パフォーマンスダッシュボードのすべてのメトリクスに適用されます。  

 例えば、デフォルトの年初来フィルター値を使用すると、次のメトリクスが表示されます。


|  メトリクス  |  説明  | 
| --- | --- | 
|  ユニークビジター  |  YTD のリスト AWS Marketplace ページにアクセスした一意の個人の数。 | 
|  新しいパブリックオファー契約  |  オファーの可視性をパブリックオファーとし、YTD 期間中に少なくとも 1 日以上アクティブな契約数。 | 
|  新しいユニークビジター  |  YTD で初めて AWS Marketplace 出品ページにアクセスした 一意の個人の数。 | 
|  再訪したユニークビジター  |  選択した年の初め以前に AWS Marketplace 出品ページを訪問し、YTD で再度訪問した 一意の個人の数。 | 

## セクション 3:  概要メトリクス
<a name="listing-summary-metrics"></a>

ダッシュボードのこのセクションには、トラフィックとパブリックオファー契約の概要が表示されます。重要業績評価指標 (KPI) には、ユニークビジター数、新しいパブリックオファー契約の数、新しいユニークビジターの数、および再訪したユニークビジターの数が含まれます。前年比または期間比の変化を数量と割合で確認できます。フィルターセクションの日付フィールドの日付条件を更新して、日付範囲を更新できます。


|  メトリクス  |  説明  | 
| --- | --- | 
|  ユニークビジター  |  AWS Marketplace 出品ページにアクセスした一意の個人の数。 | 
|  契約  |  プロポーザー (製品またはサービスの所有者) とアクセプター (お客様) の間で署名された製品の使用を開始するための契約。 | 
|  新しいパブリックオファー契約  |  選択された日付範囲内で、アクティブ、期限切れ、キャンセル、終了などのステータスを含む承諾日を持つオファー開始性としてのパブリックオファーを含む契約の数。 | 
|  ステータス  | アクティブ - 契約の条項の一部またはすべてが有効な状態です。期限切れ - 契約が事前に合意された終了日に終了した状態です。キャンセル済み – 承認者が終了日より前に契約を終了することを選択した状態です。終了 – 支払いエラーなど、AWS が開始した終了イベントにより、契約は事前に合意した終了日より前に終了した状態です。更新済み – 自動更新などの機能を使用して、契約が新しい契約に更新された状態です。置き換え済み – 契約が代替オファーを使用して置き換えられた状態です。 | 

## セクション 4:  毎月の傾向とファネル変換
<a name="monthly-trend-funnel"></a>

ダッシュボードの本セクションには、指定した日付範囲のトラフィックと同意に関するトレンドが表示されます。重要業績評価指標には、新しいパブリックオファー契約を閲覧したユニークビジターと新しい契約の数が含まれます。**月別のユニークビジター** - 月別のユニークビジター数を示します。1 人のユニークビジターが複数の月に訪問できるため、月別のユニークビジターの合計は、サマリーメトリクスセクションのユニークビジターの合計を超える場合があります。**月別の新しい契約** - 月別の新しいパブリックオファー契約数を示します。**ファネルコンバージョン** - ステップバイステップのコンバージョンビューを提供します。これには、出品ページ、調達ページ、設定ページ、フルフィルメントページが含まれます。バーの表示形式として、ユニークビジター、ページビュー、ユニークアカウントを選択できます。各バーにカーソルを合わせると、現在のバーの値として定義されているコンバージョン率を前のバーの割合として表示できます。


|  メトリクス  |  説明  | 
| --- | --- | 
|  ユニークビジター  |  AWS Marketplace 出品ページにアクセスした一意の個人の数。 | 
|  ページビュー  |  AWS Marketplace 出品ページへのアクセス回数。 | 
|  ユニークアカウント  |  訪問者に関連付けられた一意の AWS アカウント ID の数。このメトリクスは、ビジターが認証した後にのみ適用されます。 | 

## セクション 5: チャネル別のトラフィックの傾向
<a name="traffic-trend-by-channel"></a>

ダッシュボードのこのセクションでは、月別のトラフィック傾向について詳しく説明します。バーの表示形式として、ユニークビジターとページビューを選択できます。チャンネルフィルターで 1 つまたは複数のチャンネルを選択すると、選択したチャンネルの月別傾向を確認できます (複数可)。

## セクション 6: 毎月のトラフィックと契約メトリクス
<a name="monthly-traffic-agreement"></a>

ダッシュボードのこのセクションには、ユニークビジター、新しい契約、コンバージョン率、および合計アグリーメントの月次ビューが表示されます。コンバージョン率は、新しい契約を毎月のユニークビジターで割ったものとして定義されます。

テーブル内のデータは、部分的な月の日付範囲を選択した場合でも、月全体を表します。例えば、2024 年 1 月 15 日から 2024 年 3 月 15 日の期間を表示するようにデータをフィルタリングしても、テーブルには 2024 年 1 月 1 日から 2024 年 3 月 31 日の完全な月次データが含まれます。

テーブル内のデータは**月**でソートされ、直近の月が最初に表示されます。対応する列ヘッダーをクリックして、使用可能な列のいずれかでテーブルをソートすることを選択できます。オプションでは、データを昇順または降順にソートできます。

## セクション 7: ユニークビジターの ウェブトラフィックソース
<a name="traffic-sources-unique-visitors"></a>

ダッシュボードのこのセクションでは、マーケティングソース別のユニークビジターの詳細を説明します。カテゴリには、販売者の有機的検出、販売者主導のマーケティングキャンペーン、 AWS 組織的検出、AWS 主導のキャンペーンが含まれます。これらのカテゴリは、ビジターまたはアクセスに関連付けられた追跡コードによって識別されます。


|  トラフィックソース  |  説明  | 
| --- | --- | 
|  販売者経由のオーガニックディスカバリー  | ウェブサイトまたはアプリ内通知のコールトゥアクションと検出ポイントを通じて出品にアクセスしたユニークビジター。 | 
|  販売者主導のマーケティングキャンペーン  | 有料広告またはプロモーションチャネルを通じて出品にアクセスしたユニークビジター。 | 
|  AWS 有機検出  | オーガニック AWS ウェブサイトトラフィック、 AWS コンソール (複数可) 検索、 AWS マーケットプレイス検索などの AWS チャネルを通じて出品したユニークビジター。 | 
|  AWS マーケティングキャンペーン  | AWS 主導のキャンペーンや有料プロモーションを通じて出品にアクセスしたユニークビジター。 | 

## セクション 8: ウェブトラフィックソースの内訳
<a name="traffic-source-breakdown"></a>

ウェブトラフィックソースの内訳テーブルは、トラフィックをもたらしたマーケティングアクティビティの詳細な内訳を提供します。
+ **トラフィックソース** - AWS主導型と販売者主導型を 2 つの主要なカテゴリとして含めます。
+ **トラフィックタイプ** - 販売者の有機的検出、販売者主導のマーケティングキャンペーン、 AWS 組織的検出、主導 AWSのマーケティングキャンペーンが含まれます。
+ **チャンネル** - 有料表示、有料検索、有料ソーシャルメディア、E メール、オーガニック、内部サイトトラフィックの外部リンクなど、さまざまなマーケティング戦術が含まれます。
+ **Publisher** - Facebook、Google、LinkedIn、 Seller-led など AWS、キャンペーンが公開されているエンティティを指します。
+ **プロモーション** - 専用追跡コードが生成された特定のキャンペーンを指します。例として、`psm_linked_post_free-trial-global-ver-a` が挙げられます。


|  メトリクス  |  説明  | 
| --- | --- | 
|  契約への寄与  |  各プロモーションからのアクセスが寄与した契約の合計。 | 
|  コンバージョン率  |  契約数を各プロモーションからのユニークビジターで割ったもの。 | 

# 検索パフォーマンスダッシュボード
<a name="search-performance-dashboard"></a>

**検索パフォーマンス**ダッシュボードには、 AWS Marketplace 検索エクスペリエンスでの出品のパフォーマンスに関するメトリクスが表示されます AWS Marketplace 。ダッシュボードを使用して、出品の検出可能性とパフォーマンスを向上させます。ダッシュボードは、インプレッション数、クリック数、クリックスルー率を追跡します。また、指定したキーワードと顧客が使用するキーワードを追跡し、一般的な顧客検索に基づいてキーワードの提案を提供します。

ダッシュボードからのインサイトは、製品リストを絞り込み、可視性を向上させ、キーワードと顧客の好みを一致させ、 AWS Marketplaceでより適格なトラフィックをビジネスに誘導するのに役立ちます。  

ダッシュボードを開くには、 AWS Marketplace 管理ポータルを起動し、**インサイト**タブに移動します。

ダッシュボードのアクセス制御の詳細については、このセクションの前半にある「[販売者ダッシュボード](dashboards.md)」を参照してください。

## セクション 1: ダッシュボードへのアクセス
<a name="search-performace-access"></a>

 このダッシュボードを解除するには、[AWS Marketplace Seller Prime プログラム](https://pages.awscloud.com/aws-marketplace-seller-prime.html)のメンバーになる必要があります。

Seller Prime プログラムに登録すると、販売者アカウントのシステム管理者は の **Insights** タブを使用して**検索パフォーマンス**ダッシュボード AWS Marketplace 管理ポータル を開始できます。

システム管理者は、 AWS Identity and Access Management (IAM) ポリシーを作成して、販売会社の他のユーザーに特定のダッシュボードへのアクセスを提供することもできます。

**注記**  
 2023 年 9 月以降、従来の IAM アクセス許可で有効化された販売者ダッシュボードへのアクセスはサポートされなくなります。次の例に示すように、新しい Amazon リソースネーム (ARN) 形式を使用して IAM 権限を更新します。

 ポリシーを作成するための詳細については、「*AWS Identity and Access Management ユーザーガイド*」の「[IAM ポリシーの作成](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)」を参照してください。

### ポリシーを使用してアクセスをコントロールする
<a name="search-performance-access-policies"></a>

次のいずれかのポリシーを使用して、一覧表示パフォーマンスダッシュボードへのアクセスを提供します。

次の例では、現在または将来のデータフィードに関係なく、ダッシュボードやレポートなど、現在および将来のすべての AWS Marketplace リソースにアクセスできます。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
    {
    "Effect": "Allow",
    "Action": [
    "aws-marketplace:GetSellerDashboard"
    ],
    "Resource": "arn:aws:aws-marketplace:us-east-1:111122223333:AWSMarketplace/*"
    }
    ]
    }
```

------

次の例では、ARN を含めることにより、**検索パフォーマンス**ダッシュボードへのアクセスを提供します。  

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
    {
    "Effect": "Allow",
    "Action": [
    "aws-marketplace:GetSellerDashboard"
    ],
    "Resource": "arn:aws:aws-marketplace:us-east-1:111122223333:AWSMarketplace/ReportingData/Marketing_V1/Dashboard/SearchPerformance_V1"
    }
    ]
    }
```

------

## セクション 2: フィルター
<a name="search-perf-filters"></a>

 ダッシュボードのこのセクションには、次のフィルターが用意されています。これらを使用してデータを絞り込みます。


| コントロール名 | 説明 | 
| --- | --- | 
| 製品のタイトル |  製品のタイトル。 このフィルターは、インプレッション、クリック、クリックスルー率、**AWS Marketplace 検索キーワードのレコメンデーション**に影響します。**[製品カテゴリ別上位検索キーワード]** テーブルには影響しません。  | 
| 日付フィルター |  過去 30 日間、60 日間、90 日間、過去 12 か月間 (TTM)、および年初来 (YTD) でフィルタリングできます。**[カスタム]** を選択して、特定の開始日と終了日を使用します。 このフィルターは、インプレッション、クリック、クリックスルー率に影響します。**AWS Marketplace 検索キーワードのレコメンデーション**や**製品カテゴリテーブルで検索された上位キーワード**には影響しません。  | 

 フィルタリングの詳細については、「*Amazon QuickSight ユーザーガイド*」の「[Amazon QuickSight でのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」をご確認ください。

## セクション 3: AWS Marketplace 検索パフォーマンス
<a name="search-performance"></a>

ダッシュボードのこのセクションには、 AWS Marketplace 出品 の検出可能性とパフォーマンスに関する主要業績評価指標 (KPIs) が表示されます。ダッシュボードには、インプレッション数、クリック数、クリックスルー率の KPIs が表示されます。

 前年比または期間比の変化を数量と割合で確認できます。日付範囲を変更することもできます。


| メトリクス | 説明 | 
| --- | --- | 
| インプレッション |  AWS Marketplaceの検索結果の上位 20 件にリストが表示される回数。 | 
| クリック数 | ユーザーが AWS Marketplace 検索結果から出品をクリックした回数。 | 
| クリックスルー率 (CTR) | クリック数とインプレッション数の比率。検索結果から顧客を引き付けるために出品がどの程度効果的かを示す尺度。 | 

## セクション 4: インプレッション、クリック、クリックスルー率の毎月の傾向
<a name="impressions-click-throughs"></a>

 ダッシュボードのこのセクションには、指定した月のトレンドが表示されます。インプレッション数、クリック数、クリックスルー率の KPI が表示されます。

## セクション 5:AWS Marketplace キーワードレコメンデーションの検索
<a name="keyword-recommendations"></a>

 ダッシュボードのこのセクションには、現在のキーワードと各リストの推奨キーワードを一覧表示する表が表示されます。


| 列名 | 説明 | 
| --- | --- | 
| 製品のタイトル | 製品のタイトル。リンクをクリックすると、 AWS Marketplace 管理ポータルの製品概要ページに移動し、出品を管理および編集できます。 | 
| 現在のキーワード |  AWS Marketplace 管理ポータルの製品情報の更新セクションで指定したキーワード。 | 
| トップパフォーマンスのキーワード | 製品に関する上位 5 件の顧客検索に表示されるキーワード。 | 
| AWS推奨キーワード | 顧客が類似製品を検索するときに最もよく使用するキーワード。 | 
| 推定トラフィック増加率 (%) | 推奨キーワードを採用すると、トラフィックが増加する可能性があります。日付フィルターによる影響はありません。 | 

**注記**  
キーワードは重要ですが、他の要因が検索結果に影響を与える可能性があります。  
出品の最適化   
 短い説明や長い説明など、出品の他の部分を最適化します。
出品の効果を高めるために、無料トライアルなどの機能を提供することを検討してください。
キーワードと出品およびターゲット顧客とのマッチング  
可能な限り、リストを頻繁に使用するキーワードと照合します。
製品とその機能に関連するキーワードのみを使用してください。そうしないと、リストが多数の検索に表示されることがありますが、選択するユーザーが少なくなります。
キーワードのバリエーションについて  
「git」や「gitops」などの同様の用語は、同じ検索用語として扱われる場合があることに注意してください。
バリエーションの関連性を評価し、それに応じてキーワードを調整します。
キーワードの更新  
で AWS Marketplace 管理ポータル、**製品**メニューを開き、製品カテゴリを選択します。
製品へのリンクを選択して **[製品情報]** タブを選択し、**[製品情報の提供]** ページに移動します。
**AWS Marketplace 検出可能性**セクションまでスクロールし、** AWS Marketplace 検索結果のキーワード**を検索して、キーワードを調整します。

## セクション 6: 製品カテゴリ別の上位検索キーワード
<a name="top-keywords-by-product-category"></a>

類似製品の各製品カテゴリの上位 5 つの顧客検索キーワード。このダッシュボードの他の製品フィルターと日付フィルターは、このデータには影響しません。

# AWS ダッシュボードでの購入について
<a name="buy-with-aws-dashboard"></a>

**Buy with AWS** ダッシュボードには、**[Buy with AWS]** のコールトゥアクションボタンを選択して **[Buy with AWS]** 調達ページを訪問した顧客によって発生した Web トラフィック、エンゲージメント、締結された契約内容の概要が表示されます。 AWS Marketplace

ダッシュボードへのアクセスの詳細については、このガイドの前半の「[販売者ダッシュボード](dashboards.md)」を参照してください。

**Topics**
+ [セクション 1: フィルター](#buy-with-aws-filters)
+ [セクション 2: 概要メトリクス](#buy-with-aws-summary-metrics)
+ [セクション 3: ページビューと契約の合計クリック数と傾向データ](#buy-with-aws-clicks-views)
+ [セクション 4:AWS サインインページのドロップオフ率](#buy-with-aws-drop-off-rate)
+ [セクション 5: AWS 調達での購入ページのエンゲージメント](#buy-with-aws-engagements)
+ [セクション 6: AWS 調達での購入ページのエンゲージメントメトリクスの傾向データ](#buy-with-aws-procurement-page-trends)

## セクション 1: フィルター
<a name="buy-with-aws-filters"></a>

 このセクションには、次のデータフィルターがあります。


|  フィルター名  |  説明  | 
| --- | --- | 
| 製品のタイトル | 製品のタイトル。 | 
| 製品 ID | ソフトウェア製品のわかりやすい一意の識別子。 | 
| 日付フィルター | 過去 30、60、または 90 日間、過去 12 か月、または過去 1 年でフィルタリングします。[カスタム] を選択して、他の開始日と終了日を入力します。 | 

フィルタリングの詳細については、「 [クイックユーザーガイド」の「クイックでのデータのフィルタリング](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)」を参照してください。 **

## セクション 2: 概要メトリクス
<a name="buy-with-aws-summary-metrics"></a>

このセクションでは、**[Buy with AWS]** コールトゥアクションボタンと **[Buy with AWS]** 調達ページに関する情報を表示します。

以下の表では、メトリックスの一覧と説明を示しています。日付範囲を更新するには、**[フィルター]**セクションの日付条件を変更します。


|  メトリクス  |  説明  | 
| --- | --- | 
| ボタンの合計クリック数  | 販売者ウェブサイトの [Buy with AWS] など、コールトゥアクションボタンのクリックの合計数。 | 
|  AWS ページビューでの購入数  | [Buy with AWS] 調達ページへの総訪問者数。これは述べ人数になります。 | 
| Buy with AWS page からの契約の合計  | [Buy with AWS] 調達ページで作成された契約の総数。   | 

## セクション 3: ページビューと契約の合計クリック数と傾向データ
<a name="buy-with-aws-clicks-views"></a>

このセクションでは、指定した日付範囲の毎月または毎週の傾向を示します。以下の表では、KPI の一覧と説明を示しています。


| メトリクス | 説明 | 
| --- | --- | 
| **ボタンの合計クリック数** | 販売者ウェブサイトのコールトゥアクションボタンの合計クリック数。 | 
| **ページビュー** | **[Buy with AWS]** 調達ページへの総訪問者数。**[データの表示形式]** リストを使用して、月次ビューと週次ビューのどちらかを選択します。 | 
| **契約の合計** | **[Buy with AWS]** 調達ページで作成された契約の総数。**[データの表示形式]** リストを使用して、月次ビューと週次ビューのどちらかを選択します。 | 

## セクション 4:AWS サインインページのドロップオフ率
<a name="buy-with-aws-drop-off-rate"></a>

このセクションには、 AWS サインインページのドロップオフ率が表示されます。 レートは、サインインし、契約を作成したユーザーと、サインインのみを行ったユーザーの数の比率です。**[データの表示形式]** を使用して、週または月でフィルタリングします。

## セクション 5: AWS 調達での購入ページのエンゲージメント
<a name="buy-with-aws-engagements"></a>

このセクションでは、指定した日付範囲の概要メトリクスと傾向データを示します。次の表に、メトリクスの一覧と説明を示します。フィルターセクションの日付フィールドを使用して、日付範囲を更新します。


| メトリクス | 説明 | 
| --- | --- | 
| ユニークビジターの総数 | 調達ページのユニークユーザーの総数。 | 
| バウンス率 | 1 つのサイトページを表示した後にサインインして退出するユーザーと、複数のページを訪問するユーザーの比率。 | 
| 分単位の平均ユーザードウェル時間 | ユーザーがサインインしてから、そのユーザーがページを離れるまでの時間。 | 

## セクション 6: AWS 調達での購入ページのエンゲージメントメトリクスの傾向データ
<a name="buy-with-aws-procurement-page-trends"></a>

グラフには、[セクション 5](#buy-with-aws-engagements) のメトリクスの毎月または毎週の傾向が表示されます。**[データの表示形式]** リストを使用して、毎月のビューと毎週のビューのいずれかを選択します。  