如何在Power BI Desktop报表中使用Web数据源

This article explores various ways to use a Web data source in Power BI Desktop reports.

本文探讨了Power BI Desktop报表中使用Web数据源的各种方法。

介绍 (Introduction)

Information is widespread these days. You might get required data from Excel, CSV, text, PDF file, various relational and non-relational databases, SharePoint, etc. As you know, the internet provides us with an ability to view any data from any part of the World using web pages. We do not want to copy data from a webpage in an excel and then import it in Power BI Desktop.

这些天信息泛滥。 您可能会从Excel,CSV,文本,PDF文件,各种关系和非关系数据库,SharePoint等获取所需数据。众所周知,互联网使我们能够使用Web查看来自世界任何地方的任何数据。页面。 我们不想从Excel中的网页复制数据,然后将其导入Power BI Desktop。

Power BI gives you a lot of options to import data and prepare reports, visualizations for data interpretation. We can import data directly from a webpage using the Web data source.

Power BI为您提供了许多导入数据和准备报告,可视化数据解释的选项。 我们可以使用Web数据源直接从网页导入数据。

To view available data sources, launch Power BI Desktop and go to Get Data.

要查看可用的数据源,请启动Power BI Desktop,然后转到“ 获取数据”。

Get Data in Power BI Destop
  • Note: In this article, I use the March release of Power BI Desktop. You can use the 注意:在本文中,我使用Power BI Desktop的3月发行版。 您可以使用URL to download the latest version. It is always good to use the latest version to use all available features. URL下载最新版本。 使用最新版本来使用所有可用功能总是好的。
    Download March release

使用Web数据源从网页导入表 (Import tables from a Webpage using a Web data source)

Suppose we are creating a report that uses Olympic 2016 medals tally data source. We need to get data from a web page. For this click on Get Data -> Web for it. Specify URL.

假设我们正在创建一个使用2016年奥运会奖牌统计数据源的报告。 我们需要从网页获取数据。 为此,单击获取数据-> Web 。 指定URL。

Web data source

Click OK and allow anonymous access to the web page.

单击确定,并允许匿名访问网页。

Specify a URL

Once we click on Connect, it establishes a connection to the URL specified.

单击“连接”后,它将建立与指定URL的连接。

Connection status

You get a list of autodetected tables from the web page. Select the appropriate table, get a preview and use it further.

您可以从网页获取自动检测到的表的列表。 选择适当的表,进行预览并进一步使用。

Autodetected tables

You can select the required table and load the data for creating a visualization. We use Transform Data to customize data based on our requirements. It allows us to remove duplicate values, create new columns, define table headers, use calculated columns etc.

您可以选择所需的表并加载数据以创建可视化。 我们使用转换数据根据我们的要求自定义数据。 它允许我们删除重复的值,创建新列,定义表标题,使用计算所得的列等。

We can create the report as it is out of scope for this article. You can refer Power BI articles on SQLShack for more details.

我们可以创建报告,因为它超出了本文的范围。 您可以参考SQLShack上的Power BI文章以了解更多详细信息。

使用示例添加表 (Add table using examples)

Suppose you want to explore the product and their prices from an online shopping website such as Amazon. Here, the web page does not contain any tables that we can import.

假设您想从在线购物网站(例如Amazon)中浏览产品及其价格。 在这里,该网页不包含任何我们可以导入的表。

In the following screenshot, we have books listed on Amazon. We require to get the following field in a tabular format.

在以下屏幕截图中,我们在亚马逊上列出了书籍。 我们要求以表格格式获取以下字段。

  • Book Title

    书名
  • Author Name

    作者姓名
  • Paperback book price

    平装书价格
  • Kindle edition price

    Kindle版价格

Example

As you know, we do not have this data in a tabular format on Amazon so think of a question – Can we import required data from Amazon for visualization?

如您所知,我们在Amazon上没有表格格式的数据,所以请考虑一个问题–我们可以从Amazon导入所需的数据以进行可视化吗?

Yes, we have a solution for it. Let’s explore it.

是的,我们有解决方案。 让我们来探索它。

Click on Get Data-> Web. In the From Web, pop-up box paste into the web URL box that you copied from the web page.

单击获取数据-> Web。 在“ 从Web”中,弹出框将粘贴到您从网页复制的Web URL框中。

Specify a URL

Click OK and see if it gives any tables to import data. We get a few tables, but it does not contain any useful information that we required in the source data.

单击确定,看看它是否提供任何表来导入数据。 我们得到了一些表,但是它不包含我们在源数据中所需的任何有用信息。

Navigator

Look at the option Add table using examples in this data preview page.

在此数据预览页面中查看使用示例添加表格选项。

Add a table using examples option

Click on the highlighted option, and you get an interactive window with the following information.

单击突出显示的选项,您将获得一个包含以下信息的交互式窗口。

  • First part shows the web page

    第一部分显示网页
  • The second part shows an empty table. initially, it shows a single column

    第二部分显示一个空表。 最初,它只显示一列

Specify columns

In the second part, we need to specify a sample of data that we wish to import. For example, we require a book title in this column.

在第二部分中,我们需要指定要导入的数据样本。 例如,我们在此列中需要一个书名。

In column 1, type the text, and it gives suggestions for data from the web page. Select the required book title from the drop-down list.

在第1列中,输入文本,并提供有关网页数据的建议。 从下拉列表中选择所需的书名。

Specify a sample value

Once you select a value for column 1, Power BI automatically fills similar kinds of values (in this case book title) for other rows.

为列1选择一个值后,Power BI会自动为其他行填充类似类型的值(在本例中为书名)。

We can easily distinguish user entry and automated populated values. It shows user text in the regular font, but automated populated values are faded.

我们可以轻松地区分用户输入和自动填充的值。 它以常规字体显示用户文本,但自动填充的值逐渐消失。

Auto filled column data

Double-click on column 1 and rename it to give an appropriate name. Here, we give it the name Book Title.

双击列1并将其重命名以提供适当的名称。 在这里,我们给它取名为Book Title。

Rename column

In the next column, we require a book author. Click on *, and it adds a new column in the dataset. It uses a few functions to look for data from the web page.

在下一列中,我们需要一位图书作者。 单击*,它将在数据集中添加一个新列。 它使用一些功能从网页中查找数据。

In the following screenshot, check that for row 1, we entered the star rating (4.7 out of 5 stars) while for the second row, we entered the author name. You might need to look at a few combinations to get the proper data. We can modify data later using the power query editor.

在以下屏幕截图中,检查是否为第1行输入了星级(5星中的4.7分),而对于第二行,则输入了作者姓名。 您可能需要查看一些组合以获得正确的数据。 我们稍后可以使用超级查询编辑器修改数据。

Add a new table

In the third column, add the cost of the paperback edition. Some of the books contain Kindle edition as well. The price for a kindle edition is different than the paper book. Let’s add a new column and type the price of a kindle book. Here, we get few blank rows because Web URL does not contain the relevant section (in this case kindle e-book price).

在第三栏中,添加平装版的费用。 有些书还包含Kindle版。 点燃版的价格与纸质书不同。 让我们添加一个新列并输入点燃书的价格。 在这里,我们得到的空白行很少,因为Web URL不包含相关部分(在这种情况下,点燃电子书价格)。

Fill details for columns

Now click OK, and it gives you a preview in the navigator window. You can directly load or transform data as per your requirements.

现在单击“确定”,它会在导航器窗口中提供预览。 您可以根据需要直接加载或转换数据。

View table data

Click on Transform Data to edit the data in Power Query editor. Here, we have an incorrect Autor name in the first row.

单击“转换数据”以在Power Query编辑器中编辑数据。 在这里,第一行中的Autor名称不正确。

Replace value

Right-click on the first row and replace the value.

右键单击第一行并替换该值。

Replace the values

In the replace values, specify the new value to replace the existing value. You can verify the current value as well.

在替换值中,指定新值以替换现有值。 您也可以验证当前值。

Specify a new value

Similarly, I replaced the author’s name for row 13. We can see updated data, as shown below.

同样,我在第13行替换了作者的姓名。我们可以看到更新的数据,如下所示。

View updated data

You can make further changes data as per your requirement. Once changes are done, click on Close & Apply to save the changes. If you want to discard changes, click on Close.

您可以根据需要进行进一步的更改数据。 更改完成后,单击“ 关闭并应用”以保存更改。 如果要放弃更改,请单击“ 关闭”

Click on Close & Apply

新的Web表干扰预览功能 (New Web table interference preview feature)

In the above section, we saw that add tables using examples does not work correctly. We may need to try a specific combination to get table data. It cannot get accurate data after that. You may need to transform data, and it might be a tedious task for a large data set. In this section, we will look at the solution to this issue.

在上一节中,我们看到使用示例添加表无法正常工作。 我们可能需要尝试特定的组合以获取表数据。 之后,它无法获得准确的数据。 您可能需要转换数据,这对于大型数据集可能是一项繁琐的任务。 在本节中,我们将研究此问题的解决方案。

Power BI Desktop releases new features regularly in the monthly release. In these new features, few features come as a preview feature. We cannot directly start using the preview feature. To enable this feature, go to File-> Options and Settings -> Options. It opens various configuration options. Navigate to Preview features.

Power BI Desktop每月定期发布新功能。 在这些新功能中,很少有功能作为预览功能。 我们无法直接开始使用预览功能。 要启用此功能,请转到文件->选项和设置->选项。 它打开各种配置选项。 导航到预览功能

In the preview features list, put a check on New web table inference. It enables this preview feature.

在预览功能列表中,选中“ 新建Web表推断”。 它启用此预览功能。

Preview features

Click OK, and it asks you to restart Microsoft Power BI Desktop to use the recently enabled preview feature.

单击“确定”,然后它要求您重新启动Microsoft Power BI Desktop以使用最近启用的预览功能。

Restart message

After a restart, again go to the web data source and specify the URL that we used in the earlier example.

重新启动后,再次转到Web数据源并指定我们在前面的示例中使用的URL。

Specify a URL

Click OK, and here you see a few suggested tables. These suggested tables come as part of the preview feature. Here, we see 8 table suggestions from the web page data source. These table suggestions entirely depend on the web page and the Power BI algorithm.

单击确定,在这里您将看到一些建议的表格。 这些建议的表格是预览功能的一部分。 在这里,我们从网页数据源中看到8个表格建议。 这些表建议完全取决于网页和Power BI算法。

View auto suggested table

Put a check on a table, and it gives you a preview of the suggested tables. Select one that best suits our needs. In the following screenshot, you see table 2 with many useful columns.

勾选表格,即可预览建议表格。 选择最适合我们需求的产品。 在下面的屏幕截图中,您将看到表2包含许多有用的列。

View table data

You can still use the Transform Data and do required data changes.

您仍然可以使用“ 转换数据”并进行所需的数据更改。

  • Note: New web table inference is still a preview feature. You might notice significant changes in the upcoming Power BI Desktop release. You should be a little cautious with using these features in production reports.注意:新的Web表格推断仍是预览功能。 您可能会注意到即将发布的Power BI Desktop版本中的重大更改。 您应该在生产报告中使用这些功能时要谨慎一些。

结论 (Conclusion)

In this article, we explored different ways to import data from a Web data source. I am excited about the New Web table inference feature as well. You should explore this feature for your data requirements.

在本文中,我们探索了从Web数据源导入数据的不同方法。 我也对新的Web表推断功能感到兴奋。 您应该根据您的数据需求探索此功能。

翻译自: https://www.sqlshack.com/how-to-use-a-web-data-source-in-power-bi-desktop-reports/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值