实现您在 Power BI 中提到的最佳方法是利用 parameters 并参数化您的查询以获取 csv 文件。
假设我们有一个名为 SalesJan2009.csv 的 csv 文件。当您将其导入电源BI时,您应该有类似的东西:
let
Source = Csv.Document(File.Contents("\\Mac\Home\Downloads\SalesJan2009.csv"),[Delimiter=",", Columns=12, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Transaction_date", type datetime}, {"Product", type text}, {"Price", Int64.Type}, {"Payment_Type", type text}, {"Name", type text}, {"City", type text}, {"State", type text}, {"Country", type text}, {"Account_Created", type datetime}, {"Last_Login", type datetime}, {"Latitude", type number}, {"Longitude", type number}})
in
#"Changed Type"
如果我们希望用户输入文件位置(即\\Mac\Home\Downloads\),我们可以在Power BI中设置参数:
然后我们可以更新查询使用参数:(Query -> Advanced Editor)
let
Source = Csv.Document(File.Contents(#"FileLocation" & "SalesJan2009.csv"), ...
...
如果用户稍后想要更改参数(文件位置),则可以编辑参数并应用更改以刷新数据。
附:您甚至可以进一步export the Power BI file as a template允许用户将其实例化为新的Power BI桌面报告(PBIX文件)。