教程:创建分页报表并将其上传到 Power BI 服务Tutorial: Create a paginated report and upload it to the Power BI service

在本教程中,你将连接到一个示例 Azure SQL 数据库。In this tutorial, you connect to a sample Azure SQL database. 然后,使用 Power BI 报表生成器中的向导创建一个分页报表,其中包含涵盖多个页的表。Then you use a wizard in Power BI Report Builder to create a paginated report with a table that wraps to multiple pages. 接着将分页报表上传到 Power BI 服务高级容量中的工作区。Then you upload the paginated report to a workspace in a Premium capacity in the Power BI service.

Power BI 服务中的分页报表

下面介绍将在本教程中完成的步骤:Here are the steps you complete in this tutorial:

  • 创建 Azure 示例数据库。Create an Azure sample database.
  • 借助向导在 Power BI 报表生成器中创建矩阵。Create a matrix in Power BI Report Builder with the help of a wizard.
  • 设置每页包含标题、页码和列标题的报表的格式。Format the report with title, page numbers, and column headings on each page.
  • 设置货币格式。Format the currency.
  • 将报表上传到 Power BI 服务。Upload the report to the Power BI service.

如果没有 Azure 订阅,请在开始之前先创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

先决条件Prerequisites

以下时创建分页报表的先决条件:Here are the prerequisites for creating the paginated report:

以下是将分页报表上传到 Power BI 服务的先决条件:Here are the prerequisites for uploading your paginated report to the Power BI service:

使用向导创建矩阵Create the matrix with a wizard

  1. 从计算机启动 Power BI 报表生成器。Start Power BI Report Builder from your computer.

    随即将打开“入门” 对话框。The Getting Started dialog box opens.

    报表生成器入门

  2. 在左窗格中,验证是否已选中“新建报表” ,并在右窗格中选择“表或矩阵向导” 。In the left pane, verify that New Report is selected, and in the right pane, select Table or Matrix Wizard.

  3. 在“选择数据集” 页面中,选择“创建数据集” > “下一步” 。In the Choose a dataset page, select Create a dataset > Next.

    创建数据集

  4. 在“选择与数据源的连接” 页面中,选择“新建” 。In the Choose a connection to a data source page, select New.

    新建数据源

    随即将打开“数据源属性” 对话框。The Data Source Properties dialog box opens.

  5. 可以使用字符和下划线为数据源命名。You can name a data source anything you want, using characters and underscores. 对于本教程,在“名称” 框中,键入 MyAzureDataSource 。For this tutorial, in the Name box, type MyAzureDataSource.

  6. 在“选择连接类型” 框中,选择“Microsoft Azure SQL 数据库” 。In the Select connection type box, select Microsoft Azure SQL Database.

  7. 选择“连接字符串” 框旁边的“生成” 。Select Build next to the Connection string box.

    数据源属性 - 生成

  8. 在 Azure 中:返回到 Azure 门户并选择“SQL 数据库” 。In Azure: Go back to the Azure portal and select SQL databases.

  9. 在本文的“先决条件” 部分的快速入门“在 Azure 门户中创建 Azure SQL 数据库示例”中选择创建的 Azure SQL 数据库。Select the Azure SQL database you created in the quickstart "Create an Azure SQL database sample in the Azure portal" in the Prerequisites section of this article.

  10. 在“概述” 选项卡上,复制“服务器名称” 框中的值。On the Overview tab, copy the value in the Server name box.

  11. 在报表生成器中:在“连接属性” 对话框的“服务器名称” 下粘贴复制的服务器名称。In Report Builder: In the Connection Properties dialog box, under Server name paste the server name you copied.

  12. 对于“登录到服务器” ,请确保选中“使用 SQL Server 身份验证” ,然后键入在 Azure 中为示例数据库创建的用户名和密码。For Log on to the server, make sure Use SQL Server Authentication is selected, then type the user name and password you created in Azure for the sample database.

  13. 在“连接到数据库” 下,选择下拉箭头并选择在 Azure 中创建的数据库名称。Under Connect to a database, select the drop-down arrow and select the database name you created in Azure.

    数据源连接属性

  14. 选择“测试连接” 。Select Test Connection. 会看到“测试结果” 消息:“测试连接成功” 。You see the Test results message that Test connection succeeded.

  15. 选择“确定” > “确定” 。Select OK > OK.

    现在,在“连接字符串” 框中,报表生成器显示刚刚创建的连接字符串。Now in the Connection string box, Report Builder displays the connection string you just created.

    数据源连接字符串

  16. 选择“确定”。 Select OK.

  17. 在“选择与数据源的连接” 页中,会在刚刚创建的数据源连接下看到“(在此报表中)”。In the Choose a connection to a data source page, you see "(in this Report)" under the data source connection you just created. 选择该数据源 >“下一步” 。Select that data source > Next.

    我的 Azure 数据源

  18. 在框中键入相同的用户名和密码。Type the same user name and password in the box.

  19. 在“设计查询” 页中,依次展开 SalesLT、Tables,然后选择以下表:In the Design a query page, expand SalesLT, expand Tables, and select these tables:

    • 地址Address
    • 客户Customer
    • 产品Product
    • ProductCategoryProductCategory
    • SalesOrderDetailSalesOrderDetail
    • SalesOrderHeaderSalesOrderHeader

    由于选择了“关系” > “自动检测” ,因此,报表生成器会检测这些表之间的关系。Because Relationships > Auto Detect is selected, Report Builder detects the relationships between these tables.

    设计查询

  20. 选择“运行查询” 。Select Run Query. 报表生成器显示“查询结果” 。Report Builder displays the Query results.

    查询结果

  21. 选择“下一步” 。Select Next.

  22. 在“选择数据集” 页中,选择刚刚创建的数据集 >“下一步” 。In the Choose a dataset page, choose the dataset you just created > Next.

    选择数据集

  23. 在“排列字段” 页中,将这些字段从“可用字段” 框拖动到“行组” 框:In the Arrange fields page, drag these fields from the Available fields box to the Row groups box:

    • CompanyNameCompanyName
    • SalesOrderNumberSalesOrderNumber
    • Product_NameProduct_Name
  24. 将这些字段从“可用字段” 框拖动到“值” 框:Drag these fields from the Available fields box to the Values box:

    • OrderQtyOrderQty
    • 单价UnitPrice
    • LineTotalLineTotal

    报表生成器自动计算“值” 框中字段的总和。Report Builder automatically made the fields in the Values box sums.

    排列字段

  25. 在“选择布局” 页中,保留所有默认设置,但清除“展开/折叠组” 。In the Choose the layout page, keep all the default settings, but clear Expand/collapse groups. 一般情况下,展开/折叠组功能非常强大,但这次希望表包装到多个页。In general, the expand/collapse groups feature is great, but this time you want the table to wrap to multiple pages.

  26. 选择“下一步” > “完成” 。Select Next > Finish. 该表显示在设计图面上。The table is displayed on the design surface.

所创建的内容What you've created

让我们停下来看一下向导的结果。Let's pause for a moment to look at the results of the wizard.

矩阵向导的结果

  1. 在“报表数据”窗格中,可以看到嵌入的 Azure 数据源以及基于它的嵌入数据集,这两者都是你创建的。In the Report Data pane, you see the embedded Azure data source and the embedded dataset based on it, both of which you created.

  2. 设计图面约 6 英寸宽。The design surface is about 6 inches wide. 在设计图面上,可以看到矩阵、显示列标题和占位符值。On the design surface, you see the matrix, displaying column headings and placeholder values. 矩阵有六列,看起来只有五行高。The matrix has six columns and appears to be only five rows tall.

  3. 订单数量、单价和行合计都是总和,并且每个行组都有一个小计。Order Qty, Unit Price, and Line Total are all sums, and each row group has a subtotal.

    但仍看不到实际的数据值。You still don't see actual data values. 需要运行报表才能看到它们。You need to run the report to see them.

  4. 在“属性”窗格中,选定的矩阵称为 Tablix1。In the Properties pane, the selected matrix is called Tablix1. 报表生成器中的 tablix 是一个以行和列显示数据的数据区域。A tablix in Report Builder is a data region that displays data in rows and columns. 它可以是表,也可以是矩阵。It can be either a table or a matrix.

  5. 在“分组”窗格中,你将看到在向导中创建的三个行组:In the Grouping pane, you see the three row groups you created in the wizard:

    • CompanyNameCompanyName
    • 销售订单Sales Order
    • 产品名称Product Name

    该矩阵不包含任何列组。This matrix doesn't have any column groups.

运行报表Run the report

若要查看实际值,需要运行报表。To see the actual values, you need to run the report.

  1. 在“主页” 工具栏中选择“运行” 。Select Run in the Home toolbar.

    现在,你将看到这些值。Now you see the values. 矩阵包含的行数比你在“设计”视图中看到的要多得多!The matrix has many more rows than you saw in Design view! 请注意,报表生成器会显示“第 1 页,共 2 页?”。Note that Report Builder says it's page 1 of 2?. 报表生成器尽可能快地加载报表,因此它一次只能检索几页的足够数据。Report Builder loads the report as quickly as possible, so it only retrieves enough data for a few pages at a time. 问号表示报表生成器尚未加载所有数据。The question mark indicates that Report Builder hasn't loaded all the data yet.

    运行报表

  2. 选择“打印布局” 。Select Print Layout. 打印时,报表将采用此格式。The report will be in this format when you print it. 报表生成器现在知道报表有 33 页,并在页脚中自动添加了日期和时间戳。Report Builder now knows the report has 33 pages, and has automatically added a date and time stamp in the footer.

设置报表格式Format the report

现在,你有包含一个包装到 33 页的矩阵的报表。Now you have a report with a matrix that wraps to 33 pages. 让我们添加一些其他功能并改进报表的外观。Let's add some other features and improve how it looks. 如果你想了解进展如何,可以在每个步骤后运行报表。You can run the report after every step, if you want to see how it's coming along.

  • 在功能区的“运行” 选项卡上,选择“设计” ,以便继续进行修改。On the Run tab of the Ribbon, select Design, so you can continue modifying it.

设置页宽Set page width

通常,设置分页报表的格式以便适合打印,典型页面为 8 1/2 X 11 英寸。Typically a paginated report is formatted for printing, and a typical page is 8 1/2 X 11 inches.

  1. 拖动标尺以使设计图面宽 7 英寸。Drag the ruler to make the design surface 7 inches wide. 每侧默认边距为 1 英寸,因此侧边距需要更窄。The default margins are 1 inch on each side, so the side margins need to be narrower.

  2. 单击设计图面周围的灰色区域以显示“报表” 属性。Click in the gray area around the design surface to show the Report properties.

    如果未看到“属性”窗格,请单击“视图” 选项卡 >“属性” 。If you don’t see the Properties pane, click the View tab > Properties.

  3. 展开“边距” 并将“左” 和“右” 从 1 英寸更改为 0.75 英寸。Expand Margins and change Left and Right from 1in to 0.75in.

    设置页边距

添加报表标题Add a report title

  1. 选择页面顶部的“单击以添加标题” ,然后键入“按公司统计的销售量” 。Select the words Click to add title at the top of the page, then type Sales by Company.

  2. 选择标题文本,然后在“字体” 下的“属性”窗格中,将“颜色” 更改为“蓝色” 。Select the title text, and in the Properties pane under Font, change Color to Blue.

添加页码Add a page number

你会注意到报表的页脚中包含日期和时间戳。You noticed the report has a date and time stamp in the footer. 也可以在页脚中添加页码。You can add a page number to the footer, too.

  1. 在设计图面的底部,会在页脚右侧看到 [&ExecutionTime]。At the bottom of the design surface, you see [&ExecutionTime] on the right in the footer.

  2. 在“报表数据”窗格中,展开“内置字段”文件夹。In the Report Data pane, expand the Built-in Fields folder. 将“页码” 拖动到页脚左侧,与 [&ExecutionTime] 处于同一高度。Drag Page Number to the left side of the footer, at the same height as [&ExecutionTime].

  3. 拖动 [&PageNumber] 框的右侧使其成为正方形。Drag the right side of the [&PageNumber] box to make it square.

  4. 在“插入” 选项卡上,选择“文本框” 。On the Insert tab, select Text Box.

  5. 单击 [&PageNumber] 的右侧,键入“of”,然后使文本框成为正方形。Click to the right of [&PageNumber], type "of", then make the text box square.

  6. 将“总页数” 拖动到“of”右侧的页脚中,然后拖动其右侧也使其成为正方形。Drag Overall Total Pages to the footer, to the right of "of", then drag its right side to make it square, too.

    拖动页码

使表更宽Make the table wider

现在,可以使矩阵足够宽以填充页面的宽度,并使文本列更宽,以便名称不会滚动太多。Now you can make the matrix wide enough to fill the width of the page, and make the text columns wider so the names don't scroll as much.

  1. 选择矩阵,然后选择“公司名称”列。Select the matrix, then select the Company Name column.

  2. 将鼠标悬停在“公司名称”列右边缘矩阵顶部的灰色栏上。Hover over the gray bar at the top of the matrix at the right edge of the Company Name column. 向右拖动,直到列在 1 3/8 英寸处结束。Drag to the right, until the column ends at 1 3/8 inches.

    拖动列的右边缘

  3. 拖动“产品名称”的右边缘,直到列在 3 3/4 英寸处结束。Drag the right edge of Product name until the column ends at 3 3/4 inches.

现在矩阵几乎和打印区域一样宽。Now the matrix is almost as wide as the print area.

设置货币格式Format the currency

你可能在运行报表时注意到,尚未将美元金额设置为货币格式。If you noticed when you ran the report, the dollar amounts aren't formatted as currency yet.

  1. 选择左上角的 [Sum(OrderQty)] 单元格,按住 Shift 键,然后选择右下角 [Sum(LineTotal)] 单元格。Select the upper-left [Sum(OrderQty)] cell, hold down the Shift key, and select lower-right [Sum(LineTotal)] cell.

    选择包含货币值的单元格

  2. 在“主页” 选项卡上,选择美元符号 ($ ) 货币符号,然后选择“占位符样式” > “示例值” 旁边的箭头。On the Home tab, select the dollar sign ($) currency symbol, then select the arrow next to Placeholder styles > Sample Values.

    显示示例值

    现在,可以看到将这些值设置为货币格式。Now you can see the values are formatted as currency.

    货币示例值

在每个页上添加列标题Add column headers on each page

在将报表发布到 Power BI 服务之前,还需要进行一次格式设置方面的改进:使列标题显示在报表的每个页上。One more formatting improvement before publishing the report to the Power BI service: making the column headers show up on each page in the report.

  1. 在“分组”窗格顶部栏的最右端,选择下拉箭头 >“高级模式” 。In the far-right end of the top bar in the Grouping pane, select the drop-down arrow > Advanced Mode.

    打开“高级模式”

  2. 选择“行组” 中的顶部“静态” 栏。Select the top Static bar in the Row Groups. 将看到矩阵中的“公司名称”单元格已被选中。You see that the Company Name cell in the matrix is selected.

    选择“静态”组

  3. 在“属性” 窗格中,会看到“Tablix 成员” 的属性。In the Properties pane, you're looking at the properties for Tablix Member. 将“KeepWithGroup” 设置为“After” ,并将“RepeatOnNewPage” 设置为“True” 。Set KeepWithGroup to After and RepeatOnNewPage to True.

    设置 RepeatOnNewPage

    现在是运行报表并查看其外观的时候了。It's time to run the report and see how it looks now.

  4. 选择“主页” 选项卡上的“运行” 。Select Run on the Home tab.

  5. 选择“打印布局” (如果尚未选择)。Select Print Layout, if it's not already selected. 现在,报表有 29 页。Now the report has 29 pages. 滚动几页。Scroll through a few pages. 会看到已设置货币格式,列在每个页面上都有标题,并且报表每个页面的页脚上都有页码、日期和时间戳。You see the currency is formatted, the columns have headings on every page, and the report has a footer with page numbers and date and time stamp on every page.

    完成的页

  6. 将报表保存到计算机。Save the report to your computer.

将报表上传到服务Upload the report to the service

既然已经创建了这个分页报表,现在是时候将它上传到 Power BI 服务了。Now that you've created this paginated report, it's time to upload it to the Power BI service.

  1. 在 Power BI 服务 (https://app.powerbi.com) 的导航窗格中,依次选择“工作区” > “创建工作区” 。In the Power BI service (https://app.powerbi.com) in the nav pane, select Workspaces > Create workspace.

  2. 将工作区命名为“Azure AW” 或其他唯一名称。Name your workspace Azure AW, or other unique name. 现在,你是唯一的成员。You're the only member for now.

  3. 选择“高级” 旁边的箭头,然后启用“专用容量” 。Select the arrow next to Advanced and turn on Dedicated capacity.

    在高级容量中创建工作区

    如果无法启用,则需要让 Power BI 管理员授予你将工作区添加到专用高级容量的权限。If you can't turn it on, you need to ask your Power BI admin to give you permission to add the workspace to the dedicated Premium capacity.

  4. 如有必要,请为此工作区选择可用的专用容量 ,然后选择“保存” 。Choose an available dedicated capacity for this workspace, if necessary > Save.

    菱形“高级”图标

    如果工作区不处于高级容量,当你尝试上传报表时,会看到消息:“无法上传分页报表”。If the workspace isn't in a Premium capacity, when you try to upload your report you see the message, "Unable to upload paginated report." 请与 Power BI 管理员联系以移动工作区。Contact your Power BI administrator to move the workspace.

  5. 在新工作区中,选择“获取数据” 。In your new workspace, select Get Data.

  6. 在“文件” 框中,选择“获取” 。In the Files box > Get.

  7. 选择“本地文件” ,导航至保存文件的位置,然后选择“打开” 。Select Local File, navigate to where you saved the file > Open.

    Power BI 导入文件,你可以在应用列表页的“报表” 下看到该文件。Power BI imports your file, and you see it under Reports on the App list page.

    应用列表中的报表

  8. 选中报表以进行查看。Select the report to view it.

  9. 如果出现错误,则可能需要重新输入凭据。If you get an error, you may need to reenter your credentials. 选择“管理” 图标。Select the Manage icon.

    管理报表

  10. 选择“编辑凭据” ,然后输入在创建 Azure 数据库时在 Azure 中使用的凭据。Select Edit credentials and enter the credentials you used in Azure when you created the Azure database.

    编辑报表凭据

  11. 现在,可以在 Power BI 服务中查看分页报表。Now you can view your paginated report in the Power BI service.

    Power BI 服务中的分页报表

后续步骤Next steps

Power BI Premium 中的分页报表是什么?What are paginated reports in Power BI Premium?