从文件中获取数据Get data from files

在 Power BI 中,可以连接到或从三种类型的文件导入数据和报表。In Power BI, you can connect to or import data and reports from three types of files.

  • Microsoft Excel(.xlsx 或 .xlsm)Microsoft Excel (.xlsx or .xlsm)
  • Power BI Desktop (.pbix)Power BI Desktop (.pbix)
  • 逗号分隔值 (.csv)Comma Separated Value (.csv)

从文件中获取数据实际意味着什么?What does get data from a file really mean?

在 Power BI 中,你浏览的数据来自数据集。In Power BI the data you explore comes from a dataset. 但是,首先需要获取一些数据,才能拥有数据集。But in order to have a dataset, you first need to get some data. 本文将重点介绍从文件中获取数据。For this article, we're going to focus on getting data from files.

为了更好地了解数据集的重要性,以及如何为其获取数据,让我们看一看汽车。To better understand the importance of datasets, and how we get data for them, let’s look at an automobile. 坐在车里,看着仪表板。Take a seat in your car and look at the dashboard. 这很像坐在计算机前,查看 Power BI 中的仪表板。That’s a lot like sitting in front of your computer looking at a dashboard in Power BI. 仪表板显示汽车正在执行的所有操作:引擎旋转速度、温度、档位、车速等。The dashboard shows you all the things your car is doing; how fast the engine is revving, temperature, what gear you’re in, your speed, etc.

在 Power BI 中,数据集就像汽车的引擎。In Power BI, a dataset is like the engine in your car. 数据集提供显示在 Power BI 仪表板中的数据、指标和信息。The dataset provides the data, metrics, and information that’s displayed in your Power BI dashboard. 当然你的引擎(或者说数据集)需要燃油,而在 Power BI 中,燃油就是数据。Of course your engine, or dataset, needs fuel, and in Power BI, that fuel is data. 汽车具有为引擎提供汽油的油箱。Your car has a fuel tank that provides gas to the engine. Power BI 中的情况与此很相似,你需要一个油箱,将其中的数据馈送到数据集。Much the same in Power BI, you need a fuel tank that has data you can feed to your dataset. 在我们的例子中,油箱是 Power BI Desktop 文件、Excel 工作簿文件或 .CSV 文件。In our case, that fuel tank is a Power BI Desktop file, an Excel workbook file, or a .CSV file.

我们还可以更进一步。We can even take it one step further. 汽车的油箱需要装满汽油。A fuel tank in a car has to be filled with gas. 对于 Power BI Desktop、Excel 或 .CSV 文件而言,汽油就是来自其他数据源的数据。The gas for our Power BI Desktop, Excel, or .CSV file is data from another data source. 我们从其他数据源获取数据,并将其放入 Excel、Power BI Desktop 或 .CSV 文件中。We get data from another data source and put it into an Excel, Power BI Desktop, or .CSV file. 如果是 Excel 工作簿或 .CSV 文件,我们可以手动输入数据行。If it's an Excel workbook or .CSV file, we can manually enter rows of data. 或者,我们可以连接到外部数据源进行查询,并将数据加载到我们的文件中。Or, we can connect to an external data source to query and load data into our file. 当文件有一些数据后,我们可以将其作为数据集放入 Power BI。Once we have a file with some data, we can get it into Power BI as a dataset.

备注

Excel 工作簿中的数据必须位于表或数据模型中,才能由 Power BI 导入。Data in Excel workbooks must be in a table, or in the data model, to be imported by Power BI.

保存文件的位置具有重要意义Where your file is saved makes a difference

本地 - 如果你将文件保存到计算机上的本地驱动器中或者组织中的其他位置,则在 Power BI 中,你可以将文件导入到 Power BI。Local - If you save your file to a local drive on your computer or another location in your organization, from Power BI, you can import your file into Power BI. 你的文件实际上一直保存在本地驱动器中,因此整个文件并未真正导入到 Power BI。Your file will actually remain on your local drive, so the whole file isn’t really imported into Power BI. 实际上,在 Power BI 网站中创建新的数据集,数据(某些情况下为数据模型)将加载到数据集中。What really happens is a new dataset is created in your Power BI site and data, and in some cases the data model, are loaded into the dataset. 如果你的文件有任何报表,则这些报表会显示在你的 Power BI 网站中的“报表”下。If your file has any reports, those will appear in your Power BI site under Reports.

OneDrive - 企业 – 如果你有 OneDrive for Business,并且使用登录 Power BI 的同一帐户登录到其中,这是将 Excel Power BI Desktop 或 .CSV 文件中的工作与你在 Power BI 中的数据集、报表和仪表板保持同步的有史以来最有效的方法。由于 Power BI 和 OneDrive 都位于云中,Power BI 大约每小时会连接你在 OneDrive 上的文件一次。OneDrive - Business – If you have OneDrive for Business and you sign into it with the same account you sign into Power BI with, this is by-far the most effective way to keep your work in Excel Power BI Desktop, or a .CSV file and your dataset, reports, and dashboards in Power BI in-sync. Because both Power BI and OneDrive are in the cloud, Power BI connects to your file on OneDrive about every hour. 如果发现任何更改,你的数据集、报表和仪表板会在 Power BI 中自动更新。If any changes are found, your dataset, reports, and dashboards are automatically updated in Power BI.

OneDrive - 个人 – 如果你将文件保存到自己的 OneDrive 帐户,你会像使用 OneDrive for Business 那样获得很多相同优势。OneDrive - Personal – If you save your files to your own OneDrive account, you’ll get many of the same benefits as you would with OneDrive for Business. 最大的不同之处在于,当你首次连接至你的文件(使用“获取数据 > 文件 > OneDrive – 个人”)时,你将需要使用 Microsoft 帐户登录 OneDrive,这通常与你用于登录到 Power BI 的帐户不同。The biggest difference is when you first connect to your file (using Get Data > Files > OneDrive – Personal) you’ll need to sign in to your OneDrive with your Microsoft account, which is usually different from what you use to sign in to Power BI. 当使用你的 Microsoft 帐户登录 OneDrive 时,请务必选择“使我保持登录状态”选项。When signing in with your OneDrive with your Microsoft account, be sure to select the Keep me signed in option. 这样一来,Power BI 将能够大约每小时连接你的文件一次,并确保你在 Power BI 中的数据集同步。This way, Power BI will be able to connect to your file about every hour and make sure your dataset in Power BI is in-sync.

SharePoint 团队网站 – 将 Power BI Desktop 文件保存到 SharePoint 团队网站与保存到 OneDrive for Business 大致相同。SharePoint Team-Sites – Saving your Power BI Desktop files to SharePoint – Team Sites is much the same as saving to OneDrive for Business. 最大的区别是你从 Power BI 连接到文件的方式。The biggest difference is how you connect to the file from Power BI. 你可以指定一个 URL 或连接到根文件夹。You can specify a URL or connect to the root folder.

准备好开始了吗?Ready to get started?

请参阅下列文章了解有关将文件放入 Power BI 的详细信息。See the following articles to learn more about getting your file into Power BI.