

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 中的卖家报告、数据源和控制面板 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 在报告、数据源和仪表板中提供尽可能多的数据，同时遵守以下规定：
+ 亚马逊用于保护客户数据的标准和原则。
+ 买家在 AWS Marketplace上购买产品时接受的条款和条件。作为卖家，根据合同，您有义务安全管理买家数据并根据买家的要求删除数据。

**注意**  
要取消报告的通知电子邮件，请联系 [AWS Marketplace 卖家运营](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 存储桶。数据源在一天内生成，包含前一天 24 小时的数据。以下各节概述了数据源，并说明了如何访问和使用它们。随后的部分将介绍每个数据源。

交易数据以双时态结构传输和附加，因此卖家可以根据两个时间线存储和查询数据，且它们都具有时间戳
+ 有效时间：某个事实实际发生的时间（“您所知道的”）
+ 系统时间：将该事实记录到数据库的时间（“当您知道时”）。

数据源将在世界标准时间每天午夜传输，此前一天的更新包含前一天的 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)。
+ 字符编码是无 BOM 的 UTF-8。
+ 使用逗号作为值之间的分隔符。
+ 字段由双引号进行转义。
+ `\n` 是换行符。
+ 日期按 UTC 时区进行报告，采用 ISO 8601 日期和时间格式，并精确到 1 秒。
+ 所有 `*_period_start_date` 和 `*_period_end_date` 值都包括在内，这意味着 `23:59:59` 是任何一天的最后一个可能的时间戳。
+ 所有货币字段前面都有币种字段。
+ 货币字段使用句点 (`.`) 字符作为小数分隔符，不使用逗号 (,) 作为千位分隔符。

数据源的生成和存储方式如下：
+ 数据源在一天内生成，包含前一天 24 小时的数据。
+ 在 Amazon S3 存储桶中，数据源使用以下格式按月进行组织：

  `bucket-name/data-feed-name_version/year=YYYY/month=MM/data.csv`
+ 生成每个每日数据源时，它将附加到该月的现有 CSV 文件中。当新月份开始时，将为每个数据源生成一个新的 CSV 文件。
+ 数据源中的信息从 2010/01/01 到 2020/04/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 SNS 以在数据传送到已加密的 Amazon S3 存储桶时向您发送通知。有关配置通知的更多信息，请参阅《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-03-29 进行了更改（例如，记录中的地址发生了变更）。后来，在 2019-04-28，地址变更得到了更正（所以 `valid_from` 没有改变，但 `update_date` 变了）。更正地址（罕见事件）会追溯更改原始 `valid_from` 日期的记录，因此该字段不会更改。查找最新 `valid_from` 的查询将返回两条记录，具有最新 `update_date` 的记录会给出实际的当前记录。

# 访问数据源
<a name="data-feed-accessing"></a>

借助 AWS Marketplace，您可以将数据源用作一种机制，将最新的结构化产品和客户信息从 AWS Marketplace 系统发送到 Amazon S3 存储桶，以便在卖家所有的商业智能工具之间进行 ETL（提取、转换和加载）。您需要对环境进行配置，以将数据源接收到加密的 Amazon S3 存储桶中。本主题将向您介绍如何访问和取消订阅数据源。

**Topics**
+ [访问数据源](#data-feed-accessing-procedure)
+ [数据源策略](#data-feed-policies)
+ [取消订阅数据源](#data-feed-unsubscribing)

## 访问数据源
<a name="data-feed-accessing-procedure"></a>

1. 分配具有 SQL 和 ETL（提取、转换、加载）经验的商业智能或数据工程师。此人还需要有设置 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. 打开 Web 浏览器并登录 [AWS Marketplace 管理门户](https://aws.amazon.com/marketplace/management/)，然后转到[设置客户数据存储](https://aws.amazon.com/marketplace/management/reports/data-feed-configuration)。

   1. 选择**使用 CloudFormation 模板创建资源**，在 CloudFormation 控制台的另一个窗口中打开模板。

   1. 在模板中，指定以下内容，然后选择**下一步**：
      + 堆栈名称 – 您将创建的允许访问数据源的资源集合。
      + Amazon S3 存储桶名称 – 用于存储数据源的存储桶。
      + （可选）Amazon SNS 主题名称 – 在 Amazon Simple Storage Service 存储桶发生相关事件时接收通知的主题。

   1. 在**审核**页面上，确认您的条目，然后选择**创建堆栈**。这将打开一个包含 CloudFormation 状态和详细信息的新页面。

   1. 从**资源**选项卡中，将 CloudFormation 页面上的以下资源的 Amazon 资源名称 (ARN) 复制到 AWS Marketplace [设置客户数据存储](https://aws.amazon.com/marketplace/management/reports/data-feed-configuration)页面上的字段中：
      + 用于存储数据源的 Amazon S3 存储桶
      + 用于加密 Amazon S3 存储桶的 AWS KMS 密钥
      + （可选）AWS 将新数据传送到 Amazon S3 存储桶时接收通知的 Amazon SNS 主题

   1. 在**设置客户数据存储**页面上，选择**提交**。

   1. （可选）编辑由 CloudFormation 模板创建的策略。有关更多信息，请参阅[数据源策略](#data-feed-policies)。

      您现在已订阅数据源。下次生成数据源时，您可以访问数据。

1. 使用 ETL（提取、转换、加载）操作将数据源连接到您的数据仓库或关系数据库。
**注意**  
数据工具功能各异。您必须让商业智能工程师或数据工程师参与设置集成，以便与您工具的功能相匹配。

1. 要运行或创建 SQL 查询，请将数据源配置为在数据工具中强制使用主键和外键。每个数据源代表一个唯一的表，您必须使用实体关系在数据架构中设置所有数据源。有关表和实体关系的更多信息，请参阅本指南中的[数据源表概述](data-feed-joining.md)。

1. 设置 Amazon Simple Notification Service 以自动刷新您的数据仓库或关系数据库。您可以配置 Amazon SNS 通知，在来自每个唯一源的数据传送到 Amazon S3 存储桶时发送提醒。通过数据源接收新数据时，可以利用这些通知来自动刷新卖家数据仓库（如果卖家数据工具支持此功能）。请参阅《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 等可视化工具。
   + 将数据映射到您的 CRM、ERP 或财务工具，例如 Salesforce、Infor 或 Netsuite。

有关使用 CloudFormation 模板的更多信息，请参阅《AWS CloudFormation 用户指南》**中的[使用 CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)。

## 数据源策略
<a name="data-feed-policies"></a>

当使用 CloudFormation 模板创建 Amazon S3 存储桶时，它将为附加到该存储桶、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>

打开 Web 浏览器并登录 [AWS Marketplace Management Portal](https://aws.amazon.com/marketplace/management/)。然后，转到[联系我们页面](https://aws.amazon.com/marketplace/management/contact-us/)，向 AWS Marketplace 卖家运营团队提交取消订阅请求。取消订阅请求可能需要 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) 中，[创建一个爬网程序](https://docs.aws.amazon.com/glue/latest/dg/add-crawler.html)以连接到存储数据源的 Amazon S3 存储桶、提取所需数据并在 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 的更多信息，请参阅 [《Amazon Athena 用户指南》**](https://docs.aws.amazon.com/athena/latest/ug/what-is.html)。

1. 在 [Quick 控制台](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 服务收集和分析数据上传数据的一种方式的详细示例，请参阅博客上的[使用卖家数据源配送服务、Amazon Athena 和快速创建卖家](https://aws.amazon.com/blogs/awsmarketplace/using-seller-data-feed-delivery-service-amazon-athena-and-amazon-quicksight-to-create-seller-reports/)报告。 AWS Marketplace 

# 数据源表概述
<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/zh_cn/marketplace/latest/userguide/images/datafeeds-overview.png) 

## 与目录相关的表
<a name="data-feed-catalog-domain"></a>

下图显示了目录域中各表之间的关系以及表中各字段的关系。

![\[目录域中“Product”、“Offer_Product”、“Offer”、“Offer_Target”和“Legacy_id_mapping”表之间的关系。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-catalog-details.png)


`Product`、`Offer_Product`、`Offer`、`Offer_Target` 和 `Legacy_id_mapping` 表位于目录域中。

`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` 表之间的关系以及表中各字段的关系。

![\[账户域中的“Account”表和“Address”表与每个表中的字段之间的关系。\]](http://docs.aws.amazon.com/zh_cn/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/zh_cn/marketplace/latest/userguide/images/datafeeds-revenue-details.png)


**注意**  
有关这些表的更多信息，包括对表中每个字段的描述以及您可以创建的连接，请参阅以下主题：  
[账单事件数据源](data-feed-billing-event.md)
[税项数据源](data-feed-tax-item.md)

### 与采购相关的表
<a name="procurement-tables"></a>

下图显示了采购域中“Agreement”表中的字段。

**注意**  
有关这些表的更多信息，包括对表中每个字段的描述以及可以创建的连接，请参阅本指南中的[协议数据源](data-feed-agreements.md)。

以下各部分提供了每个域的*实体关系* (ER) 图。每个 ER 图都显示表和每个表中的字段，以及可用于联接表的字段。

**注意**  
本部分中的 ER 图不包括所有数据源的公共字段。有关字段的更多信息，请参阅[AWS Marketplace 数据源的存储和结构](data-feed-details.md)。

下表介绍了 ER 图中显示的符号。


| 符号 | 描述 | 
| --- | --- | 
|  ![\[字母“PK”作为符号的图像。\]](http://docs.aws.amazon.com/zh_cn/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/zh_cn/marketplace/latest/userguide/images/datafeeds-foreign-key.png)  |   **外键** - 表示不同表中主键的字段。表中不一定是唯一的。   在某些情况下，如果当前表中的记录在外表中没有相应的记录，则外键可能为空。   | 
|  ![\[字母“AK”作为符号的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-alternate-key.png)  |   **备用密钥** - 可在表中用作密钥的密钥。遵循与主键相同的唯一性规则。  | 
|  ![\[一端是十字架，另一端是圆圈和叉子的一条线的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-one-to-many.png)  |   **连接器** - 字段之间的线代表一个连接，即两个可用于连接表的字段。线的末端代表连接的类型。此示例表示一对多连接。  | 

**连接器类型**

下表显示每个连接器可以具有的端部类型。


| 连接器类型 | 描述 | 
| --- | --- | 
|  ![\[一端是十字架的一条线的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-one-to-n.png)  |   **一对 n** – 具有此端的连接器表示在此侧只有一个值的连接。  | 
|  ![\[一端是十字架，一端是圆圈的一条线的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-zero-or-one-to-n.png)  |   **零或一到 n** - 具有此端的连接器表示在此侧具有零或一个值的连接。  | 
|  ![\[一端是圆圈和叉子的一条线的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-optional-many-to-n.png)  |   **零或多对 n** - 具有此端的连接器表示此侧具有零、一个或多个值的连接。  | 
|  ![\[一端是十字架和叉子的一条线的图像。\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/images/datafeeds-one-or-more-to-n.png)  |   **一或多对 n** - 具有此端的连接器表示在此侧具有一个或多个值的连接。  | 

# 数据源查询示例
<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>

要查找按产品列出的已支付金额，您可以运行如以下示例所示的一组查询。

这些示例查询相互依存，可创建包含付款的最终产品详细信息列表。它还显示了如何在特定时间点获取产品信息。您可以使用下方所示的示例，也可以根据您的数据和用例进行自定义。

查询中的注释说明了查询的作用以及如何修改查询。

**注意**  
运行此查询时，我们假设提取的数据使用两个时间轴，分别为 `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>

要按客户查找计费收入，您可以运行如下所示的查询。这些示例查询相互依存，可创建最终的客户详细信息列表，其中包含向每位客户收取的软件使用费总额。您可以使用下方所示的查询，也可以根据您的数据和用例进行自定义。

 查询中的注释说明了查询的作用以及如何修改查询。

**注意**  
运行此查询时，我们假设提取的数据使用两个时间轴（ `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 卖家均可使用数据源。由于数据源是在一天内生成的，因此其中包含最新的可用数据。

以下各个部分介绍了每种数据源。

**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。例如，AWS Marketplace Metering Service 将 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 的值。 | 
| 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 将于 2023 年 12 月停止使用[卖家传输数据源服务](https://docs.aws.amazon.com/marketplace/latest/userguide/data-feed-service.html) PIIFeed。使用 AddressFeed\$1v1 数据源来满足您的地址数据需求。如果您有任何疑问或需要支持，请联系 [AWS Marketplace 卖家运营](https://aws.amazon.com/marketplace/management/contact-us/)团队。

此数据源提供了您与之交互的所有账户的联系信息：您自己的账户、与您合作的任何渠道合作伙伴、买家、付款人和所有纳税账户。每次进行新交易时，都会扫描交易的客户地址；如果在数据源中不包含该地址，则会在数据源文件中添加新条目。

地址数据是不可变的。

地址数据源每 24 小时刷新一次，因此每天提供的都是新数据。

下表说明了数据源列的名称和说明。


| 列名称  | 描述  | 
| --- | --- | 
| address\$1id  | 地址的唯一键。可用于连接 `Billing_Event` 数据源的 `billing_address_id` 字段，或 `Account` 数据源的 `mailing_address_id` 或 `tax_address_id` 字段。 | 
| email\$1domain  | 为该账户登记的电子邮件地址域。 | 
| company\$1name  | 为该账户登记的公司名称。 | 
| country\$1code | 为该地址登记的 ISO 3166 alpha-2 国家/地区代码。 | 
| state\$1or\$1region  | 为该地址登记的州/省或地区。 | 
| city  | 为该地址登记的城市。 | 
| postal\$1code  | 为该地址登记的邮政编码。 | 
| address\$1line\$11  | 为该地址登记的地址第一行。 | 
| address\$1line\$12  | 为该地址登记的地址第二行。 | 
| address\$1line\$13  | 为该地址登记的地址第三行。 | 

## 地址数据源示例
<a name="data-feed-address-sample-data"></a>

下面显示了地址数据源的示例。在数据源中，此信息以单个表格形式显示。为了便于阅读，数据显示在两个表格中，并且未显示数据历史记录列。有关数据历史记录字段的信息，请参阅[数据历史记录](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 小时刷新一次。

下表列出并描述了数据源中的项目。


| 列 | 说明 | 
| --- | --- | 
| valid\$1from | 主键值相对于其他字段的值有效的第一个日期。 | 
| insert\$1date | 将记录插入数据源中的日期。 | 
| update\$1date | 上次更新记录的日期。 | 
| delete\$1date | 该列始终为空。 | 
| Status |  协议的当前状态。支持的状态包括： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-agreements.html)  | 
| estimated\$1agreement\$1value | 客户在协议的整个生命周期内可能支付的已知总金额。 | 
| currency\$1code | 客户在协议的整个生命周期内可能支付的已知总金额的货币。 | 
| agreement\$1id | 协议的唯一标识符。 | 
| license\$1ids | 与协议关联的许可证标识符，以数组表示。 | 
| proposer\$1account\$1id | 提出此建议的卖家 PurchaseAgreement，由卖家账户的全球唯一标识符 (GUID) 表示。可用于连接“账户”数据源。 | 
| acceptor\$1account\$1id | 接受这一点的买家 PurchaseAgreement，由买家账户的全球唯一标识符 (GUID) 表示。可用于连接“账户”数据源。 | 
| offer\$1revision\$1at\$1acceptance | 与此协议对应的优惠的友好 ID。可用于连接“优惠”和“优惠目标”数据源。 | 
| 报价集\$1ID | 与该优惠关联的优惠套餐的标识符。 | 
| start\$1time | 协议的开始日期和时间。 | 
| end\$1time | 协议的结束日期和时间。对于没有结束日期的 pay-as-you-go协议，该字段为空。 | 
| acceptance\$1time | 买家接受优惠或协议创建的日期和时间。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-agreements.html)  | 
| intent | 上次修改协议时买家的意图。 | 
| preceding\$1agreement\$1id | 之前的协议的协议 ID。 | 
| status\$1reason\$1code | 协议状态更改原因。 | 
| 收件人\$1账号\$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 | 报价集\$1ID | start\$1time | end\$1time | acceptancet\$1time | intent | preceding\$1agreement\$1id | status | status\$1reason\$1code | estimated\$1agreement\$1value | currency\$1code | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| 2024-06-21 20:58:00.0 | agmt-34g544dfgsd5678adsrgwe5t | 88a3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 88a3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | offer-krxxxxxxxxxxx | 1 | offerset-yricpu74oqox2 | 2024-06-21 20:58:00.0 | 2025-06-21 20:58:00.0 | 2024-06-21 20:58:00.0 | 新 |  | ACTIVE |  | 1000 | USD | 

# 协议费用数据馈送
<a name="data-feed-agreement-charge"></a>

此数据源概述了与您作为登记卖家创建的协议相关的费用。该数据源目前仅提供与付款时间表条款相关的协议的费用信息。

协议费用数据源每 24 小时刷新一次。

下表列出并描述了数据源中的项目。


| 列 | 说明 | 
| --- | --- | 
| valid\$1from | 主键值相对于其他字段的值有效的第一个日期。 | 
| insert\$1date | 将记录插入数据源中的日期。 | 
| update\$1date | 上次更新记录的日期。 | 
| delete\$1date | 该列始终为空。 | 
| 量 | 要收取的金额。 | 
| currency\$1code | 付款的定价货币。 | 
| 时间 | 计划分期付款的预定收费日期。 | 
| agreement\$1id | 协议的唯一标识符。 | 
| 术语\$1id | 术语的唯一标识符。 | 

## 协议费用数据馈送示例
<a name="agreement-charge-feed-example"></a>


| valid\$1from | insert\$1date | update\$1date | delete\$1date | 量 | currency\$1code | 时间 | agreement\$1id | 术语\$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.000 000 | agmt-3kk39tbw3j6id2vakbp0xxxx | term-3986e2c7f73768ed4ff7cd8a97b41ac0ae2a02ada6b68deb9349c8604cxxxx | 

# 协议期限数据馈送
<a name="data-feed-agreement-term"></a>

此数据源概述了与您作为登记卖家创建的协议相关的协议期限。

协议条款数据源每 24 小时刷新一次。

下表列出并描述了数据源中的项目。


| 列 | 说明 | 
| --- | --- | 
| valid\$1from | 主键值相对于其他字段的值有效的第一个日期。 | 
| insert\$1date | 将记录插入数据源中的日期。 | 
| update\$1date | 上次更新记录的日期。 | 
| delete\$1date | 删除记录的日期。 | 
| agreement\$1id | 协议的唯一标识符。 | 
| 术语\$1id | 术语的唯一标识符。 | 
| 术语类型 | 与协议相关的条款类型。有关可用术语的完整列表，请参阅 https://docs.aws.amazon.com/marketplace/ latest/APIReference/API \$1Types\$1 AWS\$1M arketplace\$1Agreement\$1Service.html。 | 
| 术语配置 | 接受者在接受术语时指定的其他参数。这适用于 ConfigurableUpfrontPricingTerms 和 RenewalTerms。 | 

## 协议条款数据馈送示例
<a name="agreement-term-feed-example"></a>


| valid\$1from | insert\$1date | update\$1date | delete\$1date | agreement\$1id | 术语\$1id | 术语类型 | 术语配置 | 
| --- | --- | --- | --- | --- | --- | --- | --- | 
| 2024-12-24 11:31:47 .0 | 2025-10-01 01:03:41.0 | 2025-10-01 01:03:41.0 | null | agmt-3kk39tbw3j6id2vakbp0xxxx | term-3986e2c7f73768ed4ff7cd8a97b41ac0ae2a02ada6b68deb9349c8604cxxxx | ConfigurableUpfrontPricingTerm | \$1“selectorValue”: “P36M”，“dimensionKey”：[\$1“dimensionKey”: “应用程序”，“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/zh_cn/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/zh_cn/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` 具有其他值，则此字段为空。 当 `broker_id` 的值为 `AWS_EUROPE` 时，`parent_billing_event_id` 表示在以下情况下启动此账单事件的原始 `billing_event_id`： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html) 当 `broker_id` 的值为 `AWS_EUROPE` 时，对于所有剩余情景，此字段均为空。  | 
| disbursement\$1billing\$1event\$1id |  `action` 的值为 `DISBURSED` 且以下参数之一为 True 时的相关支付： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html) 其他所有情景下，此值为 Null。  | 
| 量 | 账单事件金额。 | 
| currency | ISO 639 币种代码。 | 
| disbursement\$1amount | 付款金额。对于双重开票场景，此字段显示付款金额。对于统一开票场景，此字段为空。 | 
| disbursement\$1currency | 付款金额对应的 ISO 639 货币代码。对于双重开票场景，此字段显示付款货币代码。对于统一开票场景，此字段为空。 | 
| balance\$1impacting | 在计算卖家付款时是否考虑该金额。值为 0 指示显示该金额以供参考，对余额没有影响。值为 1 指示在确定卖家付款时考虑该金额。 | 
| invoice\$1date | 创建发票的日期。 | 
| payment\$1due\$1date |  如果 `action` 的值为 `INVOICED`，则为发票的到期日期。  | 
| usage\$1period\$1start\$1date | 记录中期间的开始日期。 | 
| usage\$1period\$1end\$1date | 记录中期间的结束日期。 | 
| invoice\$1id |  发 AWS 票编号。  | 
| billing\$1address\$1id | 地址数据源中的付款人账单地址参考。可用于连接 `address_id` 数据源的 `Address` 字段。 | 
| transaction\$1reference\$1id |  允许您交叉引用以下报告中的数据的标识符： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| buyer\$1transaction\$1reference\$1id |  一种标识符，它使用 `GROUP BY` 或在 SQL 中构造的窗口函数对账单源中的所有相关记录进行分组。这些相关记录可以包含买家发票、卖家发票和上市费的增值税 (VATs)。  | 
| 操作日期 |  交易事件发生的日期。具体日期取决于操作类型： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/data-feed-billing-event.html)  | 
| 收件人\$1账号\$1id | 在上传数据中接收数据的卖家账户。可用于连接 `account_id` 数据源的 `Account` 字段。 | 
| offer\$1id | 与买家发票单项关联的报价的友好编号。可用于连接 `offer_id` 数据源的 `Offer` 字段。 | 
| 买家发票日期 | 关联的买家发票明细项目的发票日期。 | 
| line\$1item\$1id | 按支出粒度分列的发票明细项目编号。 | 
| buyer\$1line\$1item\$1id | 按支付粒度划分的买家发票单项编号。 | 
| 冲锋变体 | 表示正在买入或卖出什么。 | 
| 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>

本部分显示开发票时和一个月之后的账单事件数据期间的示例。对于本部分中的所有表，请注意以下各项：
+ 在数据源中，`billing_event_id` 值为 40 个字符的字母数字字符串。为了便于阅读，它们在这里显示为两个字符的字符串。
+ 在数据源中，此信息以单个表格形式显示。为了便于阅读，数据显示在此处的多个表中，并且不显示所有列。

对于本部分中的示例，假定以下内容：
+ Arnav 是买家。
  + 他的账户 ID 是 `737399998888`。
  + 他位于法国，需要遵守电商平台促进法的规定。有关更多信息，请参阅 [Amazon Web Service 税务帮助](https://aws.amazon.com/tax-help/)。
  + 他购买了 `prod-o4grxfafcxxxx` 并因他每月使用该产品而获得了 120.60 美元的发票。
  + 他在当月内支付了发票。
+ 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 | 采买 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1TAX\$1分享 | 
| I2 | 777788889999 | 111122223333 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | SELLER\$1REV\$1SHARE | 
| I3 | 777788889999 | 采买 | 737399998888 | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1分享 | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | 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 | 采买 | 737399998888 | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1分享 | 
| I14 | 采买 | 777788889999 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | 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 | 采买 |  | prod-o4grxfafcxxxx | INVOICED | AWS\$1REV\$1分享 | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | 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 | 采买 |  | prod-o4grxfafcxxxx | DISBURSED | AWS\$1REV\$1分享 | 
| I33 | 采买 | 111122223333 |  |  | DISBURSED | DISBURSEMENT | 




| parent\$1billing\$1event\$1id | disbursement\$1billing\$1event\$1id | 量 | 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 存储桶中的数据运行查询。本部分提供了您执行此操作可能采取的常见方法的一些示例。所有示例都假定使用单一币种。

## 示例 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 小时刷新一次。

下表列出并描述了数据源中的项目。


| 列 | 说明 | 
| --- | --- | 
| valid\$1from | 主键值相对于其他字段的值有效的第一个日期。 | 
| insert\$1date | 将记录插入数据源中的日期。 | 
| update\$1date | 上次更新记录的日期。 | 
| delete\$1date | 软删除记录的日期。 | 
| usage\$1feed\$1id | 使用记录的唯一标识符。这是针对每个卖家的加盐哈希值，可确保数据隐私，同时保持记录的唯一性。 | 
| usage\$1date | 客户使用日期，不含时间部分。由于每天的使用量是汇总的，因此省略了该时间。 | 
| product\$1id | 产品的友好 ID。可用于加入账户、Billing\$1Event 和 Offer\$1Product 数据馈送的`product_id`字段。 | 
| agreement\$1id | 协议的唯一标识符。如果存在，则始终以`agmnt-`。此字段偶尔可能为空或与相应的发票行项目不匹配。 | 
| end\$1user\$1account\$1id | 实际使用产品的账户，由最终用户账户的全局唯一标识符 (GUID) 表示。可用于连接“账户”数据源。这是每个卖家的加盐哈希值，而不是原始的 AWS 账户 ID。 | 
| payer\$1account\$1id | 应支付产品使用费用的账户，由付款人账户的全球唯一标识符 (GUID) 表示。可用于连接“账户”数据源。这是每个卖家的加盐哈希值，而不是原始的 AWS 账户 ID。 | 
| region | 买家使用发生的地 AWS 区。 | 
| 维度键 | 卖家在发布报价时配置的维度密钥。 | 
| 用量\$1单位 | 使用单位的分类，描述使用量测量的类型。 | 
| usage\$1quantity | 与账单记录关联的 AWS 服务或使用类型的使用值。该值最多可提供 2 位小数。 | 
| pricing\$1currency | 预计收入的货币。 | 
| 以定价货币计算的估计收入 | 使用`usage_rate_per_unit`和计算的估计收入`usage_quantity`。该值最多可提供 2 位小数。要获取 ISV 对经销商产品使用情况的看法，则需要将其乘以收入分成百分比。 | 
| 收件人\$1账号\$1ID | 在上传数据中接收数据的卖家账户。 | 
| offer\$1id | 优惠的友好 ID。这将与购买协议的 offer\$1id（如果有）匹配。可用于连接“优惠”和“优惠目标”数据源。为了保持一致性，此字段始终为非空。 | 
| 每单位用量费率定价货币 | 每单位的使用率，可以乘以`usage_quantity`来验证。`estimated_revenue_in_pricing_currency`该值最多可提供 6 位小数。 | 
| 充电商品描述 | 完整的费用项目描述，通常格式为 offer\$1term\$1description\$1region\$1region\$1dimension\$1description，表示基于使用量的 | 

## 每日使用量数据 Feed 示例
<a name="daily-usage-feed-example"></a>

以下是带有关键列的 “每日使用量” 数据馈送的示例。为了便于阅读，某些列未显示。


| usage\$1date | product\$1id | agreement\$1id | region | 维度键 | 用量\$1单位 | usage\$1quantity | pricing\$1currency | 以定价货币计算的估计收入 | offer\$1id | 每单位用量费率定价货币 | 充电商品描述 | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| 2025-01-15 | prod-abcd1234efgh5678 | agmnt-wxyz9876abcd5432 | us-east-1 | USE1\$1InputTokenCount | 单位 | 24.00 | USD | 12.00 | offer-mnop5432qrst7890 | 0.500000 | AWS Marketplace 软件使用情况\$1美国东部-100万个输入代币 | 
| 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>

此数据源列出了产品 IDs 和报价如何 IDs 映射到传统的全球唯一标识符 (GUIDs)。旧版用于 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 | 
| --- | --- | --- | 
| 优惠 | 8a806c74-dbd6-403e-9362-bb08f417ff37 | offer-dacpxznflfwin | 
| 产品 | 1368541d-890b-4b6c-9bb9-4a55306ab642 | prod-o4grxfafcxxxy | 
| 优惠 | 558d8382-6b3a-4c75-8345-a627b552f5f1 | offer-gszhmle5npzip | 



# 优惠数据源
<a name="data-feed-offer"></a>

优惠数据源提供了有关您作为记录卖家创建的所有优惠的信息。如果单个优惠具有多个修订版，则所有修订版都包含在数据源中。

当您创建优惠修订版且公开字段中的数据发生更改时，会在数据源中为同一主键（`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 | 只有当经销商销售您的产品时，才会填写机会的标识符。如果产品相同，则由不同渠道合作伙伴（或卖家）创建的所有优惠具有相同的 opportunity\$1id。 | 
| 收件人\$1账号\$1ID | 在上传数据中接收数据的卖家账户。可用于连接 `account_id` 数据源的 `Account` 字段。 | 

## 优惠数据源示例
<a name="data-feed-offer-sample-data"></a>

下面显示了优惠数据源的示例。为了便于阅读，未显示数据历史记录列。有关数据历史记录字段的信息，请参阅[数据历史记录](data-feed-details.md#data-feed-historization)。


| offer\$1id  | offer\$1revision | name | 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>

一种优惠可以包含多种产品，一种产品可以包含在不同优惠中。此数据源列出了有关优惠与产品之间的关系的信息。

此数据源提供了有关您作为记录卖家创建的所有产品优惠的信息。

当您在优惠中添加或删除产品时，您将创建优惠修订版。

每 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>

此数据源为您作为记录卖家创建的所有优惠列出了优惠修订版的目标。如果单个优惠具有多个修订版，则所有修订版都包含在数据源中。

当您创建优惠修订版且公开字段中的数据发生更改时，会在数据源中为同一主键（`offer_id` 和 `offer_revision`）创建一条新记录，但 `valid_from` 字段的值不同。

优惠目标数据源每 24 小时刷新一次，因此每天提供的都是新数据。

下表说明了数据源列的名称和说明。


| 列名称  | 描述  | 
| --- | --- | 
| offer\$1target\$1id | 源的主键。 | 
| offer\$1id\$1offer\$1revision | 优惠的标识符和修订版。这两列引用了与此目标相关的优惠。可用于连接 `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/zh_cn/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 | value | 
| --- | --- | --- | --- | --- | --- | 
| 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`)，每个税务管辖区一个或多个。例如，对于使用不同 AWS 实体（例如美国和爱尔兰）使用不同 AWS 区域规则的客户而言，会发生这种情况。要详细了解在哪里对您的销售征 AWS 收销售税、增值税或商品及服务税，并以 AWS, Inc. 的名义将此类税款汇给当地税务机关，请参阅[亚马逊网络服务税务帮助](https://aws.amazon.com/tax-help/)。

税项数据源每 24 小时刷新一次，因此每天提供的都是新数据。

税项数据是不可变的。

下表说明了数据源列的名称和说明。有关数据历史记录列的信息，请参阅[数据历史记录](data-feed-details.md#data-feed-historization)。


| 列名称  | 说明  | 
| --- | --- | 
| tax\$1item\$1id | 税项记录的唯一标识符。 | 
| invoice\$1id | 发 AWS 票编号。您可以将此值与 product\$1id 值结合使用，以查找相关的税务记账事件。 | 
| line\$1item\$1id | 客户账单行项目的唯一标识符。退款交易具有与远期税务交易相同的行项目 ID。 | 
| customer\$1bill\$1id | 客户账单的唯一标识符。买家可与卖家共享此标识符，以帮助识别和解决税务计算问题。 | 
| tax\$1liable\$1party | `AWS` 或 `Seller`。如果卖家是税务责任方，则会征收税款。如果 AWS 是纳税方，则由 AWS其征收和汇出销售税。有关更多信息，请参阅 [AWS Marketplace 卖家和税务征收](https://aws.amazon.com/tax-help/marketplace)。 如果未征收税款，则此处不显示值。卖家需要确定是否针对每张发票征收某些税务，因为卖家有征税责任。 | 
| transaction\$1type\$1code | 交易的类型。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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 | 与纳税位置关联的 vertex 地理编码。 | 
| 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/zh_cn/marketplace/latest/userguide/data-feed-tax-item.html)  | 
| legal\$1amount | 需缴纳税款对应的法定货币金额。 | 
| legal\$1currency | 需缴纳税款对应的法定货币。 | 
| tax\$1invoice\$1id | 在双重开票的情况下，税目对应的税务发票标识符。对于统一开票场景，此字段将为空。 | 
| tax\$1invoice\$1date | 税务发票的开具日期。对于统一开票场景，此字段将为空。 | 

**注意**  
从 2021 年 8 月 5 日起，国际 Marketplace 服务商 AWS 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 | 
| --- | --- | --- | --- | --- | 
| Seller | AWS | prod-o4grxfafcxxxx | AWSMP\$1SOFTWARE\$1RA | 2018-12-31T00:00:00Z | 
| Seller | AWS | prod-o4grxfafcxxxx | AWSMP\$1SOFTWARE\$1RA | 2018-12-31T00:00:00Z | 
| Seller | AWS | prod-t3grxfafcxxxy | AWS\$1REMOTE\$1访问软件 | 2018-08-31T00:00:00Z | 
| Seller | REFUND | prod-t3grxfafcxxxy | AWS\$1REMOTE\$1访问软件 | 2018-08-31T00:00:00Z | 
| Seller | AWS | prod-x8faxxfafcxxy | AWS\$1REMOTE\$1访问软件 | 2018-08-31T00:00:00Z | 
| Seller | TAXONLYREFUND | prod-x8faxxfafcxxy | AWS\$1REMOTE\$1访问软件 | 2018-05-31T00:00:00Z | 
| AWS | AWS | prod-wghj8xfafrhgj | AWS\$1REMOTE\$1访问软件 | 2019-07-31T00:00:00Z | 




| taxed\$1customer\$1account\$1id | taxed\$1customer\$1country | taxed\$1customer\$1state\$1or\$1region | taxed\$1customer\$1city | taxed\$1customer\$1postal\$1code | 
| --- | --- | --- | --- | --- | 
| VIega2 XXCg GCGUree t9j3muxioh9wc8lsnd xriocm5 | 美国 | GA | MILTON | 48573-4839 | 
| VIega2 XXCg GCGUree t9j3muxioh9wc8lsnd xriocm5 | 美国 | GA | MILTON | 48573-4839 | 
| 7nyo5jw plyx81vx9ji04 o TRo 1ff8biqi88w8 eEwTur | 美国 | NC | DURHAM | 27517-4834 | 
| 7nyo5jw plyx81vx9ji04 o TRo 1ff8biqi88w8 eEwTur | 美国 | NC | DURHAM | 27517-4834 | 
| 7nyo5jw plyx81vx9ji04 o TRo 1ff8biqi88w8 eEwTur | 美国 | TX | NOT APPLICABLE | 75844-1235 | 
| 7nyo5jw plyx81vx9ji04 o TRo 1ff8biqi88w8 eEwTur | 美国 | 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 | Sales | State | GA | 排除 | 100 | 0 | 
| 66301164 | Sales | County | FULTON | 排除 | 0 | 100 | 
| 692938178 | SellerUse | 州 | NC | 排除 | 58.1 | 523.8 | 
| 692938178 | SellerUse | 州 | NC | 排除 | -58.1 | 523.8 | 
| 356794387 | Sales | 州 | TX | Exclusive | 1105.14 | 0 | 
| 528887443 | Sales | City | HOUSTON | 排除 | -36 | 0 | 
| 171248162 | Sales | 州 | 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 | NonTaxable | 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 | NonTaxable | 2018-07-31T00:00:00Z | 
| 0 | 0 | USD | Exempt | 2019-06-30T00:00:00Z | 



# 补充报告
<a name="supplementary-reports"></a>

AWS Marketplace 通过卖家拥有的 [AWS Marketplace 中的卖家传输数据源](data-feed-service.md) Amazon S3 账户提供补充报告，这些账户关联到与 AWS Marketplace 卖家 AWS Marketplace 商品相关的卖家账户编号。有关更多信息，请参阅[创建目标 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 至次日 UTC 16:01。

## 协议详细信息报告
<a name="agreement-details-report"></a>

协议详细信息报告可帮助您向使用软件即服务 (SaaS) 免费试用的客户提供支持。该报告包括协议详细信息，例如订阅用户名称、订阅用户 ID、优惠 ID、协议开始和协议结束日期。

只有在具有相关信息时，您才会收到该报告。如果您认为自己应该收到该报告但却没有收到，请与 [AWS Marketplace 卖家运营](https://aws.amazon.com/marketplace/management/contact-us/)团队联系。

您可以通过与 AWS Marketplace 卖家账户编号关联的 Amazon S3 存储桶访问此报告。

下表列出了协议详细信息报告的列名和描述。


**SaaS 合同免费试用报告数据**  

| Name | 说明 | 
| --- | --- | 
| vendor\$1display\$1name | 销售产品的供应商名称。 | 
| vendor\$1aws\$1account\$1id | 与销售产品的供应商关联的标识。 | 
| subscriber\$1aws\$1account\$1id | 与订阅产品的人相关的标识。 AWS 账户  | 
| 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 | 协议的结束日期。对于 metered/pay as go/subscriptions，该值设置为 1-JAN-9999。 | 
| 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 系统管理员可以访问中 “Insights” 选项卡上的所有控制面板 AWS Marketplace 管理门户。系统管理员可以创建 AWS Identity and Access Management (IAM) 策略，向卖方公司的其他用户提供对特定控制面板的访问权限。

**注意**  
2023 年 9 月，我们将不再支持通过旧 IAM 权限访问卖家控制面板。在下面的代码示例中，使用新的 Amazon 资源名称 (ARN) 格式更新您的 IAM 权限。

有关创建 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/*"
            ]
        }
    ]
}
```

------

您还可以通过添加一个或多个仪表板来提供对这些仪表板的访问权限 ARNs。以下示例演示了如何提供对所有控制面板的访问权限：

------
#### [ 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>

控制面板在每日世界标准时间午夜更新。如果发票是在 5 月 10 日世界标准时间午夜*之前*创建的，那么 5 月 11 日的更新将显示该发票。如果发票是在 5 月 10 日世界标准时间午夜*之后*创建的，那么 5 月 12 日的更新将显示该发票。如果从上游系统收到的最新发票或付款数据延迟，则最新数据可能会延迟 1-2 天才能反映在控制面板上。

如果您没有看到预期的客户发票，请在联系您的 AWS Marketplace 业务发展联系人之前按照以下步骤操作。

**解决账单收入控制面板缺失的客户发票问题**

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. 考虑一下交易是否采用[用量定价模式](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 的账单。您也可以向分析添加筛选条件，例如您想要包含在视觉对象中的日期范围。在控件中选择的筛选条件会更新指标、趋势、细分和精细数据部分中显示的数据。

有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](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/zh_cn/marketplace/latest/userguide/billed-revenue-dashboard.html) | 
| 付款人 ID AWS 账户  | 费用计入的账户的 ID。 | 
| 付款人公司名称 | 费用计入的企业名称。 | 
| 经销公司 |  授权销售软件制造商产品的经销商账户的公司名称。  | 
| 经销商 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 转售授权 ID | 已注册的机会的唯一标识符。 | 
| 转售授权名称 | 已注册的机会的唯一名称。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的 2 字符国家/地区代码。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市或区域。 | 
| 交易参考 ID | 交易的唯一标识符，可帮助您关联 AWS Marketplace 旧版报告中的交易。 | 

## 第 2 部分：筛选条件
<a name="section-2-invoice-date-range"></a>

控制面板的这个部分提供筛选条件，用于根据优惠采用的货币和发票日期范围细化记录。您可以使用发票日期范围来选择账单日期是在指定日期之前还是之后，或者是在某个日期范围内。所选筛选条件会更新指标、趋势、细分和精细数据部分中显示的数据。默认发票日期范围设置为拉取最近六个月的数据。

## 第 3 部分：关键指标
<a name="section-3-metrics"></a>

控制面板的此部分显示关键绩效指标（KPI），以使用所选筛选条件直观比较关键计费收入数据。将显示指定发票日期范围内采用指定货币的总收入、退款总额、上架费、批发成本（如适用）和卖家净收入的 KPI。您可以更新筛选条件以查看不同日期范围内采用不同货币的指标。

## 第 4 部分：趋势
<a name="section-3-metrics"></a>

控制面板的此部分提供指定日期范围内的账单收入趋势。您可以按指定日期聚合（例如日、、或 year-over-year）查看趋势 month-over-month quarter-over-quarter，以深入了解账单收入。计费收入趋势信息按汇总层面或按优惠可见性类型提供：
+ **账单趋势** – 提供日期聚合筛选条件中选定日期范围内的总收入、卖家净收入、批发成本（如适用）和退款的快照。
+ **按产品/服务可见性划分的计费趋势** – 按优惠可见性类型提供一段时间内[专属优惠、公开优惠](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 费账单的总金额。 AWS 使用以下三个频率向客户开具账单：
+ 接受订阅日期（预付账单）
+ 自定义付款计划（由灵活付款计划程序创建的专属优惠）
+ 在当月第二天和第三天对上月用量计量

**注意**  
2021 年 4 月 1 日之前创建的发票可能没有关联的协议编号、优惠编号、订阅者 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)，并提供符合税收要求的发票。对于适用的交易，对上市费征收的增值税的发票 ID 与软件或产品订阅发票 ID 不同。AWS, Inc. 交易的值为 “missing\$1listing\$1fee\$1invoice\$1ID”，因为上架费发票 ID 不适用。 | 
| 批发发票 ID | 分配给非应付发票的 AWS ID，该发票代表 ISV 和渠道合作伙伴之间在渠道合作伙伴私有报价 (CPPO) 中的销售。对于公开报价和 Marketplace Private 报价 (MPOs)，此字段将为 “不适用”。 | 
| 卖家开具的发票编号 | 卖家向 AWS 开具的发票。 | 
| 卖家开具的发票变体 | 对应于 invoice\$1id 列的发票类型。可能的值包括：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/billed-revenue-dashboard.html) | 
| 订阅用户公司名称 | 订阅产品的账户的名称。 | 
| 订阅者 AWS 账户 ID | 订阅产品的账户的 ID。 | 
| 订阅用户电子邮件域 | 与订阅产品的账户关联的电子邮件域。例如，如果电子邮件地址是 liu-jie@example.com，则该条目为 example.com。 | 
| 订阅用户城市 | 与订阅产品的账户关联的账单地址中的城市。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的账单地址中的国家/地区。 | 
| 订阅用户邮政编码 | 与订阅产品的账户关联的账单地址中的邮政编码。 | 
| 产品标题 | 产品的标题。 | 
| 优惠名称 | 卖家定义的优惠名称。 | 
| 优惠 ID | 买家签订的优惠的标识符。 | 
| 优惠可见性 | 优惠是公开、专属还是企业合同优惠。 | 
| 优惠套装 ID | 与该优惠关联的优惠套餐的标识符。 | 
| 协议 ID | 提议者和接受者之间签署的开始使用产品的协议的唯一协议数据源参考。 | 
| 协议开始日期 | 客户开始订阅产品的日期，格式为 MM-DD-YYYY。如果这是未来日期的协议，则该日期可能与接受日期不同。 | 
| 协议接受日期 | 客户订阅产品的日期，格式为 MM-DD-YYYY。 | 
| 协议结束日期 | 合同到期的日期，格式为 MM-DD-YYYY。对于计量/ pay-as-you-go 订阅，此日期设置为 JAN-1-9999。 | 
| 协议条款类型 | 协议创建过程中与接受者相关并被接受的条款类型。 | 
| 使用期结束日期 | 产品使用期的结束日期。 | 
| 使用期开始日期 | 产品使用期的开始日期。 | 
| 支付状态 | 与发票关联的状态，用于确认 AWS 未向您的银行账户支付任何款项、部分或全部款项。可能的状态包括：已支付、部分支付、支付失败、未支付。 | 
| 支付日期 |  AWS 开始向卖家银行付款的日期。 | 
| 支付参考编号 | 对于付款，付款参考编号是在创建每个付款 AWS 请求时生成的。付款参考编号可用于将卖家银行提供的存款通知和报告与报告中的发票关联起来。 AWS Marketplace  | 
| 支付银行跟踪 ID | 对于支付，跟踪 ID 由银行分配。付款银行追踪编号可用于将卖家银行提供的存款通知和报告与报告中的发票关联起来。 AWS Marketplace  | 
| 总收入 | 向客户计费的产品用量或月度费用的金额。 | 
| 总退款 | 如果在数据涵盖时段内处理了任何退款，则为向客户退还的订阅成本总额。 | 
| 上架费用 | 要从账单金额中扣除的 AWS Marketplace 费用金额。 | 
| 上架费用退款 | 如果在数据覆盖期内处理了任何退款，则退还的部分 AWS Marketplace 费用。 | 
| 上架费用百分比 | 要从账单金额中扣除的 AWS Marketplace 费用百分比。 | 
| 卖家纳税份额 | 该交易收取的美国销售和使用税总额。 | 
| 卖家纳税份额退款 | 如果处理了退款，则为该交易退还的美国销售和使用税总额。 | 
| AWS 税收份额 | 代表卖家为该交易计费的美国销售和使用税总额。 | 
| AWS 税收份额退款 | 当代表卖家收取了此类税款时，如果已处理退款，则为该交易退还的美国销售和使用税总额。 | 
| 批发成本 | 仅适用于渠道合作伙伴专属优惠。经销商的产品成本。例如，经销商在销售制造商产品时向制造商支付的费用。批发成本等于标价乘以折扣百分比。 | 
| 批发成本退款 | 仅适用于渠道合作伙伴专属优惠。经销商退还的产品成本。 | 
| 批发卖家纳税份额 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款，且该税款由卖家承担。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发卖家纳税份额退款 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款的退款，且该税款由卖家承担。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发类其他卖家纳税份额 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款，且该税款由卖家承担。当参与交易的其他卖家承担税款时，系统将填充此字段。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发类其他卖家纳税份额退款 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款的退款，且该税款由卖家承担。当参与交易的其他卖家承担税款时，系统将填充此字段。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发 AWS 税份额 | 在渠道合作伙伴私人报价 (CPO) 中，独立软件供应商与渠道合作伙伴之间的销售应纳税 AWS 的税。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发 AWS 税份额退税 | ISV 与渠道合作伙伴之间在渠道合作伙伴私有报价 (CPPO) 中进行销售的退税，其中 AWS 应纳税。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 卖家净收入 | 扣除 AWS Marketplace 费用、退款以及美国销售和使用税后的总账单金额。 | 
| 收取的净收入 | AWS 已成功向买家收取的此笔交易的总金额。 | 
| 未收净收入 | AWS 尚未就此交易向买家收取的总金额。 | 
| 上次领取日期 | AWS 就此交易向买家收取任何款项的最近日期和时间。 | 
| 货币 | 交易的货币。例如，如果交易是以美元达成的，则该条目为 USD。 | 
| 交易参考 ID | 代表交易的唯一标识符，可用于关联 AWS Marketplace 报表中的交易。 | 
| AWS 记录在案的卖家 |  为交易提供便利的商业实体的标识符。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/billed-revenue-dashboard.html)  | 
| 转售授权 ID |  已注册的机会的唯一标识符。  | 
| 转售授权名称 | 已注册的机会的唯一名称。 | 
| 转售授权说明 | ISV 为已注册商机定义的描述。 | 
| 转售公司名称 | 从 ISV 批发购买产品或服务以转售给客户的账户名称。 | 
| 付款人 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 付款人电子邮件域 |  与费用计入的账户关联的电子邮件域。例如，如果电子邮件地址是 liu-jie@example.com，则该条目为 example.com。  | 
| 付款人城市 | 与费用计入的账户关联的账单地址中的城市。 | 
| 付款人省/自治区/直辖市 | 与费用计入的账户关联的账单地址中的省/自治区/直辖市。 | 
| 付款人国家/地区 | 与费用计入的账户关联的 2 字符国家/地区代码。 | 
| 付款人邮政编码 |  与费用计入的账户关联的账单地址中的邮政编码。  | 
| ISV 账户 ID | 产品或服务所有者的标识符。 | 
| ISV 公司名称 | 产品或服务所有者的企业名称。 | 
| 产品 ID |  软件产品的友好型唯一标识符。  | 
| 已支付净收入 |  向卖家支付的交易总额。如果该金额与“卖家净收入”不相等，则属于部分付款。  | 
| 未支付净收入 |  未向卖家支付的交易总额。如果该金额不为零，说明客户仍有未结清余额。  | 

# 收取和支付控制面板
<a name="collections-disbursement-dashboard"></a>

收取和支付控制面板提供已拨付至您银行账户的资金相关数据。同时，它还提供已发送部分付款、全额付款或付款失败的所有发票。该列表不包括未发生付款的发票。要查看未支付的发票，可使用**已计费收入**控制面板。

支付包括产品订阅相关的客户付款或已结算退款，以及向客户收取或退还的一些税费。控制面板上的退款显示为负数，因为在您批准退款后这笔款项退还给您的客户。

收取和支付控制面板可让您更快地获取客户付款相关信息。与旧版[支付报告](https://docs.aws.amazon.com/marketplace/latest/userguide/monthly-disbursement-report.html)相比，预计可节省大约四天，旧版是在支付发送五天后创建的。

**注意**  
买家的付款条件不同 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 部分：控件
<a name="collections-disbursement-dashboard-controls"></a>

控制面板的这一部分提供了筛选条件，用于调整您的控制面板数据。例如，您可以在[AWS Marketplace 事件通知](https://docs.aws.amazon.com/marketplace/latest/userguide/notifications.html)的字段上选择筛选条件，以确认特定客户账户 ID、订阅者公司名称或优惠 ID 的付款。您还可以按支付状态进行筛选，以了解所有已支付给您的发票或未结和未付的发票。您可以向分析添加筛选条件，例如您想要包含在视觉对象中的日期范围。在控件中选择的筛选条件会更新指标、趋势、细分和精细数据部分中显示的数据。

有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](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/zh_cn/marketplace/latest/userguide/collections-disbursement-dashboard.html) | 
| 支付状态 | 与发票关联的状态，用于确认 AWS 未向您的银行账户支付任何款项、部分或全部款项。可能的状态包括：已支付、部分支付、支付失败、未支付。 | 
| 付款人 ID AWS 账户  | 费用计入的账户的 ID。 | 
| 付款人公司名称 | 费用计入的企业名称。 | 
| 经销公司 |  授权销售软件制造商产品的经销商账户的公司名称。  | 
| 经销商 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 转售授权 ID | 已注册的机会的唯一标识符。 | 
| 转售授权名称 | 已注册的机会的唯一名称。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的 2 字符国家/地区代码。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市或区域。 | 
| 交易参考 ID | 交易的唯一标识符，可帮助您关联 AWS Marketplace 旧版报告中的交易。 | 
| 支付银行跟踪 ID | 对于支付，跟踪 ID 由银行分配。银行追踪 ID 可用于将卖家银行提供的存款通知和报告与 AWS Marketplace 报告中的发票关联起来。 | 

## 第 2 部分：筛选条件
<a name="section-2-select-date-range"></a>

控制面板的此部分提供了筛选条件，可根据优惠采用的货币和两个不同的日期维度（日期字段值是在指定日期之前还是之后还是在某个日期范围内）来细化记录。日期维度是付款到期日或最后一次支付日期。支付日期将结果限制为在指定日期范围内支付的发票。付款到期日包括到期日位于指定范围内的发票，与支付日期无关。日期类别筛选条件会更新指标、趋势、细分和精细数据部分中显示的数据。默认日期类别是最后一次支付日期，它提取最近六个月的数据。

## 第 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 日之前创建的发票可能没有关联的协议编号、优惠编号、订阅者 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 Marketplace 订阅是通过 AWS EMEA SARL、日本或澳大利亚法人（记录在案的卖家）进行交易时，销售的商城运营商（例如 AWS EMEA SARL）需要向卖家收取卖家上架费的增值税。对于适用的交易，对上市费征收的增值税的发票 ID 与软件或产品订阅发票 ID 不同。  | 
| 批发发票 ID |  分配给非应付发票的 AWS ID，该发票代表 ISV 和渠道合作伙伴之间在渠道合作伙伴私有报价 (CPPO) 中的销售。对于公开报价和 Marketplace Private 报价 (MPOs)，此字段将为 “不适用”。  | 
| 卖家开具的发票编号 | 卖家向 AWS 开具的发票。 | 
| 卖家开具的发票变体 | 对应于 invoice\$1id 列的发票类型。可能的值包括：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/collections-disbursement-dashboard.html) | 
| 订阅用户公司名称 | 订阅产品的账户的名称。 | 
| 订阅者 AWS 账户 ID | 订阅产品的账户的 ID。 | 
| 订阅用户电子邮件域 | 与订阅产品的账户关联的电子邮件域。例如，如果电子邮件地址是 liu-jie@example.com，则该条目为 example.com。 | 
| 订阅用户城市 | 与订阅产品的账户关联的账单地址中的城市。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的账单地址中的国家/地区。 | 
| 订阅用户邮政编码 | 与订阅产品的账户关联的账单地址中的邮政编码。 | 
| 产品标题 | 产品的标题。 | 
| 优惠名称 | 卖家定义的优惠名称。 | 
| 优惠 ID | 买家签订的优惠的标识符。 | 
| 优惠可见性 | 优惠是公开、专属还是企业合同优惠。 | 
| 优惠套装 ID | 与该优惠关联的优惠套餐的标识符。 | 
| 协议 ID | 提议者和接受者之间签署的开始使用产品的协议的唯一协议数据源参考。 | 
| 协议开始日期 | 客户产品订阅开始日期，格式为 MM-DD-YYYY。如果这是未来日期的协议，则该日期可能与接受日期不同。 | 
| 协议结束日期 | 合同到期的日期，格式为 MM-DD-YYYY。对于计量/ pay-as-you-go 订阅，此日期设置为 JAN-1-9999。 | 
|  |  | 
| 协议接受日期 | 客户订阅产品的日期，格式为 MM-DD-YYYY。 | 
| 使用期结束日期 | 产品使用期的结束日期。 | 
| 使用期开始日期 | 产品使用期的开始日期。 | 
| 支付状态 | 与发票关联的状态，用于确认自上次付款以来 AWS 已向您的银行账户收款并支付了款项。相关发票的已支付资金已收取并支付。相关发票的未支付资金未收取也未支付。 | 
| 支付日期 |  AWS 开始向卖家银行付款的日期。 | 
| 支付银行跟踪 ID | 对于支付，跟踪 ID 由银行分配。银行追踪编号可用于将卖家银行提供的存款通知和报告与报告中的发票关联起来。 AWS Marketplace  | 
| 总收入 | 向客户计费的产品用量或月度费用的金额。 | 
| 总退款 | 如果在数据涵盖时段内处理了任何退款，则为向客户退还的订阅成本总额。 | 
| 上架费用 | 要从账单金额中扣除的 AWS Marketplace 费用金额。 | 
| 上架费用退款 | 如果在数据覆盖期内处理了任何退款，则退还的部分 AWS Marketplace 费用。 | 
| 上架费用百分比 | 要从账单金额中扣除的 AWS Marketplace 费用百分比。 | 
| 卖家纳税份额 | 该交易收取的美国销售和使用税总额。 | 
| 卖家纳税份额退款 | 如果处理了退款，则为该交易退还的美国销售和使用税总额。 | 
| AWS 税收股票上市费 |  AWS 作为市场运营商，需要以自己的名义对卖家的销售收取和收取增值税。该金额将与向您的 AWS Marketplace 卖家账户收取的增值税金额相对应。 | 
| AWS 税收份额退税上市费 |  AWS 作为市场运营商，需要以自己的名义退还卖家销售的增值税。该金额将与退还给您的 AWS Marketplace 卖家账户的增值税金额相对应。 | 
| 批发成本 | 仅适用于渠道合作伙伴专属优惠。经销商的产品成本。例如，经销商在销售制造商产品时向制造商支付的费用。批发成本等于标价乘以折扣百分比。 | 
| 批发成本退款 | 仅适用于渠道合作伙伴专属优惠。经销商退还的产品成本。 | 
| 批发卖家纳税份额 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款，且该税款由卖家承担。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发卖家纳税份额退款 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款的退款，且该税款由卖家承担。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发类其他卖家纳税份额 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款，且该税款由卖家承担。当参与交易的其他卖家承担税款时，系统将填充此字段。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发类其他卖家纳税份额退款 | 渠道合作伙伴专属优惠（CPPO）中，ISV 与渠道合作伙伴之间销售交易所涉税款的退款，且该税款由卖家承担。当参与交易的其他卖家承担税款时，系统将填充此字段。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发 AWS 税份额 | 在渠道合作伙伴私人报价 (CPO) 中，独立软件供应商与渠道合作伙伴之间的销售应纳税 AWS 的税。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 批发 AWS 税份额退税 | ISV 与渠道合作伙伴之间在渠道合作伙伴私有报价 (CPPO) 中进行销售的退税，其中 AWS 应纳税。对于公开报价和 Marketplace Private 报价 (MPPOs)，此字段将为 “不适用”。 | 
| 卖家净收入 | 扣除 AWS Marketplace 费用、退款以及美国销售和使用税后的总账单金额。 | 
| 货币 | 交易的货币。例如，如果交易是以美元达成的，则该条目为 USD。 | 
| 交易参考 ID | 代表交易的唯一标识符，可用于关联 AWS Marketplace 报表中的交易。 | 
| AWS 记录在案的卖家 |  为交易提供便利的商业实体的标识符。可能值如下所示： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/collections-disbursement-dashboard.html)  | 
| 转售授权 ID |  已注册的机会的唯一标识符。  | 
| 转售授权名称 | 已注册的机会的唯一名称。 | 
| 转售授权说明 | ISV 为已注册商机定义的描述。 | 
| 经销商公司名称 | 从 ISV 批发购买产品或服务以转售给客户的账户名称。 | 
| 经销商 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 付款人公司名称 | 费用计入的账户的 ID。 | 
| 付款人 ID AWS 账户  | 费用计入的账户的 ID。 | 
| 付款人电子邮件域 |  与费用计入的账户关联的电子邮件域。例如，如果电子邮件地址是 liu-jie@example.com，则该条目为 example.com。  | 
| 付款人城市 | 与费用计入的账户关联的账单地址中的城市。 | 
| 付款人省/自治区/直辖市 | 与费用计入的账户关联的账单地址中的省/自治区/直辖市。 | 
| 付款人国家/地区 | 与费用计入的账户关联的 2 字符国家/地区代码。 | 
| 付款人邮政编码 |  与费用计入的账户关联的账单地址中的邮政编码。  | 
| ISV 账户 ID | 产品或服务所有者的标识符。 | 
| ISV 公司名称 | 产品或服务所有者的企业名称。 | 
| 产品 ID |  软件产品的友好型唯一标识符。  | 
| 支付状态 | 与发票关联的状态，用于确认 AWS 未向您的银行账户支付任何款项、部分或全部款项。可能的状态包括：已支付、部分支付、支付失败、未支付。 | 
| 已支付净收入 | 向卖家支付的交易总额。如果该金额与“卖家净收入”不相等，则属于部分付款。 | 
| 未支付净收入 | 未向卖家支付的交易总额。如果该金额不为零，说明客户仍有未结清余额。 | 
| 支付期 | 描述应收账款收款的类别范围（例如，未到期，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-exemption-codes)

## 税务控制面板的刷新频率
<a name="publication-schedule"></a>

控制面板每天更新。如果从上游系统收到的最新交易数据延迟，则最新数据可能会延迟 1-2 天才能反映在控制面板上。

## 第 1 部分：控件
<a name="billed-revenue-dashboard-controls"></a>

控制面板的这一部分提供筛选条件，用于细化您的税务数据。您也可以向分析添加筛选条件，例如您想要包含在视觉对象中的日期范围。在控件中选择的筛选条件会更新指标、趋势、细分和精细数据部分中显示的数据。

有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)。

### 控件描述
<a name="control-descriptions"></a>


| 控件名称 | 说明 | 
| --- | --- | 
| 发票 ID  | 为向客户收取的费用分配的 AWS ID。 | 
| 已纳税的客户 ID AWS 账户  | 为订阅产品而征税的账户的 AWS ID。 | 
| AWS 记录在案的卖家 | 为交易提供便利的商业实体的标识符。 | 
| 纳税客户所在国家/地区 | 与纳税客户关联的国家/地区代码，以两个字符表示 | 
| 纳税客户所在的省/自治区/直辖市或区域 | 与纳税客户关联的账单地址中的省/自治区/直辖市或区域。 | 
| 纳税客户所在城市 | 与纳税客户关联的账单地址中的城市 | 
| 应税 | 应税、非应税和退税的源交易。 | 
| 税务责任方 |  `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>

控制面板的这个部分提供指定日期范围内的税务趋势。您可以按指定日期汇总（例如每日、、或 year-over-year）查看趋势 month-over-month quarter-over-quarter，以深入了解税收情况。将提供以下税务趋势信息：
+ **税务趋势 - 金额** - 按发票日期提供选定时间段的应纳税额和税额的概览。
+ **税收趋势 - 发票数量** - 按发票日期提供所选时间段内发票数量的概览。

## 第 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>


| 列 | 说明 | 
| --- | --- | 
| 发票 ID | 分配给开具费用 AWS 账单的发票的 AWS ID。可以是买家商业发票、卖家批发发票或卖家上架费发票。 | 
| 上架费发票 ID | 分配给向卖家开具卖家上架费和增值税的发票的 AWS 编号。 ISVs 仅适用于。 | 
| 行项目 ID | 行项目的唯一标识符。退款交易具有与远期税务交易相同的行项目 ID。 | 
| 客户账单 ID | 客户账单 ID | 
| 税务发票 ID | 在双重开票的情况下，税目对应的税务发票标识符。对于统一开票场景，此字段将为空。 | 
| 税务发票日期 | 税务发票的开具日期。对于统一开票场景，此字段将为空。 | 
| 税务责任方  |  `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/zh_cn/marketplace/latest/userguide/taxation-dashboard.html)退款交易具有与原始远期交易相同的行项目 ID。 | 
| 产品 ID | 软件产品的友好型唯一标识符。 | 
| 产品标题 | 购买的产品的名称。 | 
| 产品税务代码 | 用于标识产品税费属性的标准代码。您可以在创建或修改产品时选择这些属性。 | 
| 发票日期 | 向客户收取产品订阅费用和税费的日期。 | 
| 已纳税的客户 ID AWS 账户  | 纳税客户的 AWS 账户 ID。 | 
| 纳税客户所在国家/地区 | 与纳税客户关联的国家/地区代码，以两个字符表示。 | 
| 纳税客户所在的省/自治区/直辖市或区域 | 与纳税客户关联的账单地址中的省/自治区/直辖市或区域。 | 
| 纳税客户所在城市 | 与纳税客户关联的账单地址中的城市。 | 
| 纳税客户邮政编码 | 用于税务计算的邮政编码。 | 
| 税费类型 | 应用于交易的税费类型。可能的值包括 None、Sales 以及 SellerUse、Tax registration type、VAT、CNPJ、IGST、CT。 | 
| 管辖区级别 | 用于税务位置的地址的管辖区级别。可能的值为 State、County、City 和 District。 | 
| 纳税管辖区 | 纳税管辖区的名称。 | 
| 显示价格应税类型 | 向客户显示的价格的纳税类型。所有 AWS Marketplace 产品均为独家优惠。 | 
| 税务管辖区税率 | 在管辖区级别应用的税率。 | 
| 税额 | 在管辖区级别收取的税费。 | 
| 货币 | 纳税的货币。例如，如果交易是以美元达成的，则该条目为 USD。 | 
| 法定税额 | 在司法管辖区级别收取的以法定货币显示的税款金额。 | 
| 法定计税货币 | 所收税款的法定货币币种。 | 
| 税费计算原因代码 | 交易是应税、非应税、免税还是零税率，按管辖区级别划分。 | 
| 税费计算日期 | 用于计算交易税费的日期。 | 
| 客户免税证明 ID | 免税证明的证明 ID。 | 
| 客户免税证明 ID 域 | 在 Amazon 系统中存储证明的位置。 | 
| 客户免税证明级别 | 提供免税的管辖区级别。 | 
| 客户免税代码 | 指定免税的代码。例如 RESALE。 | 
| 交易参考 ID | 交易的唯一标识符，可帮助您关联 AWS Marketplace 报表中的交易。 | 
| AWS 记录在案的卖家 | 为交易提供便利的商业实体的标识符。 | 
| 买家发票 ID | 为向买家收取 AWS 账单的发票分配的 AWS 编号。卖家可以将其批发发票或上架费发票与对应的买家费用相关联。 | 

**注意**  
总税额和买家费用总额已移至[账单收入控制面板](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 | 保险 | 
| IPM | IPM | 
| LB | 图书馆 | 
| MPU | 多重使用点豁免；数字化 Products/Software 豁免 | 
| NA | 美洲原住民  | 
| NAI | 美洲原住民个人 | 
| NP | 非营利组织 | 
| NPR | 非营利性宗教组织 | 
| OT | 其他 | 
| RESALE | 分销商 | 
| SBE | 小型企业豁免 | 
| SLG | 州/地方政府 | 

## 欧盟免税代码
<a name="eu-exemption-codes"></a>


| 免税代码 | 说明 | 
| --- | --- | 
| SpecialOrg | 免征增值税的组织。 | 
| 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>

这一部分提供了筛选条件，用于调整您的协议和续订数据。您可以选择以下筛选条件：

**注意**  
有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](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 标志 |  一个 yes/no 标志，表示协议是否使用渠道合作伙伴的私人报价达成。如果是，则记录卖家是渠道合作伙伴。如果否，则记录卖家是软件制造商（独立软件供应商）。  | 
| ISV AWS 账户 ID |  产品或服务所有者的账户。  | 
| ISV 公司名称 |  产品或服务所有者的企业名称。  | 
| 旧版产品 ID | 软件产品的旧版唯一标识符。 | 
| 产品标题 | 产品的标题。 | 
| 转售授权 ID |  ISV 向渠道合作伙伴提供的转售授权的 ID。  | 
| 转售授权名称 | ISV 向渠道合作伙伴提供的转售授权的名称。 | 
| 经销商 ID AWS 账户  | 从 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>

控制面板的此部分提供指定日期范围内的订阅趋势。您可以按指定日期聚合（例如每日、、或 year-over-year）查看趋势 month-over-month quarter-over-quarter，以深入了解协议。将整体显示协议和续订趋势信息。
+ **订阅趋势** – 根据所选日期聚合筛选条件和所选日期类别筛选条件，提供有效协议数量和已终止协议数量的快照。要根据协议开始日期查看订阅趋势，可以在**选择日期类别**筛选条件中选择**协议开始日期**。要根据协议开始结束查看订阅趋势，可以在**选择日期类别**筛选条件中选择**协议结束日期**。
+ **续订明细** – 提供在特定天数内已结束或即将结束的续订的快照。您可以查看多个时间段的续订明细，例如在 1 到 30 天前、31 到 60 天前或超过 60 天前结束的协议。您还可以筛选即将在 0 到 30 天、31 到 60 天后结束的协议，依此类推。

## 第 5 部分：细分
<a name="agreements-renewals-dashboard-breakdowns"></a>

控制面板的这一部分为您提供跨公司名称 ISVs、活跃订阅者和经销商的业务指标。您可以查看协议数量、已结束的协议 IDs、报价 IDs IDs、续订的协议 IDs和订阅者。

## 第 6 部分：精细数据
<a name="agreements-renewals-dashboard-granular-data"></a>

仪表板的这一部分显示了协议、报价、产品、协议提议者、订阅者、转售授权、经销商和的详细数据。 ISVs

**注意**  
有关如何从快速表中导出和下载数据的更多信息，请参阅*快速用户指南*中的[从视觉对象导出数据](https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html)。

### 精细数据描述
<a name="agreements-renewals-dashboard-granular-data-descriptions"></a>


| 列 | 说明 | 
| --- | --- | 
| 订阅用户公司名称 | 订阅用户公司的名称。 | 
| 订阅者 AWS 账户 ID | 订阅产品的账户的 ID。 | 
| 订阅用户电子邮件域 | 与订阅产品的账户关联的电子邮件域。例如，如果电子邮件地址是 liu-jie@example.com，则该条目为 example.com。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的账单地址中的国家/地区。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市。 | 
| 订阅用户城市 | 与订阅产品的账户关联的账单地址中的城市。 | 
| 订阅用户邮政编码 | 与订阅产品的账户关联的账单地址中的邮政编码。 | 
| 产品标题 | 产品的标题。 | 
| 产品 ID | 软件产品的友好型唯一标识符。 | 
| 旧版产品 ID | 软件产品的旧版唯一标识符。 | 
| 优惠名称 | 卖家定义的优惠名称。 | 
| 优惠 ID | 买家签订的优惠的标识符。 | 
| 优惠可见性 | 优惠是公开、专属还是企业合同优惠。 | 
| 优惠套装 ID | 与该优惠关联的优惠套餐的标识符。 | 
| 协议 ID | 提议者和接受者之间签署的开始使用产品的协议的唯一协议数据源参考。 | 
| 协议开始日期 | 客户开始订阅产品的日期，格式为 MM-DD-YYYY。如果这是未来日期的协议，则该日期可能与接受日期不同。 | 
| 协议接受日期 | 客户订阅产品的日期，格式为 MM-DD-YYYY。 | 
| 协议结束日期 | 合同到期的日期，格式为 MM-DD-YYYY。对于计量/ pay-as-you-go 订阅，此日期设置为 JAN-1-9999。 | 
| Status | 协议的当前状态。支持的状态包括：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/agreements-renewals-dashboard.html)  | 
| 协议条款类型 |  协议创建过程中与接受者相关并被接受的条款类型。 | 
| 预估协议价值 | 协议的预估成本，也称为“合同总价值”或“购买金额”。这适用于以下产品类型：SaaS、专业服务和服务器以及合同或年度定价类型。 | 
| 货币代码 | 与协议预估成本相关的优惠定价货币。 | 
| 经销商公司名称 | 从 ISV 批发购买产品或服务以转售给客户的账户名称。 | 
| 经销商 AWS 账户 ID | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 转售授权 ID | 已注册的机会的唯一标识符。 | 
| 转售授权名称 | 已注册的机会的唯一名称。 | 
| 转售授权说明 | ISV 为已注册商机定义的描述。 | 
| CPPO 标志 | “快速” 中的 “计算” 字段。 | 
| 协议意图 | 如果当前协议是先前协议的续订或升级，则填充之前的 agrement\$1id 列中提供的协议。可能的值包括：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/marketplace/latest/userguide/agreements-renewals-dashboard.html) | 
| 之前的协议 ID | 如果本协议已续订或升级，则为协议参考。 | 
| 下一个协议 ID | 如果当前协议已续订或升级，则为下一个协议的协议 ID。 | 
| 以前的优惠 ID | 如果当前协议已续订或升级，则与之前的协议关联的优惠 ID。 | 
| 下一个优惠 ID | 如果当前协议已续订或升级，则与下一份协议关联的优惠 ID。 | 
| 下一份协议 ID 接受日期 | 买家接受下一份协议的日期。 | 
| 投标人 AWS 账户 ID | 产品或服务所有者的标识符。 | 
| 提议者公司名称 | 产品或服务所有者的企业名称。 | 
| ISV AWS 账户 ID | 卖家的 AWS 标识符。 | 
| ISV 公司名称 | 卖家的公司名称。 | 
| 协议到期（以天为单位） | QuickSight 中的计算字段。从今天起协议到期的剩余天数。 | 
| 协议终止期间 | “快速” 中的 “计算” 字段。协议终止的时间段。 | 

# 使用情况控制面板
<a name="usage-dashboard"></a>

使用情况控制面板为使用 SaaS 和基于服务器使用情况的产品的客户提供可视化和细粒度数据。 AWS Marketplace 卖家可以使用此控制面板跟踪客户对基于使用情况的产品的消费，从而就产品支持、定价、从公开报价转换为私有报价以及产品停产做出决定。该控制面板以滚动窗口的形式提供过去 6 个月的数据。

要打开此控制面板，请登录 [AWS Marketplace 管理门户](https://aws.amazon.com/marketplace/management/)，然后依次选择**见解**、**销售运营**和**使用情况**选项卡。

**注意**  
此控制面板显示在创建优惠时指定的所有维度键的使用情况。例如，对于亚马逊机器映像（AMI）产品，维度键为实例类型，因此优惠中指定的所有实例类型都会显示在此控制面板中，即使是定价为 0 美元的实例类型。要查看在创建优惠时未指定的维度的产品使用情况，请考虑重新发布该产品以包含您需要的维度。

**非美元私募优惠的重要说明**  
使用情况控制面板以美元显示所有私人优惠使用数据，无论您的报价的原始币种是什么（日元、欧元、英镑等）。这是预期行为，因为 AWS 成本和使用量报告 (CUR) 目前仅以美元报告定价。如果您使用美元以外的货币创建了私人报价，请注意：  
控制面板中的所有使用量指标和估算值都将以美元显示
显示的美元金额是从您的原始报价货币转换而来的
您的实际发票和付款将反映您的私人优惠的原始货币
要获得准确的财务对账，请查看您的发票，而不仅仅依靠使用情况控制面板的估算值

**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 点（世界标准时间午夜）更新。请注意，使用情况数据接收自上游数据来源，可能会遇到延迟，为清楚起见，您可以查看具体的使用日期和控制面板上的使用情况报告日期，将两者进行比较。

## 第 1 部分：控件
<a name="usage-dashboard-controls"></a>

控制面板的这个部分提供筛选条件，用于筛选您的使用数据。例如，您可以选择以下筛选条件：

**注意**  
有关筛选的更多信息，请参阅《[*快速用户指南》*中的 Quick 中的筛选数据](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)。

### 控件描述
<a name="usage-control-descriptions"></a>


| 控件名称 | 说明 | 
| --- | --- | 
| 最终用户公司名称 | 使用产品的账户的名称。 | 
| 最终用户 AWS 账户 ID | 使用产品的账户的 ID。 | 
| 最终用户所在国家/地区 | 与使用产品的账户关联的 2 字符国家/地区代码。 | 
| 产品标题 | 产品的标题。 | 
| 产品代码 | 用于计量产品的现有授权产品代码。此值还用于将数据与报告联接，或引用 AWS Marketplace Metering Service 中提供的内容。 | 
| 优惠 ID | 买家签订的优惠的标识符。 | 
| 优惠可见性 | 优惠是公开、专属还是企业合同优惠。 | 
| 优惠套装 ID | 与该优惠关联的优惠套餐的标识符。 | 
| 协议 ID | 提议者和接受者之间签署的开始使用产品的协议的唯一协议数据源参考。 | 
| 维度键 | 与产品使用情况相关的资源类型。维度键适用于 SaaS 和基于服务器使用情况的产品。 | 
| 订阅用户公司名称 | 订阅产品的账户的名称。 | 
| 订阅者 AWS 账户 ID | 订阅产品的账户的 ID。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的 2 字符国家/地区代码。 | 
| 经销商公司名称 | 授权销售产品制造商产品的经销商账户的名称。 | 
| 经销商 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 转售授权 ID | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| CPPO 标志 | 一个 yes/no 标志，表示协议是否使用渠道合作伙伴的私人报价达成。如果是，则记录卖家是渠道合作伙伴。如果否，则记录卖家是产品制造商（独立软件供应商）。 | 

## 第 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>

控制面板的这个部分提供指定日期范围内的使用趋势。您可以按指定日期聚合（例如每日、、或）查看趋势 quarter-over-quarter， year-over-year以深入了解使用情况。 month-over-month也可以选择使用单位类型，以图形方式查看其使用趋势。

## 第 5 部分：细分
<a name="section-4-breakdowns"></a>

控制面板的这一部分为您提供企业的估计使用量指标，包括公司名称、产品标题、维度密钥和所选单位类型的报价 IDs 。您也可以选择要查看的条目数。

## 第 6 部分：精细数据
<a name="section-5-new-product-subscribers"></a>

控制面板的这一部分显示了使用情况、优惠、产品、订阅者、付款人、最终用户、转售授权、经销商和独立软件供应商（）的精细数据。ISVs请注意，精细数据表显示所有单位类型的数据。

在月底账单最终确定之前，应将收入视为估计值。用于结算上个月使用量的发票将在下个月的第二天或第三天提交给买家（例如，在 11 月 1 日至 11 月 30 日之间计量使用量的客户将在 12 月 2 日或 12 月 3 日收到使用量发票）。计量的使用量可能会在实际使用日期的几天后到达此控制面板，因此使用日期和使用情况报告日期可能会有所不同。这意味着您可能需要在整个月中每天访问控制面板以进行当月的 up-to-date跟踪。有关权威的客户账单信息，请参阅**财务运营**选项卡中的[账单收入控制面板](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。 | 
| 最终用户电子邮件域 | 与使用产品的账户关联的电子邮件域。例如，如果电子邮件地址为 abc@example.com，则该条目为 example.com。 | 
| 最终用户城市 | 与使用产品的账户关联的城市。 | 
| 最终用户省/自治区/直辖市 | 与使用产品的账户关联的省/自治区/直辖市。 | 
| 最终用户所在国家/地区 | 与使用产品的账户关联的 2 字符国家/地区代码。 | 
| 最终用户邮政编码 | 与使用产品的账户关联的账单地址中的邮政编码。 | 
| 产品标题 | 产品的标题。 | 
| 旧版产品 ID | 产品的旧版唯一标识符。 | 
| 产品 ID | 产品的友好型唯一标识符。 | 
| 产品代码 | 用于计量产品的现有授权产品代码。此值还用于将数据与报告联接，或引用 AWS Marketplace Metering Service中提供的内容。 | 
| 优惠 ID | 买家签订的优惠的标识符。 | 
| 优惠名称 | 卖家定义的优惠名称。 | 
| 优惠可见性 | 优惠是公开、专属还是企业合同优惠。 | 
| 优惠套装 ID | 与该优惠关联的优惠套餐的标识符。 | 
| 协议 ID | 提议者和接受者之间签署的开始使用产品的协议的唯一协议数据源参考。 | 
| 协议接受日期 | 客户订阅产品时的日期时间戳（UTC 时间）。 | 
| 协议开始日期 | 客户的产品订阅开始时的日期时间戳（UTC 时间）。如果这是未来日期的协议，则该日期可能与接受日期不同。 | 
| 协议结束日期 | 合同的到期日期（UTC 时间）。对于计量/订pay-as-you-go阅，此日期设置为 9999 年 1 月 1 日上午 12:00。 | 
| 协议条款类型 | 协议创建过程中与接受者相关并被接受的条款类型。 | 
| 维度键 | 与产品使用情况相关的资源类型。维度键适用于 SaaS 和基于服务器使用情况的产品。 | 
| Region | 买家部署 Amazon EC2 实例的区域。 | 
| 估计使用量 | 为产品记录的使用量。 | 
| 使用量单位类型 | 记录使用量的单位类型。 | 
| 每单位使用率 | 每单位的使用率。 | 
| 冲锋物品描述 | 对收费的描述。 | 
| 估计收入 | 产品使用量带来的估计收入。在月底账单最终确定之前，应将收入视为估计值。用于结算上个月使用量的发票将在下个月的第二天或第三天提交给买家。 | 
| 货币 | 交易的货币。例如，如果交易是以美元达成的，则该条目为 USD。 | 
| 订阅用户公司名称 | 订阅产品的账户的名称。 | 
| 订阅者 AWS 账户 ID | 订阅产品的账户的 ID。 | 
| 订阅用户电子邮件域 | 与订阅产品的账户关联的电子邮件域。例如，如果电子邮件地址为 abc@example.com，则该条目为 example.com。 | 
| 订阅用户城市 | 与订阅产品的账户关联的账单地址中的城市。 | 
| 订阅用户省/自治区/直辖市或区域 | 与订阅产品的账户关联的账单地址中的省/自治区/直辖市。 | 
| 订阅用户国家/地区 | 与订阅产品的账户关联的账单地址中的国家/地区。 | 
| 订阅用户邮政编码 | 与订阅产品的账户关联的账单地址中的邮政编码。 | 
| 付款人公司名称 | 为产品付款的账户名称。 | 
| 付款人身份证 AWS 账户  | 为产品付款的账户 ID。 | 
| 付款人电子邮件域 | 与为产品付款的账户关联的电子邮件域。例如，如果电子邮件地址为 abc@example.com，则该条目为 example.com。 | 
| 付款人城市 | 与为产品付款的账户关联的账单地址中的城市。 | 
| 付款人省/自治区/直辖市 | 与为产品付款的账户关联的账单地址中的省/自治区/直辖市。 | 
| 付款人国家/地区 | 与为产品付款的账户关联的账单地址中的国家/地区。 | 
| 付款人邮政编码 | 与为产品付款的账户关联的账单地址中的邮政编码。 | 
| 经销商公司名称 | 从 ISV 批发购买产品或服务以转售给客户的账户名称。 | 
| 经销商 ID AWS 账户  | 从 ISV 批发购买产品或服务以转售给客户的账户 ID。 | 
| 转售授权 ID | 已注册的转售机会的唯一标识符。 | 
| 转售授权名称 | 已注册的转售机会的唯一名称。 | 
| 转售授权说明 | 对已注册的转售机会的说明。 | 
| CPPO 标志 | 一个 yes/no 标志，表示协议是否使用渠道合作伙伴的私人报价达成。如果是，则记录卖家是渠道合作伙伴。如果否，则记录卖家是产品制造商（ISV）。 | 
| ISV 公司名称 | 产品或服务所有者的名称。 | 
| ISV ID AWS 账户  |  产品或服务所有者的标识符。 | 

# 营销控制面板
<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/zh_cn/marketplace/latest/userguide/customer-agreements-dashboard.html)  | 

有关筛选的更多信息，请参阅 *Amazon 快速用户指南*[中的在 Quick 上筛选数据](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)。

## 第 2 部分：日期过滤器深入探索
<a name="customer-agreements-date-deep-dive"></a>

此日期筛选条件适用于客户协议控制面板上的所有指标。  

例如，当您使用默认 year-to-date筛选值时，会显示以下指标：


|  指标  |  说明  | 
| --- | --- | 
|  公开优惠协议数量  |  优惠可见性为公开优惠，且年初至今至少有 1 天活跃期的协议数量。 | 
|  专属优惠协议数量  |  优惠可见性为专属优惠，且年初至今至少有 1 天活跃期的协议数量。 | 
|  新的公开优惠协议数量  |  优惠可见性为公开优惠，且接受日期在年初至今范围内的协议数量。 | 
|  新的专属优惠协议数量  |  优惠可见性为专属优惠，且接受日期在年初至今范围内的协议数量。 | 
|  活跃客户  |  标识为订阅用户 AWS 账户 ID 且年初至今至少有 1 份活跃协议的唯一客户的数量。活跃协议是指在相应时间段内至少有 1 天活跃期的协议。 | 
|  新的付费客户  |  标识为订阅用户 AWS 账户 ID 且第一个账单月份在年初至今范围内的唯一客户的数量。 | 

## 第 3 节：公开发行和私募协议
<a name="customer-agreements-public-private-agreements"></a>

控制面板的这个部分显示您的协议概览。关键绩效指标 (KPIs) 包括公开发行协议的数量、私募协议的数量、新的公开发行协议的数量以及新的私募协议的数量。您可以看到音量和百分比中的 year-over-year或 period-over-period变化。您可以通过更新筛选条件部分中的日期筛选条件来更新日期范围。

 *协议*是提议者（产品或服务所有者）和接受者（客户）之间签署的开始使用产品的合同。

**注意**  
新的协议指标包括活跃、已过期、已取消和已终止的协议。

 下表列出并描述了协议状态。


|  状态  |  说明  | 
| --- | --- | 
|  活跃  |  协议的部分或全部条款已生效。 | 
|  已过期  |  协议已在预先商定的结束日期结束。 | 
|  已取消  |  接受者选择在协议结束日期之前结束协议。 | 
|  已终止  |  由于 AWS 发起的终止事件（例如付款失败），协议在预先商定的结束日期之前结束。 | 
|  已续订  |  通过使用自动续订等功能，协议已续订为新协议。 | 
|  已替换  |  已通过替换优惠来替换协议。 | 

## 第 4 部分：卖家指标
<a name="section-5-customer-metrics"></a>

控制面板的此部分提供指定日期范围内的客户趋势。 KPIs包括活跃客户数量和新付费客户数量。
+ **月度趋势** – 根据图表中的筛选条件，提供活跃客户数量和新付费客户数量的月度视图。 
+ **客户指标** – 根据所选的指标筛选条件，提供活跃客户数量和新付费客户数量的相关数据。您可以选择客户细分或行业，以了解各自对总客户指标的贡献。

**注意**  
协议具有给定状态。有关状态的信息，请参阅[上一部分中的表格](#customer-agreements-public-private-agreements)。

下表列出并描述了指标。


|  指标  |  说明  | 
| --- | --- | 
|  公开优惠协议  | 标识为 IDs 具有公开报价可见性的协议的数量；协议期限与选定的日期范围至少有一天重叠；长度在协议开始日期和协议结束日期之间确定。 | 
|  专属优惠协议  | 标识为 IDs 具有私募报价可见性的协议的数量；协议期限与选定的日期范围至少有一天重叠；期限在协议开始日期和协议结束日期之间确定。 | 
|  新的公开优惠协议  | 标识为协议 ID 且具有公开优惠可见性的协议数量；协议接受日期在所选日期范围内。 | 
|  新的专属优惠协议  |  标识为 IDs 具有私募报价可见性的协议的数量；协议接受日期在选定的日期范围内。 | 
|  活跃客户  | 标识为订阅者 AWS 账户 IDs 且至少有一份有效协议的客户数量；协议期限至少有一天与所选日期范围重叠  | 
| 新的付费客户  |  被标识为订阅者 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）。您可以选择自定义特定的开始和结束日期。 | 

有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)。

## 第 2 部分：日期过滤器深入探索
<a name="date-filter-deep-dive"></a>

 此日期筛选条件适用于产品页面表现控制面板上的所有指标。  

 例如，当您使用默认 year-to-date筛选值时，会显示以下指标：


|  指标  |  说明  | 
| --- | --- | 
|  唯一访客  |  年初至今访问过 AWS Marketplace 房源页面的独立个人数量。 | 
|  新的公开优惠协议  |  优惠可见性为公开优惠，且年初至今至少有 1 天活跃期的协议数量。 | 
|  新的唯一访客  |  年初至今首次访问 AWS Marketplace 房源页面的独立个人数量。 | 
|  唯一回访访客  |  访问过 AWS Marketplace 房源页面、之前在选定年份开始之前访问过并在年初至今再次访问过的个人数量。 | 

## 第 3 部分：摘要指标
<a name="listing-summary-metrics"></a>

控制面板的这个部分显示您的流量和公开优惠协议的摘要可视化内容。关键绩效指标 (KPIs) 包括独立访客数量、新的公开发售协议数量、新的独立访客数量以及回访的独立访客数量。您可以看到音量和百分比中的 year-over-year或 period-over-period变化。您可以通过更新筛选条件部分的日期字段中的日期标准来更新日期范围。


|  指标  |  说明  | 
| --- | --- | 
|  唯一访客  |  访问过 AWS Marketplace 房源页面的独立个人数量。 | 
|  协议  |  提议者（产品或服务所有者）和接受者（客户）之间签署的开始使用产品的合同。 | 
|  新的公开优惠协议  |  优惠可见性为公开优惠，且接受日期在选定日期范围内的协议数量，包括处于活跃、已过期、已取消和已终止状态的协议。 | 
|  状态  | 活跃 - 协议的部分或全部条款已生效。已过期 - 协议已在预先商定的结束日期结束。已取消 - 接受者选择在协议结束日期之前结束协议。已终止 - 由于 AWS 发起的终止事件（例如付款失败），协议在预先商定的结束日期之前结束。已续订 - 通过使用自动续订等功能，协议已续订为新协议。已替换 - 已通过替换优惠来替换协议。 | 

## 第 4 部分：每月趋势和渠道转化率
<a name="monthly-trend-funnel"></a>

控制面板的这个部分提供指定日期范围内的流量和协议趋势。关键绩效指标包括唯一访客数量和新协议数量，后者指的是新的公开优惠协议。**按月统计的唯一访客** - 提供唯一访客数量的月度视图。每月的独立访客总数可能超过摘要指标部分中的独立访客总数，因为一个独立访客可以访问多个月。 **按月划分的新协议-** 提供新公开募股协议数量的月度视图。 **漏斗转换-** 提供 step-by-step转化视图。它包括产品页面、采购页面、配置页面和履行页面。您可以选择唯一访客、页面浏览量和唯一账户作为显示在条形图中的指标。当您将鼠标悬停在每个条形上时，可以看到转化百分比，它是当前条形值相对于前一个条形值的百分比。


|  指标  |  说明  | 
| --- | --- | 
|  唯一访客  |  访问过 AWS Marketplace 房源页面的独立个人数量。 | 
|  页面浏览量  |  AWS Marketplace 列表页面的访问次数。 | 
|  唯一账户  |  与访客关联的唯一 AWS 账户 ID 的数量。此指标仅适用于访客进行身份验证后。 | 

## 第 5 部分：按渠道划分的流量趋势
<a name="traffic-trend-by-channel"></a>

控制面板的这个部分提供每月流量趋势的深入数据。您可以选择唯一访客和页面浏览量作为显示在条形图中的指标。您可以在渠道筛选条件中选择一个或多个渠道，以查看所选渠道的月度趋势。

## 第 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 主机搜索和 M AWS arketplace 搜索等 AWS 渠道访问您房源的独特访客。 | 
|  AWS 营销活动  | 通过 AWS 主导的市场活动和付费推广活动进入您产品页面的唯一访客。 | 

## 第 8 部分：网络流量来源明细
<a name="traffic-source-breakdown"></a>

Web 流量来源明细表提供了推动流量的营销活动的精细明细。
+ **流量来源**-包括 AWS由主导和卖家主导的两个主要类别。
+ **流量类型**-包括卖家自然发现、卖家主导的营销活动、 AWS 自然发现和主 AWS导的营销活动。
+ **渠道** - 包括各种营销策略，例如付费展示、付费搜索、付费社交媒体、电子邮件、自然、内部网站流量、外部链接等。
+ **发布商**-指发布广告活动的实体，包括 Facebook、Google、 LinkedIn、 AWS、卖家主导等。
+ **推广** - 指已为其生成专用跟踪代码的特定市场活动，例如 `psm_linked_post_free-trial-global-ver-a`。


|  指标  |  说明  | 
| --- | --- | 
|  带来的协议  |  每个推广活动的访问所带来的协议总数。 | 
|  转化率  |  每个推广活动带来的协议除以唯一访客。 | 

# 搜索表现控制面板
<a name="search-performance-dashboard"></a>

**搜索效果**控制面板提供有关您的 AWS Marketplace 房源在 AWS Marketplace 搜索体验中的表现的指标。您可以使用该控制面板来提高产品页面的可发现性和表现。该控制面板会跟踪展示次数、点击次数和点击率。它还会跟踪您提供的和客户使用的热门关键字，并根据常见的客户搜索提供关键字建议。

控制面板中的洞见可以帮助您完善产品页面以提高可见性，将关键字与客户偏好相匹配，并为您的 AWS Marketplace业务带来更多合格的流量。  

要打开控制面板，请启动 AWS Marketplace 管理门户并前往 **Insights** 选项卡。

有关控制该控制面板访问权限的更多信息，请参阅本节前面的[卖家控制面板](dashboards.md)。

## 第 1 部分：访问控制面板
<a name="search-performace-access"></a>

 要解锁此控制面板，您必须成为 [AWS Marketplace Seller Prime 计划](https://pages.awscloud.com/aws-marketplace-seller-prime.html)的成员。

在您注册 Seller Prime 计划后，卖家账户的系统管理员可以使用中的 “**见解**” 选项卡启动**搜索绩效**控制面板。 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 搜索关键字推荐**或**按产品类别列出的热门搜索关键字**表。  | 

 有关筛选的更多信息，请参阅《亚马逊* QuickSight用户指南》中的 “在亚马逊 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 提供展示次数、点击次数和点击率。

 您可以看到 year-over-year音量和百分比的 period-over-period变化。您也可以更改日期范围。


| 指标 | 说明 | 
| --- | --- | 
| 展示次数 | 您的产品页面出现在 AWS Marketplace前 20 个搜索结果中的次数。 | 
| 点击次数 | 用户在 AWS Marketplace 搜索结果中点击您的房源的次数。 | 
| 点击率（CTR） | 点击次数和展示次数的比率。衡量您的产品页面能否在搜索结果中吸引客户的指标。 | 

## 第 4 部分：展示次数、点击次数和点击率的月度趋势
<a name="impressions-click-throughs"></a>

 控制面板的这一部分提供指定日期范围内的月度趋势。它 KPIs 提供了展示次数、点击次数和点击率。

## 第 5 部分：AWS Marketplace 搜索关键字推荐
<a name="keyword-recommendations"></a>

 控制面板的这一部分提供一个表格，其中列出了您当前的关键字，以及每个产品页面的推荐关键字。


| 列名称 | 说明 | 
| --- | --- | 
| 产品标题 | 产品标题。该链接可将您带到 AWS Marketplace Management Portal 中的产品概述页面，您可以在其中管理和编辑产品页面。 | 
| 当前关键字 | 您在 AWS Marketplace 管理门户网站的 “更新产品信息” 部分中提供的关键字。 | 
| 表现最好的关键字 | 客户搜索您的产品时，排名前五的关键字。 | 
| AWS推荐的关键字 | 买家在搜索类似产品时使用最多的关键字。 | 
| 预计流量增幅百分比 | 如果您采用推荐的关键字，有可能获得的流量增幅。不受日期筛选条件影响。 | 

**注意**  
虽然关键字很重要，但其他因素也会影响搜索结果。  
产品页面优化   
 优化产品页面的其他部分，例如简短描述和详细描述。
考虑提供诸如免费试用之类的功能，以增强产品页面的吸引力。
使关键字与产品页面和目标客户匹配  
尽可能使产品页面与常用关键字匹配。
仅使用与您的产品及其功能相关的关键字。否则，您的产品页面可能会出现在更多搜索中，但选择它们的用户会更少。
了解关键字变体  
请记住，类似的术语，例如“git”和“gitops”，可能会被视为相同的搜索词。
评估所有变体的相关性，并相应地调整关键字。
更新关键字  
在中 AWS Marketplace 管理门户，打开**产品**菜单并选择一个产品类别。
选择您的产品链接，再选择**产品信息**选项卡，然后导航至**提供产品信息**页面。
向下滚动到**AWS Marketplace 可发现性**部分，找到** AWS Marketplace 搜索结果的关键词**，然后调整关键字。

## 第 6 部分：按产品类别划分的热门搜索关键字
<a name="top-keywords-by-product-category"></a>

在每个产品类别中，客户搜索相似产品时最常用的前五大关键字。此控制页面上的其他产品和日期筛选条件不会影响此数据。

# 通过 AWS 仪表板了解 “购买”
<a name="buy-with-aws-dashboard"></a>

“**使用购买 AWS**方式” 控制面板概述了选择您的 “使用购买方式” AWS call-to-action 按钮并访问 “****带 AWS**采购购买**” 页面的客户创建的网络流量、互动和协议。 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>

 该部分提供以下数据筛选条件。


|  筛选条件名称  |  说明  | 
| --- | --- | 
| 产品标题 | 产品的标题。 | 
| 产品编号 | 软件产品的友好型唯一标识符。 | 
| 日期筛选条件 | 可按过去 30 天、60 天、90 天、最近 12 个月或本年度至今筛选。选择自定义可输入其他开始日期和结束日期。 | 

有关筛选的更多信息，请参阅[《*快速用户指南》*中的在 Quick 上筛选数据](https://docs.aws.amazon.com/quicksight/latest/user/adding-a-filter.html)。

## 第 2 部分：摘要指标
<a name="buy-with-aws-summary-metrics"></a>

此部分显示有关 “**使用购买**方式 AWS call-to-action” 按钮和 “通过 AWS采购**购买**” 页面的信息。

下表列出并描述了指标。要更新日期范围，请更改**筛选条件**部分中的日期标准。


|  指标  |  说明  | 
| --- | --- | 
| 按钮总点击量  | 卖家网站上的 call-to-action按钮（例如 “使用 AWS 购买”）的总点击次数。 | 
|  AWS 页面浏览量下的 “购买” 数量  | 通过 AWS采买采购页面的总访问次数，包含重复访问。 | 
| “使用购买方式 AWS ” 页面上的协议总数  | 在通过 AWS采买采购页面上创建的协议总数量。   | 

## 第 3 部分：总点击量及页面浏览量与协议总数趋势数据
<a name="buy-with-aws-clicks-views"></a>

此部分提供指定日期范围内的每月或每周趋势。下表列出并描述了 KPIs：


| 指标 | 说明 | 
| --- | --- | 
| **按钮总点击量** | 卖家网站上 call-to-action按钮的总点击量。 | 
| **页面浏览量** | **通过 AWS 采买**采购页面的总访问次数。使用**数据显示依据**列表可选择按月或按周查看。 | 
| **协议总数** | 在**通过 AWS 采买**采购页面上创建的协议总数量。使用**数据显示依据**列表可选择按月或按周查看。 | 

## 第 4 部分：AWS 登录页面流失率
<a name="buy-with-aws-drop-off-rate"></a>

此部分显示 AWS 登录页面的丢失率。 费率是登录并创建协议的用户与仅登录的用户数量的比率。使用**数据显示依据**列表可按周或月进行筛选。

## 第 5 部分：“通过 AWS 采购购买” 页面上的互动
<a name="buy-with-aws-engagements"></a>

此部分提供指定日期范围内的摘要指标和趋势数据。下表列出并描述了指标。使用筛选条件部分中的日期字段可更新日期范围。


| 指标 | 说明 | 
| --- | --- | 
| 独立访客总数 | 采购页面的独立用户总数量。 | 
| 退回邮件率 | 仅浏览一个页面后便登录退出的用户数，与浏览多个页面用户数的比率。 | 
| 用户平均停留时长（分钟） | 用户从登录页面到离开页面的总时长。 | 

## 第 6 部分：“通过 AWS 采购购买” 页面上的参与度指标的趋势数据
<a name="buy-with-aws-procurement-page-trends"></a>

此图表显示[第 5 部分](#buy-with-aws-engagements)中指标的每月或每周趋势。使用**数据显示依据**列表可在每月和每周视图之间进行选择。  