我正在尝试将Power BI数据集与Microsoft Flow结合使用以进行每日更新。这是我目前的情况:
有没有办法避免打开Excel并按Power Query刷新的手动步骤?
let
Source = SharePoint.Files("https://xxxxxxxxxx", [ApiVersion = 15]),
FileContent = Source{[Name = "Individual Status.xls"]}[Content],
ParsedTable = ParseXls(FileContent, "Individual Status")
in
Source
Expression.Error: We cannot convert the value "Individual Status" to type Binary.
Details:
Value=Individual Status.xls
Type=[Type]
答案 0 :(得分:0)
可能的解决方法是直接在Power BI中使用Python或R脚本解析.xls文件。
这是使用Python解析.xls的示例函数。将以下代码复制并粘贴到空白查询中,然后将其重命名为“ ParseXls”或其他有意义的名称。
(workbook as binary, sheet as text, optional header as logical) as table =>
let dataset = Table.FromRecords({[
content = Binary.ToText(workbook, BinaryEncoding.Base64),
sheet = sheet,
header = if header = null then true else header
]}),
result = Python.Execute("import pandas as pd#(lf)from base64 import b64decode#(lf)from io import BytesIO#(lf)params = dataset.loc[0]#(lf)content = BytesIO(b64decode(params['content']))#(lf)sheet = params['sheet']#(lf)header = 0 if params['header'] else None#(lf)result = pd.read_excel(content, sheet, header=header)", [dataset = dataset]){[Name = "result"]}[Value]
in result
然后,您可以将此功能与从SharePoint获得的二进制文件内容一起使用。整个查询将如下所示。
let
Source = SharePoint.Files("https://yourcompany.sharepoint.com/...", [ApiVersion = 15]),
FileContent = Source{[Name = "Book1.xls"]}[Content],
ParsedTable = ParseXls(FileContent, "Sheet1"),
...